Skip to content

SDK

@openpicker/sdk is a tiny, dependency-free client. It does not draw any UI — it starts a pick and awaits the result; the extension owns the picker overlay and the cross-tab routing.

bash
npm install @openpicker/sdk

Quick start

ts
import { createOpenpicker, OpenpickerError } from "@openpicker/sdk"

const op = createOpenpicker({ appName: "My App" })

if (!(await op.isAvailable())) {
  // prompt the user to install the openpicker extension
}

try {
  const { selector, matchCount, element, screenshot } = await op.pick({
    url: "https://app.example.com",
    screenshot: "element",
  })
  console.log(selector, `(matches ${matchCount})`, element)
} catch (err) {
  if (err instanceof OpenpickerError && err.code === "cancelled") {
    // the user closed the picker
  } else {
    throw err
  }
}

createOpenpicker(options?)

Returns an Openpicker handle.

OptionTypeDefaultDescription
appNamestringDisplay name shown to the user (informational, never trusted).
pingTimeoutnumber1500ms before ping assumes the extension isn't installed.
defaultTimeoutnumber3000ms for quick ops (cancel / highlight / clearHighlight).
targetWindowWindowwindowWindow to communicate over.

Methods

MethodReturnsDescription
ping()PingResultProbe the extension; negotiate version & capabilities.
isAvailable()booleantrue if the extension responds to a ping.
pick(params)PickResultOpen params.url, let the user pick there, resolve with the result.
cancel()voidCancel an in-flight pick (it rejects with cancelled).
highlight(selector)HighlightResultHighlight matches of a selector without entering pick mode.
clearHighlight()voidRemove any active highlight.
activateSelf()voidBring the calling tab to the foreground (a tab can only focus itself).
isTargetOpen()booleanWhether the cross-tab target tab this tab opened is still open.
destroy()voidStop listening and reject any in-flight requests.

pick(params)

FieldTypeDescription
urlstring (required)Page to open and pick in. Omitting it rejects with invalid_params.
screenshot"none" | "element" | "viewport"Screenshot to include. Defaults to "none".
excludestringExtra regex of id/class names to exclude, on top of the built-ins.
keystringOpaque task id; decides whether a later pick reuses the target tab.
appNamestringOverrides the instance appName for this call.

PickResult

ts
{
  selector: string
  matchCount: number
  element: { tag: string; id?: string; classes: string[]; text?: string; attributes: Record<string, string> }
  screenshot?: string // data: URL, present only when requested
}

pick is cross-tab only — see Cross-tab picking. Error codes are listed in Errors.

Released under the MIT License.