Skip to content

Interface: WebviewService

Defined in: packages/sdk/src/webview-service.ts:171

The webview-bridge domain, exposed as ExtensionContext.webview. Requires the "webview" Permission.

Example

tsx
function MyPanel({ ctx }: { ctx: ExtensionContext }) {
  const iframeRef = useRef<HTMLIFrameElement>(null);
  const frameRef = useRef<WebFrame | null>(null);

  useEffect(() => {
    if (!iframeRef.current) return;
    const frame = ctx.webview.attach(iframeRef.current);
    frameRef.current = frame;
    const sub = frame.onNavigate((e) => console.log(e.type, e.url));
    return () => { sub.dispose(); frame.dispose(); };
  }, []);

  return <iframe ref={iframeRef} src="https://example.com" />;
}

Methods

attach()

ts
attach(frame): WebFrame;

Defined in: packages/sdk/src/webview-service.ts:177

Attach the bridge to an iframe your panel owns. The iframe can be cross-origin — that's the point. Returns a WebFrame; call .dispose() (or push it onto ctx.subscriptions) when done with it.

Parameters

frame

HTMLIFrameElement

Returns

WebFrame