Skip to content

@extension-use/client ​

The typed client that controllers use: a web app in your side panel, your website, or a script. It's small (about 2.1 KB gzipped, plus 0.8 KB for the frame transport) and has no dependencies beyond the protocol types.

bash
npm install @extension-use/client

Entry points ​

ImportExportUse it when
@extension-use/clientconnect(), ExtensionUseError, types (Client, CoreActions, Locator, Target, …)Always
@extension-use/client/frameframe({ hostOrigins? }), inExtensionFrame()Your app runs in an iframe that the extension's frame bridge mounted
@extension-use/client/pagepage({ extensionId })Your site runs in a normal tab
@extension-use/client/remoteremote({ relay, token, device?, WebSocket? })Your code runs outside the browser and reaches it through a relay
@extension-use/client/memorymemoryPair()Tests and custom hosts
@extension-use/client/standalone/extension-use-client.jsconnect, frame, inExtensionFrame, page, remote and ExtensionUseError in one ES moduleNo build step

Quick example ​

ts
import { connect } from "@extension-use/client";
import { frame } from "@extension-use/client/frame";

const ext = await connect(frame());

const { text } = await ext.dom.snapshot({ format: "text" });
await ext.dom.click({ locator: { role: "button", name: "Save" } });
await ext.overlay.toast({ message: "Saved", kind: "success" });
ext.on("tab.updated", ({ tab }) => console.log(tab.url));

API ​

MemberWhat it does
connect(transport, options?)Handshake with the host. Rejects with NOT_CONNECTED if nothing answers.
ext.<group>.<action>(input?, options?)Call an action, typed.
ext.call(name, input?, options?)The same, by name.
ext.callRaw(name, input?, options?)Call any action, including your own before you have types.
ext.has(name)Whether the host offers the action and this controller may call it.
ext.on(event, handler)Subscribe. Patterns like "tab.*" work. Returns an unsubscribe function.
ext.onDisconnect(handler)Called when the connection ends.
ext.close()Close the session.
ext.host, ext.session, ext.capabilities, ext.connectedHost info, session ID, callable actions, connection state.

Call options: { target?, timeoutMs?, signal? }. Connect options: name, version, handshakeTimeoutMs, timeoutMs, debug, expose.

The controllers guide covers transports, targets, locators, events and errors in detail. The action reference lists every action's input and output.

Your own actions, typed ​

ts
import { connect, type CoreActions } from "@extension-use/client";
import type { HostActions } from "./extension-actions"; // from `extension-use codegen`

const ext = await connect<CoreActions & HostActions>(frame());
await ext.app.saveNote({ text: "Read later" });

See custom actions.

The SDK packages are released under the MIT license.