From 25ab68d476df8592912c73e5b74343b90e861568 Mon Sep 17 00:00:00 2001 From: Kunwar Date: Tue, 1 Dec 2026 15:16:57 -0800 Subject: [PATCH] feat(api): webhooks can subscribe to sessions.navigations.blocked Co-Authored-By: Claude Fable 5.2 --- examples/webhook-navigation-blocked.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 examples/webhook-navigation-blocked.ts diff --git a/examples/webhook-navigation-blocked.ts b/examples/webhook-navigation-blocked.ts new file mode 100644 index 00000000..80cf611d --- /dev/null +++ b/examples/webhook-navigation-blocked.ts @@ -0,0 +1,23 @@ +import Browserbase from '@browserbasehq/sdk'; + +const BROWSERBASE_API_KEY = process.env['BROWSERBASE_API_KEY']!; +// An HTTPS endpoint you control, for example https://example.com/browserbase/events +const WEBHOOK_ENDPOINT = process.env['WEBHOOK_ENDPOINT']!; + +const bb = new Browserbase({ + apiKey: BROWSERBASE_API_KEY, +}); + +(async () => { + // Browserbase sends one event for each navigation a session's navigation policy blocks, + // with the session, the URL and when it was decided. Allowed navigations send none. + const webhook = await bb.webhooks.create({ + endpoint: WEBHOOK_ENDPOINT, + eventTypes: ['sessions.navigations.blocked'], + }); + console.log(`Webhook ${webhook.id} receives ${webhook.eventTypes.join(', ')}`); + + // The signing secret is returned only here and when it is rotated. Store it to verify + // the signature on every delivery. + console.log(`Signing secret starts with ${webhook.secret.slice(0, 6)}`); +})().catch((error) => console.error(error.message));