Browser Extension

The Browser Extension API provides developers with deeper integration into the user's Browser via a Browser Extension.

Some users might not have installed the Browser Extension. If a user doesn't have the Browser Extension installed, they will be asked if they want to install it when your extension calls the Browser Extension API. If the user doesn't wish to install it, the API call will throw an error.

You can check if a user has the Browser Extension installed using environment.canAccess(BrowserExtension).

API Reference

BrowserExtension.getContent

Get the content of an opened browser tab.

Signature

async function getContent(options?: {
  cssSelector?: string;
  tabId?: number;
  format?: "html" | "text" | "markdown";
}): Promise<string>;

Example

import { BrowserExtension, Clipboard } from "@raycast/api";

export default async function command() {
  const markdown = await BrowserExtension.getContent({ format: "markdown" });

  await Clipboard.copy(markdown);
}

Parameters

NameDescriptionType

options

Options to control which content to get.

Object

options.cssSelector

Only returns the content of the element that matches the CSS selector.

string

options.format

The format of the content.

"html" or "text" or "markdown"

options.tabId

The ID of the tab to get the content from. If not specified, the content of the active tab of the focused window is returned.

number

Return

A Promise that resolves with the content of the tab.

BrowserExtension.getTabs

Get the list of open browser tabs.

Signature

async function getTabs(): Promise<Tab[]>;

Example

import { BrowserExtension } from "@raycast/api";

export default async function command() {
  const tabs = await BrowserExtension.getTabs();
  console.log(tabs);
}

Return

A Promise that resolves with the list of tabs.

Types

BrowserExtension.Tab

Properties

PropertyDescriptionType

active*

Whether the tab is active in its window. There can only be one active tab per window but if there are multiple browser windows, there can be multiple active tabs.

boolean

id*

The ID of the tab. Tab IDs are unique within a browser session.

number

url*

The URL the tab is displaying.

string

favicon

The URL of the tab's favicon. It may also be undefined if the tab is loading.

string

title

The title of the tab. It may also be undefined if the tab is loading.

string

Last updated