Domain policy, borrowed pages, and CDP attach.
allowedDomains and/or blockedDomains into the toolkit factory to restrict http(s) navigations in the provider-managed browser context.1234567import { createAiSdkBrowserTools } from "libretto-browser-tools/ai-sdk"; import { LocalBrowserProvider } from "libretto-browser-tools"; const { tools, dispose } = createAiSdkBrowserTools(new LocalBrowserProvider(), { allowedDomains: ["example.com", "*.example.com"], blockedDomains: ["ads.example.com"], });
*.suffix wildcards. Non-http(s) URLs are not filtered.DomainPolicyRestricted (not { ok: false }) so the host can inspect attemptedNavigationUrl and the configured policy.browser_exec code and does not cover caller-created browser contexts outside the toolkit.Page (for example inside a failing automation), attach tools without owning the browser lifecycle:123456import { createBrowserToolsForPage } from "libretto-browser-tools"; // or: createAiSdkBrowserToolsForPage from "libretto-browser-tools/ai-sdk" const { sessionId, tools, dispose } = createBrowserToolsForPage(page); // tools: browser_exec, browser_snapshot, browser_status only await dispose(); // detaches tools; does not close page / context / browser
libretto-playwright-debugger uses this pattern so a debugging agent can inspect and drive the live failed page. See Playwright debugging agent.browser_connect when Chromium (or an Electron app) is already running with a remote-debugging endpoint:1234// Agent tool call shape await tools.browser_connect.execute({ cdpUrl: "ws://127.0.0.1:9222/devtools/browser/<id>", });
browser_open when the provider should create and tear down the browser for you.