Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Handle native browser dialogs during Chrome action runs
Emre Sokullue2ca50080093
diff --git a/docs/architecture.md b/docs/architecture.mdindex 8c0df548d..400015b72 100644--- a/docs/architecture.md+++ b/docs/architecture.md@@ -814,6 +814,25 @@ Wraps `chrome.debugger` API for:`WebMCP.invokeTool` executes a page-registered structured capability. WebBrainexposes opaque `wmcp_*` IDs rather than page-controlled names as call handles.+During active Chrome Act/Dev runs (including saved workflow replay), native+JavaScript dialogs are continued through `Page.javascriptDialogOpening` and+`Page.handleJavaScriptDialog`. Alerts and confirmations are accepted;+`beforeunload` warnings choose Leave; prompts use the site's default text (or+an empty string when no default exists). This includes accepting confirmation+of the pending page action and potentially discarding unsaved changes. Dialog+text is never interpreted as instructions. The event handler runs independently+of blocked renderer commands, and is removed on Stop, completion, or detach,+even when Dev diagnostics keep the debugger attached. Ask mode and idle tabs+do not auto-answer dialogs. Already-observed dialogs are resolved before+startup commands, so retained Dev connections can resume them. Chrome does not+expose a dialog opened before debugger attachment to the new session; dismiss+that existing dialog manually. Dialog setup responds to Stop and times out after+five seconds rather than holding the run indefinitely. Existing action permission+checks still apply.+This does not handle browser permission requests, authentication windows, or+OS file pickers. Firefox WebExtensions provide no equivalent native-dialog API;+those dialogs still require manual handling in Firefox.+WebMCP is an experimental Chrome-only fast path that is off by default. Theuser must enable **Experimental WebMCP** under Settings → General → Advanced;until then, neither WebMCP tool schemas nor WebMCP prompt guidance enter modeldiff --git a/package.json b/package.jsonindex c1c025865..7139af282 100644--- a/package.json+++ b/package.json@@ -5,7 +5,7 @@"private": true,"type": "module","scripts": {- "test": "npm run test:runtime-lifecycle && npm run test:provider-limits && npm run test:toolbar-guard && npm run test:pdf-read && npm run test:pdf-selection && npm run test:social-contract && node test/run.js && node test/selection-scope-restoration.mjs && node scripts/benchmark-offline-relevance.mjs && npm run test:security",+ "test": "node --test test/browser-dialogs.mjs && npm run test:runtime-lifecycle && npm run test:provider-limits && npm run test:toolbar-guard && npm run test:pdf-read && npm run test:pdf-selection && npm run test:social-contract && node test/run.js && node test/selection-scope-restoration.mjs && node scripts/benchmark-offline-relevance.mjs && npm run test:security","test:provider-limits": "node test/provider-model-limits.mjs","test:security": "node test/security/injection-corpus.mjs","test:toolbar-guard": "node test/rich-text-toolbar-guard.mjs",diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 55ae57f3d..f001dea2b 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -5979,6 +5979,7 @@ export class Agent extends LoopDetector {}_releaseRunEntry(tabId) {+ cdpClient.stopDialogHandling(tabId);this._runAbortStates.get(tabId)?.dispose();this._runAbortStates.delete(tabId);this.abortFlags.delete(tabId);@@ -16004,6 +16005,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dabort(tabId) {for (const id of this._researchEscalationTabIds(tabId)) {this.abortFlags.set(id, true);+ cdpClient.stopDialogHandling(id);const controller = this._runAbortStates.get(id)?.controller;if (controller && !controller.signal.aborted) {const error = new Error('Stopped by user');@@ -32042,6 +32044,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dthis._prepareClarificationAuthorizationForRun(tabId);this.permissions.beginTurn(tabId);this.conversationModes.set(tabId, 'act');+ await cdpClient.startDialogHandling(tabId, { signal: this._runAbortSignal(tabId) })+ .catch(error => {+ if (error?.name === 'AbortError' || error?.code === 'dialog_startup_timeout') throw error;+ // Restricted tabs can still use non-CDP tools.+ });completionRunToken = this._beginCompletionInvariant(tabId);previousForegroundCapture = this._configureCapturePolicyForRun(tabId, runOptions);capturePolicyConfigured = true;@@ -32076,7 +32083,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dtry {if (completionRunToken) this._clearCompletionInvariant(tabId, completionRunToken);} finally {- this._releaseRunEntry(tabId);+ try {+ await cdpClient.cleanupRun(tabId);+ } catch { /* preserve the original setup failure */ }+ finally { this._releaseRunEntry(tabId); }}}throw error;@@ -40225,10 +40235,19 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dthis.cloudRunContexts.set(tabId, { outputSchema: runOptions.outputSchema ?? null, schemaRepairUsed: false });}try {+ if ((mode === 'act' || mode === 'dev') && !this._isStandaloneChatRun(runOptions)) {+ await cdpClient.startDialogHandling(tabId, {+ signal: this._runAbortSignal(tabId),+ }).catch(error => {+ if (error?.name === 'AbortError' || error?.code === 'dialog_startup_timeout') throw error;+ // Restricted tabs can still use non-CDP tools.+ });+ }const result = await this._processMessageInner(tabId, userMessage, onUpdate, mode, attachments, runOptions);void this._maybeEmitAskModeHandoff(tabId, mode, userMessage, result, onUpdate, runOptions);return result;} finally {+ cdpClient.stopDialogHandling(tabId);this.currentCostState.delete(tabId);this._discardProvisionalSelectionGroundingScope(tabId);this._storeContinuationExecutionEvidence(tabId);@@ -41827,10 +41846,19 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dthis.cloudRunContexts.set(tabId, { outputSchema: runOptions.outputSchema ?? null, schemaRepairUsed: false });}try {+ if ((mode === 'act' || mode === 'dev') && !this._isStandaloneChatRun(runOptions)) {+ await cdpClient.startDialogHandling(tabId, {+ signal: this._runAbortSignal(tabId),+ }).catch(error => {+ if (error?.name === 'AbortError' || error?.code === 'dialog_startup_timeout') throw error;+ // Restricted tabs can still use non-CDP tools.+ });+ }const result = await this._processMessageStreamInner(tabId, userMessage, onUpdate, mode, runOptions);void this._maybeEmitAskModeHandoff(tabId, mode, userMessage, result, onUpdate, runOptions);return result;} finally {+ cdpClient.stopDialogHandling(tabId);this.currentCostState.delete(tabId);this._discardProvisionalSelectionGroundingScope(tabId);this._storeContinuationExecutionEvidence(tabId);diff --git a/src/chrome/src/cdp/cdp-client.js b/src/chrome/src/cdp/cdp-client.jsindex 29a99dc08..bafdd6e64 100644--- a/src/chrome/src/cdp/cdp-client.js+++ b/src/chrome/src/cdp/cdp-client.js@@ -94,11 +94,22 @@ export class CDPClient {this.devDiagnostics = new Map(); // tabId -> bounded console/network buffersthis.webMcpSessions = new Map(); // tabId -> WebMCP tools + pending invocationsthis.runtimeContexts = new Map(); // tabId -> session/context key -> default context+ this.pendingDialogs = new Map(); // tabId -> sessionId -> current native dialog+ this.dialogRuns = new Map(); // tabId -> active action-run ownerthis.fileChooserGuards = new Map(); // tabId -> temporary protocol interceptionthis._debuggerListenersRegistered = false;this._onDebuggerEvent = (source, method, params) => {const tabId = source?.tabId;if (tabId == null) return;+ if (method === 'Page.javascriptDialogOpening') {+ if (!this.pendingDialogs.has(tabId)) this.pendingDialogs.set(tabId, new Map());+ const dialog = { type: params?.type, defaultPrompt: params?.defaultPrompt };+ this.pendingDialogs.get(tabId).set(source.sessionId || '', dialog);+ this._continueJavaScriptDialog(tabId, source, dialog);+ } else if (method === 'Page.javascriptDialogClosed') {+ this.pendingDialogs.get(tabId)?.delete(source.sessionId || '');+ if (!this.pendingDialogs.get(tabId)?.size) this.pendingDialogs.delete(tabId);+ }this._trackRuntimeContextEvent(tabId, source, method, params);const handlers = this.eventHandlers.get(tabId)?.[method];if (handlers) {@@ -108,6 +119,8 @@ export class CDPClient {this._onDebuggerDetach = (source, reason) => {const tabId = source?.tabId;if (tabId == null) return;+ this.stopDialogHandling(tabId);+ this.pendingDialogs.delete(tabId);this._dropWebMCPSession(tabId, `Debugger detached: ${reason || 'unknown reason'}`);this.sessions.delete(tabId);this.eventHandlers.delete(tabId);@@ -205,6 +218,8 @@ export class CDPClient {* Detach debugger from a tab.*/async detach(tabId) {+ this.stopDialogHandling(tabId);+ this.pendingDialogs.delete(tabId);if (!this.sessions.has(tabId)) {const pendingAttach = this.attachPromises.get(tabId);if (!pendingAttach) return;@@ -238,6 +253,7 @@ export class CDPClient {* page-owned catalog.*/async cleanupRun(tabId) {+ this.stopDialogHandling(tabId);try { await this.disableWebMCP(tabId); } catch {}if (!this.devDiagnostics.has(tabId)) await this.detach(tabId);}@@ -257,6 +273,81 @@ export class CDPClient {await this.detach(tabId);}+ /** Native dialogs pause renderer commands, so resolve them from the debugger+ * event callback rather than queuing behind the click/evaluate they blocked.+ * Firefox has no equivalent WebExtension API; never patch page JS to fake it.+ */+ async startDialogHandling(tabId, { signal, onHandled, timeoutMs = 5000 } = {}) {+ this.stopDialogHandling(tabId);+ if (signal?.aborted) return;+ const owner = { signal, onHandled };+ owner.onAbort = () => {+ if (this.dialogRuns.get(tabId) === owner) this.stopDialogHandling(tabId);+ };+ this.dialogRuns.set(tabId, owner);+ signal?.addEventListener('abort', owner.onAbort, { once: true });+ try {+ await this.attach(tabId);+ if (this.dialogRuns.get(tabId) !== owner) return;+ // Resolve an already-observed dialog before Page.enable, which itself+ // can wait for the paused renderer when Dev retained the connection.+ for (const [sessionId, dialog] of this.pendingDialogs.get(tabId) || []) {+ this._continueJavaScriptDialog(tabId, { tabId, sessionId }, dialog);+ }+ // Page.enable can wait indefinitely behind a pre-existing dialog. Stop+ // must release the run even when Chrome never answers this command.+ let timer;+ const interrupted = new Promise((_, reject) => {+ owner.cancelStartup = () => {+ const error = new Error('Stopped during browser dialog setup');+ error.name = 'AbortError';+ reject(error);+ };+ timer = setTimeout(() => {+ const error = new Error('Browser dialog setup timed out. Dismiss any existing browser dialog and try again.');+ error.code = 'dialog_startup_timeout';+ reject(error);+ }, timeoutMs);+ });+ try {+ await Promise.race([this.sendCommand(tabId, 'Page.enable'), interrupted]);+ } finally {+ clearTimeout(timer);+ delete owner.cancelStartup;+ }+ } catch (error) {+ if (this.dialogRuns.get(tabId) === owner) this.stopDialogHandling(tabId);+ throw error;+ }+ }++ stopDialogHandling(tabId) {+ const owner = this.dialogRuns.get(tabId);+ owner?.cancelStartup?.();+ owner?.signal?.removeEventListener('abort', owner.onAbort);+ this.dialogRuns.delete(tabId);+ }++ _continueJavaScriptDialog(tabId, source, params = {}) {+ const owner = this.dialogRuns.get(tabId);+ if (!owner || owner.signal?.aborted || params.handling) return;+ if (!['alert', 'confirm', 'prompt', 'beforeunload'].includes(params.type)) return;+ params.handling = true;+ const response = { accept: true };+ // Use the site's existing default; never invent answers or interpret dialog+ // text as instructions. No page-controlled text is sent to status/trace UI.+ if (params.type === 'prompt') response.promptText = String(params.defaultPrompt ?? '');+ void this.sendCommand(tabId, 'Page.handleJavaScriptDialog', response, source?.sessionId || '')+ .then(() => {+ if (this.dialogRuns.get(tabId) !== owner) return;+ try { owner.onHandled?.(params.type); } catch {}+ })+ .catch(() => {+ // The user may have already closed it, navigated, or detached. Do not+ // retry: a retry could answer a different dialog opened immediately after.+ });+ }+/*** Send a CDP command and get the result.*/diff --git a/test/README.md b/test/README.mdindex 4a4326622..4494669a3 100644--- a/test/README.md+++ b/test/README.md@@ -151,3 +151,10 @@ python3 -m http.server 8765 -d test/memoryThen open `http://127.0.0.1:8765/`. The page walks through `/memory --add`,form-derived learning, normal auto-learning, replaying saved memories into alater form, and Profile auto-fill.++### Native browser dialogs++`node --test test/browser-dialogs.mjs` covers dialog responses, per-tab ownership,+Stop/abort, retained Dev sessions, and protocol races (included in `npm test`).+`node test/browser-dialogs-e2e.mjs` uses installed Chrome through Playwright to+verify real alert/confirm/prompt and beforeunload continuation.diff --git a/test/browser-dialogs-e2e.mjs b/test/browser-dialogs-e2e.mjsnew file mode 100644index 000000000..7d927eb02--- /dev/null+++ b/test/browser-dialogs-e2e.mjs@@ -0,0 +1,50 @@+import assert from 'node:assert/strict';+import { chromium } from 'playwright';+import { CDPClient } from '../src/chrome/src/cdp/cdp-client.js';++const timeout = setTimeout(() => { console.error('Dialog test timed out'); process.exit(1); }, 30000);+const browser = await chromium.launch({ channel: 'chrome', headless: true });+try {+ const page = await browser.newPage();+ // Prevent Playwright's default dismissal: the production client must answer.+ page.on('dialog', () => {});+ const session = await page.context().newCDPSession(page);+ const client = new CDPClient();+ const answered = [];+ client.attach = async () => {};+ client.sendCommand = (_tab, method, params) => session.send(method, params);+ session.on('Page.javascriptDialogOpening', params => client._onDebuggerEvent(+ { tabId: 1 }, 'Page.javascriptDialogOpening', params,+ ));+ session.on('Page.javascriptDialogClosed', params => client._onDebuggerEvent(+ { tabId: 1 }, 'Page.javascriptDialogClosed', params,+ ));+ await client.startDialogHandling(1, { onHandled: type => answered.push(type) });+ await page.setContent('<button id="go">Continue</button>');+ const result = await session.send('Runtime.evaluate', {+ expression: `(() => { alert('Notice'); const confirmed = confirm('Continue?');+ const answer = prompt('Value?', 'default value'); return { confirmed, answer }; })()`,+ returnByValue: true,+ });+ assert.deepEqual(result.result.value, { confirmed: true, answer: 'default value' });+ await page.evaluate(() => {+ document.querySelector('#go').onclick = () => {+ window.onbeforeunload = event => { event.preventDefault(); event.returnValue = ''; };+ };+ });+ await page.click('#go');+ await page.goto('about:blank');+ assert.equal(page.url(), 'about:blank');+ assert.deepEqual(answered, ['alert', 'confirm', 'prompt', 'beforeunload']);+ client.stopDialogHandling(1);+ const opened = new Promise(resolve => session.once('Page.javascriptDialogOpening', resolve));+ const pending = session.send('Runtime.evaluate', { expression: 'confirm("Already open")', returnByValue: true });+ await opened;+ await client.startDialogHandling(1);+ assert.equal((await pending).result.value, true);+ client.stopDialogHandling(1);+ console.log('PASS: real Chrome alert, confirm, prompt, and beforeunload resume renderer/navigation.');+} finally {+ await browser.close();+ clearTimeout(timeout);+}diff --git a/test/browser-dialogs.mjs b/test/browser-dialogs.mjsnew file mode 100644index 000000000..97c336041--- /dev/null+++ b/test/browser-dialogs.mjs@@ -0,0 +1,180 @@+import test from 'node:test';+import assert from 'node:assert/strict';+import { CDPClient } from '../src/chrome/src/cdp/cdp-client.js';++function harness() {+ const calls = [];+ const client = new CDPClient();+ client.sessions.set(7, { tabId: 7 });+ client.attach = async id => client.sessions.set(id, { tabId: id });+ client.sendCommand = async (...args) => { calls.push(args); };+ return { client, calls };+}+const tick = () => new Promise(resolve => setImmediate(resolve));++test('native dialogs continue immediately, preserving prompt defaults and child sessions', async () => {+ const { client, calls } = harness();+ const handled = [];+ await client.startDialogHandling(7, { onHandled: type => handled.push(type) });+ assert.equal(calls[0][1], 'Page.enable');+ for (const type of ['alert', 'confirm', 'beforeunload', 'prompt']) {+ client._onDebuggerEvent({ tabId: 7, sessionId: 'child' }, 'Page.javascriptDialogOpening', {+ type, defaultPrompt: 'existing answer', message: 'untrusted instructions',+ });+ }+ await tick();+ assert.deepEqual(handled, ['alert', 'confirm', 'beforeunload', 'prompt']);+ assert.deepEqual(calls.slice(1), ['alert', 'confirm', 'beforeunload', 'prompt'].map(type => [+ 7, 'Page.handleJavaScriptDialog',+ type === 'prompt' ? { accept: true, promptText: 'existing answer' } : { accept: true }, 'child',+ ]));+});++test('inactive tabs, stop, abort, and cleanup never auto-answer dialogs', async () => {+ const { client, calls } = harness();+ const emit = id => client._onDebuggerEvent({ tabId: id }, 'Page.javascriptDialogOpening', { type: 'confirm' });+ emit(7);+ client._onDebuggerEvent({ tabId: 7 }, 'Page.javascriptDialogClosed', {});+ const controller = new AbortController();+ await client.startDialogHandling(7, { signal: controller.signal });+ emit(8);+ controller.abort();+ emit(7);+ client._onDebuggerEvent({ tabId: 7 }, 'Page.javascriptDialogClosed', {});+ await client.startDialogHandling(7);+ client.stopDialogHandling(7);+ emit(7);+ client._onDebuggerEvent({ tabId: 7 }, 'Page.javascriptDialogClosed', {});+ await client.startDialogHandling(7);+ client.devDiagnostics.set(7, {}); // debugger survives the run+ client.disableWebMCP = async () => {};+ await client.cleanupRun(7);+ emit(7);+ client._onDebuggerEvent({ tabId: 7 }, 'Page.javascriptDialogClosed', {});+ await tick();+ assert.ok(calls.every(call => call[1] === 'Page.enable'));+});++test('failed startup and already-aborted runs do not retain dialog handling', async () => {+ const { client } = harness();+ await client.startDialogHandling(7, { signal: AbortSignal.abort() });+ assert.equal(client.dialogRuns.size, 0);+ client.sendCommand = async () => { throw new Error('detached'); };+ await assert.rejects(client.startDialogHandling(7));+ assert.equal(client.dialogRuns.size, 0);+});++test('dialog races consume protocol failures without retrying the next dialog', async () => {+ const { client, calls } = harness();+ await client.startDialogHandling(7);+ client.sendCommand = async (...args) => { calls.push(args); throw new Error('No dialog'); };+ client._onDebuggerEvent({ tabId: 7 }, 'Page.javascriptDialogOpening', { type: 'alert' });+ await tick();+ assert.equal(calls.length, 2);+});++test('a new action run resumes an already-observed dialog exactly once', async () => {+ const { client, calls } = harness();+ client._onDebuggerEvent({ tabId: 7 }, 'Page.javascriptDialogOpening', { type: 'beforeunload' });+ assert.equal(calls.length, 0);+ await client.startDialogHandling(7);+ await client.startDialogHandling(7);+ assert.equal(calls.filter(call => call[1] === 'Page.handleJavaScriptDialog').length, 1);+ client._onDebuggerEvent({ tabId: 7 }, 'Page.javascriptDialogClosed', {});+ assert.equal(client.pendingDialogs.size, 0);+});++test('cached dialog is answered before renderer-dependent Page.enable', async () => {+ const { client } = harness();+ client._onDebuggerEvent({ tabId: 7 }, 'Page.javascriptDialogOpening', { type: 'alert' });+ let answered = false;+ client.sendCommand = async (_tabId, method) => {+ if (method === 'Page.handleJavaScriptDialog') answered = true;+ if (method === 'Page.enable') assert.equal(answered, true);+ };+ await client.startDialogHandling(7);+});++for (const action of ['abort', 'stop', 'timeout']) {+ test(`${action} releases blocked Page.enable startup`, async () => {+ const { client } = harness();+ const controller = new AbortController();+ let entered;+ const ready = new Promise(resolve => { entered = resolve; });+ let finish;+ client.sendCommand = () => { entered(); return new Promise(resolve => { finish = resolve; }); };+ const startup = client.startDialogHandling(7, { signal: controller.signal, timeoutMs: 20 });+ const rejected = assert.rejects(startup, error => action === 'timeout'+ ? error.code === 'dialog_startup_timeout' : error.name === 'AbortError');+ await ready;+ if (action === 'abort') controller.abort();+ if (action === 'stop') client.stopDialogHandling(7);+ await rejected;+ assert.equal(client.dialogRuns.has(7), false);+ finish();+ await tick();+ assert.equal(client.dialogRuns.has(7), false);+ });+}++test('failed workflow setup releases its debugger but preserves a Dev owner', async () => {+ const previousChrome = globalThis.chrome;+ const area = { get: async () => ({}), set: async () => {}, remove: async () => {} };+ let detaches = 0;+ globalThis.chrome = {+ storage: { local: area, session: area },+ runtime: { getURL: value => value },+ tabs: { get: async id => ({ id, url: 'https://example.com/' }) },+ debugger: { detach: (_target, callback) => { detaches++; callback(); } },+ };+ const { Agent } = await import('../src/chrome/src/agent/agent.js');+ const { cdpClient } = await import('../src/chrome/src/cdp/cdp-client.js');+ const originalAttach = cdpClient.attach;+ const originalSend = cdpClient.sendCommand;+ try {+ cdpClient.attach = async id => cdpClient.sessions.set(id, { tabId: id });+ cdpClient.sendCommand = async () => ({});+ for (const preserveDev of [false, true]) {+ const tabId = preserveDev ? 92 : 91;+ const agent = new Agent({ getActive: () => ({ promptTier: 'full' }) });+ agent._hydrate = async () => {};+ agent._currentUrl = async () => { throw new Error('workflow setup failure'); };+ if (preserveDev) cdpClient.devDiagnostics.set(tabId, {});+ await assert.rejects(agent.replaySavedWorkflow(tabId, { id: 'test', steps: [{}] }), /workflow setup failure/);+ assert.equal(agent.isRunning(tabId), false);+ assert.equal(cdpClient.dialogRuns.has(tabId), false);+ assert.equal(cdpClient.sessions.has(tabId), preserveDev);+ assert.equal(cdpClient.devDiagnostics.has(tabId), preserveDev);+ cdpClient.devDiagnostics.delete(tabId);+ cdpClient.sessions.delete(tabId);+ }+ assert.equal(detaches, 1);+ for (const streaming of [false, true]) {+ const tabId = streaming ? 94 : 93;+ const agent = new Agent({ getActive: () => ({ promptTier: 'full' }) });+ agent._hydrate = async () => {};+ agent._persistNow = async () => ({});+ agent._beginReadCompleteness = async () => '';+ let entered;+ const ready = new Promise(resolve => { entered = resolve; });+ cdpClient.sendCommand = async (_id, method) => {+ if (method === 'Page.enable') { entered(); return new Promise(() => {}); }+ return {};+ };+ const run = streaming+ ? agent.processMessageStream(tabId, 'Continue', () => {}, 'act')+ : agent.processMessage(tabId, 'Continue', () => {}, 'act');+ await ready;+ agent.abort(tabId);+ assert.match(await run, /Stopped by user/);+ assert.equal(agent.isRunning(tabId), false);+ assert.equal(cdpClient.sessions.has(tabId), false);+ assert.equal(cdpClient.dialogRuns.has(tabId), false);+ }++ } finally {+ cdpClient.attach = originalAttach;+ cdpClient.sendCommand = originalSend;+ globalThis.chrome = previousChrome;+ }+});