Skip to content

Chrome DevTools for coding agents

chore: polyfill DisposableStack and AsyncDisposableStack (#2492)

Nikolay Vitkov2c7f594f0b95
diff --git a/src/McpPage.ts b/src/McpPage.ts
index 21d9ca93..3ed0b7c6 100644
--- a/src/McpPage.ts
+++ b/src/McpPage.ts
@@ -4,8 +4,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-import {DisposableStack} from './third_party/index.js';
-
export function replaceHtmlElementsWithUids(schema: JSONSchema7Definition) {
if (typeof schema === 'boolean') {
return;
diff --git a/src/TextSnapshot.ts b/src/TextSnapshot.ts
index a65d53e6..4de543f5 100644
--- a/src/TextSnapshot.ts
+++ b/src/TextSnapshot.ts
@@ -4,7 +4,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-import {DisposableStack} from './third_party/index.js';
import type {McpPage} from './McpPage.js';
import type {
Protocol,
diff --git a/src/tools/script.ts b/src/tools/script.ts
index 3c7611a3..8e58b3a1 100644
--- a/src/tools/script.ts
+++ b/src/tools/script.ts
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
-import {DisposableStack, zod} from '../third_party/index.js';
+import {zod} from '../third_party/index.js';
import type {Frame, JSHandle, Page, WebWorker} from '../third_party/index.js';
import type {ExtensionServiceWorker} from '../types.js';
diff --git a/src/utils/polyfill.ts b/src/utils/polyfill.ts
index d7fdd997..6955bb20 100644
--- a/src/utils/polyfill.ts
+++ b/src/utils/polyfill.ts
@@ -1,8 +1,10 @@
/**
* @license
- * Copyright 2025 Google Inc.
+ * Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
-// polyfills are now bundled with all other dependencies
-import '../third_party/index.js';
+import {DisposableStack, AsyncDisposableStack} from '../third_party/index.js';
+
+globalThis.DisposableStack ??= DisposableStack;
+globalThis.AsyncDisposableStack ??= AsyncDisposableStack;
diff --git a/tsconfig.json b/tsconfig.json
index 5281842f..8f8b5d2b 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -5,6 +5,7 @@
"ES2023",
"DOM",
"ES2024.Promise",
+ "ESNext.Disposable",
"ESNext.Iterator",
"ESNext.Collection"
],