Skip to content

Chrome DevTools for coding agents

revert: support experimental allowlist for navigate tool calls (#1935) (#2203)

Nikolay Vitkovca8d219edee2
diff --git a/package-lock.json b/package-lock.json
index 4afc9066..762992c1 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -47,7 +47,6 @@
"sinon": "^22.0.0",
"typescript": "^6.0.2",
"typescript-eslint": "^8.43.0",
- "urlpattern-polyfill": "^10.1.0",
"yargs": "18.0.0"
},
"engines": {
@@ -8274,13 +8273,6 @@
"punycode": "^2.1.0"
}
},
- "node_modules/urlpattern-polyfill": {
- "version": "10.1.0",
- "resolved": "https://registry.npmjs.org/urlpattern-polyfill/-/urlpattern-polyfill-10.1.0.tgz",
- "integrity": "sha512-IGjKp/o0NL3Bso1PymYURCJxMPNAf/ILOpendP9f5B6e1rTJgdgiOvgfoT8VxCAdY+Wisb9uhGaJJf3yZ2V9nw==",
- "dev": true,
- "license": "MIT"
- },
"node_modules/vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
diff --git a/package.json b/package.json
index 50194251..00fa98ee 100644
--- a/package.json
+++ b/package.json
@@ -82,7 +82,6 @@
"sinon": "^22.0.0",
"typescript": "^6.0.2",
"typescript-eslint": "^8.43.0",
- "urlpattern-polyfill": "^10.1.0",
"yargs": "18.0.0"
},
"peerDependencies": {
diff --git a/src/bin/chrome-devtools-mcp-cli-options.ts b/src/bin/chrome-devtools-mcp-cli-options.ts
index 2fe8fc69..c943b7c3 100644
--- a/src/bin/chrome-devtools-mcp-cli-options.ts
+++ b/src/bin/chrome-devtools-mcp-cli-options.ts
@@ -188,11 +188,6 @@ export const cliOptions = {
describe:
'Whether to include all kinds of pages such as webviews or background pages as pages.',
},
- experimentalNavigationAllowlist: {
- type: 'boolean',
- describe: 'Whether to enable navigation allowlist tool parameter.',
- hidden: true,
- },
experimentalInteropTools: {
type: 'boolean',
describe: 'Whether to enable interoperability tools',
diff --git a/src/telemetry/flag_usage_metrics.json b/src/telemetry/flag_usage_metrics.json
index a73b1a31..da297928 100644
--- a/src/telemetry/flag_usage_metrics.json
+++ b/src/telemetry/flag_usage_metrics.json
@@ -232,11 +232,13 @@
},
{
"name": "experimental_navigation_allowlist",
- "flagType": "boolean"
+ "flagType": "boolean",
+ "isDeprecated": true
},
{
"name": "experimental_navigation_allowlist_present",
- "flagType": "boolean"
+ "flagType": "boolean",
+ "isDeprecated": true
},
{
"name": "experimental_page_id_routing",
diff --git a/src/third_party/index.ts b/src/third_party/index.ts
index e9e6cfc3..41772e33 100644
--- a/src/third_party/index.ts
+++ b/src/third_party/index.ts
@@ -4,7 +4,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-import 'urlpattern-polyfill';
import 'core-js/modules/es.promise.with-resolvers.js';
import 'core-js/modules/es.set.union.v2.js';
import 'core-js/proposals/iterator-helpers.js';
diff --git a/src/tools/pages.ts b/src/tools/pages.ts
index 0a74aa22..776f19dd 100644
--- a/src/tools/pages.ts
+++ b/src/tools/pages.ts
@@ -5,11 +5,10 @@
*/
import {logger} from '../logger.js';
-import type {CdpPage, Dialog, HTTPRequest} from '../third_party/index.js';
+import type {CdpPage, Dialog} from '../third_party/index.js';
import {zod} from '../third_party/index.js';
import {ToolCategory} from './categories.js';
-import type {ContextPage} from './ToolDefinition.js';
import {
CLOSE_PAGE_ERROR,
definePageTool,
@@ -17,64 +16,6 @@ import {
timeoutSchema,
} from './ToolDefinition.js';
-async function navigateWithInterception(
- page: ContextPage,
- action: () => Promise<unknown>,
- allowListString?: string,
- timeout?: number,
-): Promise<void> {
- const allowList = allowListString
- ? allowListString.split(',').map((p: string) => new URLPattern(p.trim()))
- : undefined;
-
- const requestHandler = (interceptedRequest: HTTPRequest) => {
- if (!interceptedRequest.isNavigationRequest()) {
- void interceptedRequest.continue();
- return;
- }
- const requestUrl = interceptedRequest.url();
- const isAllowed = allowList!.some((pattern: URLPattern) =>
- pattern.test(requestUrl),
- );
-
- if (isAllowed) {
- void interceptedRequest.continue();
- } else {
- logger?.(`Blocking request to: ${requestUrl}`);
- void interceptedRequest.abort('blockedbyclient');
- }
- };
-
- const cleanupInterception = async () => {
- if (allowList) {
- page.pptrPage.off('request', requestHandler);
- await page.pptrPage.setRequestInterception(false).catch(error => {
- logger?.(`Failed to disable request interception`, error);
- });
- }
- };
-
- if (allowList) {
- await page.pptrPage.setRequestInterception(true);
- page.pptrPage.on('request', requestHandler);
- }
-
- try {
- await page.waitForEventsAfterAction(
- async () => {
- try {
- await action();
- } finally {
- await cleanupInterception();
- }
- },
- {timeout},
- );
- } finally {
- await cleanupInterception();
- }
-}
-
export const listPages = defineTool(args => {
return {
name: 'list_pages',
@@ -155,7 +96,7 @@ export const closePage = defineTool({
},
});
-export const newPage = defineTool(args => {
+export const newPage = defineTool(() => {
return {
name: 'new_page',
description: `Open a new tab and load a URL. Use project URL if not specified otherwise.`,
@@ -179,16 +120,6 @@ export const newPage = defineTool(args => {
'Pages in the same browser context share cookies and storage. ' +
'Pages in different browser contexts are fully isolated.',
),
- ...(args?.experimentalNavigationAllowlist
- ? {
- allowList: zod
- .string()
- .optional()
- .describe(
- 'Optional comma-separated list of URL patterns to allow. If provided, all other navigations will be blocked.',
- ),
- }
- : {}),
...timeoutSchema,
},
blockedByDialog: false,
@@ -199,14 +130,13 @@ export const newPage = defineTool(args => {
request.params.isolatedContext,
);
- await navigateWithInterception(
- page,
- () =>
- page.pptrPage.goto(request.params.url, {
+ await page.waitForEventsAfterAction(
+ async () => {
+ await page.pptrPage.goto(request.params.url, {
timeout: request.params.timeout,
- }),
- request.params.allowList,
- request.params.timeout,
+ });
+ },
+ {timeout: request.params.timeout},
);
response.setIncludePages(true);
@@ -215,7 +145,7 @@ export const newPage = defineTool(args => {
};
});
-export const navigatePage = definePageTool(args => {
+export const navigatePage = definePageTool(() => {
return {
name: 'navigate_page',
description: `Go to a URL, or back, forward, or reload. Use project URL if not specified otherwise.`,
@@ -247,16 +177,6 @@ export const navigatePage = definePageTool(args => {
.describe(
'A JavaScript script to be executed on each new document before any other scripts for the next navigation.',
),
- ...(args?.experimentalNavigationAllowlist
- ? {
- allowList: zod
- .string()
- .optional()
- .describe(
- 'Optional comma-separated list of URL patterns to allow. If provided, all other navigations will be blocked.',
- ),
- }
- : {}),
...timeoutSchema,
},
blockedByDialog: false,
@@ -301,8 +221,7 @@ export const navigatePage = definePageTool(args => {
page.pptrPage.on('dialog', dialogHandler);
try {
- await navigateWithInterception(
- page,
+ await page.waitForEventsAfterAction(
async () => {
switch (request.params.type) {
case 'url':
@@ -363,8 +282,7 @@ export const navigatePage = definePageTool(args => {
break;
}
},
- request.params.allowList,
- request.params.timeout,
+ {timeout: request.params.timeout},
);
} finally {
page.pptrPage.off('dialog', dialogHandler);
diff --git a/tests/third_party_notices.test.js.snapshot b/tests/third_party_notices.test.js.snapshot
index 0e1fe922..a3901afe 100644
--- a/tests/third_party_notices.test.js.snapshot
+++ b/tests/third_party_notices.test.js.snapshot
@@ -1,31 +1,4 @@
exports[`THIRD_PARTY_NOTICES > matches snapshot if exists 1`] = `
-Name: urlpattern-polyfill
-URL: https://github.com/kenchris/urlpattern-polyfill
-Version: <VERSION>
-License: MIT
-
-Copyright 2020 Intel Corporation
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-
--------------------- DEPENDENCY DIVIDER --------------------
-
Name: core-js
URL: https://core-js.io
Version: <VERSION>
diff --git a/tests/tools/pagesNavigateAllowlist.test.ts b/tests/tools/pagesNavigateAllowlist.test.ts
deleted file mode 100644
index 98da02d7..00000000
--- a/tests/tools/pagesNavigateAllowlist.test.ts
+++ /dev/null
@@ -1,102 +0,0 @@
-/**
- * @license
- * Copyright 2025 Google LLC
- * SPDX-License-Identifier: Apache-2.0
- */
-
-import assert from 'node:assert';
-import {describe, it} from 'node:test';
-
-import type {ParsedArguments} from '../../src/bin/chrome-devtools-mcp-cli-options.js';
-import {navigatePage} from '../../src/tools/pages.js';
-import {serverHooks} from '../server.js';
-import {withMcpContext} from '../utils.js';
-
-describe('pages allowList', () => {
- const server = serverHooks();
- const args = {experimentalNavigationAllowlist: true} as ParsedArguments;
-
- it('navigates through redirects when all URLs are allowed', async () => {
- server.addRoute('/a.html', (_req, res) => {
- res.writeHead(302, {Location: '/b.html'});
- res.end();
- });
- server.addRoute('/b.html', (_req, res) => {
- res.writeHead(302, {Location: '/c.html'});
- res.end();
- });
- server.addHtmlRoute(
- '/c.html',
- '<html><body><h1>Final Destination</h1></body></html>',
- );
-
- await withMcpContext(async (response, context) => {
- const page = context.getSelectedMcpPage();
- const baseUrl = server.baseUrl;
- const allowList = `${baseUrl}/a.html,${baseUrl}/b.html,${baseUrl}/c.html`;
-
- await navigatePage(args).handler(
- {
- params: {
- url: `${baseUrl}/a.html`,
- allowList,
- },
- page,
- },
- response,
- context,
- );
-
- assert.strictEqual(page.pptrPage.url(), `${baseUrl}/c.html`);
- const content = await page.pptrPage.evaluate(
- () => document.querySelector('h1')?.textContent,
- );
- assert.strictEqual(content, 'Final Destination');
- });
- });
-
- it('blocks navigation when a redirect target is not allowed', async () => {
- server.addRoute('/a.html', (_req, res) => {
- res.writeHead(302, {Location: '/b.html'});
- res.end();
- });
- server.addRoute('/b.html', (_req, res) => {
- res.writeHead(302, {Location: '/c.html'});
- res.end();
- });
- server.addHtmlRoute(
- '/c.html',
- '<html><body><h1>Final Destination</h1></body></html>',
- );
-
- await withMcpContext(async (response, context) => {
- const page = context.getSelectedMcpPage();
- const baseUrl = server.baseUrl;
- // b.html is missing from allowList
- const allowList = `${baseUrl}/a.html,${baseUrl}/c.html`;
-
- await navigatePage(args).handler(
- {
- params: {
- url: `${baseUrl}/a.html`,
- allowList,
- timeout: 2000, // Short timeout for failure
- },
- page,
- },
- response,
- context,
- );
-
- // The navigation to b.html should be blocked.
- // Puppeteer's goto will likely throw a timeout or net::ERR_ABORTED error.
- const url = page.pptrPage.url();
- assert.notStrictEqual(url, `${baseUrl}/c.html`);
- assert.ok(
- response.responseLines.some(line =>
- line.includes('Unable to navigate'),
- ),
- );
- });
- });
-});