chrome-devtools-mcp 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -20
- package/build/src/BrowserManager.js +27 -18
- package/build/src/McpContext.js +435 -87
- package/build/src/McpPage.js +189 -59
- package/build/src/McpResponse.js +61 -44
- package/build/src/TextSnapshot.js +37 -18
- package/build/src/ToolHandler.js +256 -135
- package/build/src/bin/chrome-devtools-mcp-main.js +6 -4
- package/build/src/bin/chrome-devtools.js +4 -4
- package/build/src/collectors/PageCollector.js +13 -9
- package/build/src/collectors/ServiceWorkerCollector.js +2 -2
- package/build/src/collectors/constants.js +7 -0
- package/build/src/config/ConfigParser.js +44 -149
- package/build/src/config/ConfigWatcher.js +3 -2
- package/build/src/config/ServerConfig.js +251 -0
- package/build/src/config/browser-options.js +13 -4
- package/build/src/config/cli-options.js +35 -19
- package/build/src/config/mcp-options.js +61 -35
- package/build/src/config/puppeteer-options.js +4 -2
- package/build/src/daemon/client.js +3 -3
- package/build/src/daemon/daemon.js +7 -3
- package/build/src/daemon/utils.js +2 -1
- package/build/src/devtools/DevToolsCommentBridge.js +28 -5
- package/build/src/devtools/DevtoolsUtils.js +49 -12
- package/build/src/formatters/ConsoleFormatter.js +28 -1
- package/build/src/formatters/HeapSnapshotFormatter.js +14 -18
- package/build/src/formatters/NetworkFormatter.js +54 -15
- package/build/src/formatters/RemoteObjectFormatter.js +231 -0
- package/build/src/formatters/SnapshotFormatter.js +13 -3
- package/build/src/index.js +256 -104
- package/build/src/processors/HeapSnapshotManager.js +390 -128
- package/build/src/third_party/THIRD_PARTY_NOTICES +542 -445
- package/build/src/third_party/bundled-packages.json +2 -2
- package/build/src/third_party/cli.js +9239 -0
- package/build/src/third_party/devtools-formatter-worker.js +3089 -2438
- package/build/src/third_party/devtools-heap-snapshot-worker.js +172 -1
- package/build/src/third_party/index.js +52247 -55764
- package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +54576 -52174
- package/build/src/tools/ToolDefinition.js +90 -12
- package/build/src/tools/comments.js +42 -3
- package/build/src/tools/console.js +6 -4
- package/build/src/tools/css.js +1 -0
- package/build/src/tools/emulation.js +5 -4
- package/build/src/tools/extensions.js +5 -0
- package/build/src/tools/input.js +21 -6
- package/build/src/tools/lighthouse.js +24 -8
- package/build/src/tools/memory.js +59 -53
- package/build/src/tools/network.js +5 -4
- package/build/src/tools/pages.js +48 -6
- package/build/src/tools/performance.js +7 -4
- package/build/src/tools/pwa.js +7 -0
- package/build/src/tools/screencast.js +3 -1
- package/build/src/tools/screenshot.js +23 -7
- package/build/src/tools/script.js +38 -6
- package/build/src/tools/slim/tools.js +21 -5
- package/build/src/tools/snapshot.js +13 -3
- package/build/src/tools/thirdPartyDeveloper.js +3 -1
- package/build/src/tools/webmcp.js +2 -0
- package/build/src/utils/TaskRunner.js +136 -0
- package/build/src/utils/WaitForHelper.js +1 -1
- package/build/src/utils/bytes.js +2 -12
- package/build/src/utils/check-for-updates.js +1 -1
- package/build/src/utils/disclaimers.js +27 -0
- package/build/src/utils/keyboard.js +14 -2
- package/build/src/utils/logger.js +69 -0
- package/build/src/utils/resourceType.js +27 -0
- package/build/src/utils/text.js +29 -0
- package/build/src/utils/timeout.js +14 -0
- package/build/src/utils/url.js +41 -0
- package/build/src/version.js +1 -1
- package/package.json +5 -4
- package/skills/a11y-debugging/SKILL.md +3 -8
package/build/src/McpPage.js
CHANGED
|
@@ -59,7 +59,7 @@ import { DevToolsCommentBridge } from './devtools/DevToolsCommentBridge.js';
|
|
|
59
59
|
import { createTargetUniverse, } from './devtools/DevtoolsUtils.js';
|
|
60
60
|
import { ConsoleCollector, NetworkCollector, } from './collectors/PageCollector.js';
|
|
61
61
|
import { TextSnapshot } from './TextSnapshot.js';
|
|
62
|
-
import { PredefinedNetworkConditions, DevTools, } from './third_party/index.js';
|
|
62
|
+
import { PredefinedNetworkConditions, DevTools, lighthouseNavigation, lighthouseSnapshot, } from './third_party/index.js';
|
|
63
63
|
import { logger } from './utils/logger.js';
|
|
64
64
|
import { getNetworkMultiplierFromString, WaitForHelper, } from './utils/WaitForHelper.js';
|
|
65
65
|
export function replaceHtmlElementsWithUids(schema) {
|
|
@@ -143,6 +143,7 @@ export class McpPage {
|
|
|
143
143
|
id;
|
|
144
144
|
#pptrPage;
|
|
145
145
|
#initPromise;
|
|
146
|
+
#focusEmulationRequested = false;
|
|
146
147
|
#disposed = false;
|
|
147
148
|
#closed = false;
|
|
148
149
|
// Snapshot
|
|
@@ -159,21 +160,18 @@ export class McpPage {
|
|
|
159
160
|
#dialogHandler;
|
|
160
161
|
// Screencast
|
|
161
162
|
#screenRecorder = null;
|
|
162
|
-
|
|
163
|
+
// Performance trace
|
|
164
|
+
#isRunningPerformanceTrace = false;
|
|
163
165
|
#networkCollector;
|
|
164
166
|
#consoleCollector;
|
|
165
|
-
#hasNetworkBlockOrAllowlist;
|
|
166
167
|
#locatorClass;
|
|
167
168
|
#navigationTimeout;
|
|
168
|
-
#
|
|
169
|
+
#config;
|
|
169
170
|
#commentBridge;
|
|
170
|
-
#onNotification;
|
|
171
171
|
constructor(target, id, options) {
|
|
172
|
-
this.#
|
|
172
|
+
this.#config = options.config;
|
|
173
173
|
this.#locatorClass = options.locatorClass;
|
|
174
174
|
this.#navigationTimeout = options.navigationTimeout ?? NAVIGATION_TIMEOUT;
|
|
175
|
-
this.#sourceMaps = options.sourceMaps ?? true;
|
|
176
|
-
this.#onNotification = options.onNotification;
|
|
177
175
|
this.target = target;
|
|
178
176
|
this.id = id;
|
|
179
177
|
this.isolatedContextName = options.isolatedContextName;
|
|
@@ -181,6 +179,10 @@ export class McpPage {
|
|
|
181
179
|
this.#dialog = dialog;
|
|
182
180
|
};
|
|
183
181
|
}
|
|
182
|
+
get #hasNetworkBlockOrAllowlist() {
|
|
183
|
+
return Boolean(this.#config.resolved.allowedUrlPattern ||
|
|
184
|
+
this.#config.resolved.blockedUrlPattern);
|
|
185
|
+
}
|
|
184
186
|
get pptrPage() {
|
|
185
187
|
if (!this.#pptrPage) {
|
|
186
188
|
throw new Error(`McpPage (id=${this.id}) is not initialized. Call init() first.`);
|
|
@@ -242,20 +244,24 @@ export class McpPage {
|
|
|
242
244
|
this.dispose();
|
|
243
245
|
await page?.close({ runBeforeUnload: false });
|
|
244
246
|
}
|
|
245
|
-
async init() {
|
|
247
|
+
async init(options) {
|
|
246
248
|
if (this.#disposed) {
|
|
247
249
|
throw new Error(`McpPage (id=${this.id}) has already been disposed.`);
|
|
248
250
|
}
|
|
249
|
-
if (this.#initPromise) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
await this.#initPromise;
|
|
251
|
+
if (!this.#initPromise) {
|
|
252
|
+
this.#initPromise = this.#doInit().catch(err => {
|
|
253
|
+
this.#initPromise = undefined;
|
|
254
|
+
throw err;
|
|
255
|
+
});
|
|
255
256
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
257
|
+
await this.#initPromise;
|
|
258
|
+
// Discovery skips focus emulation, but a later page tool still needs it.
|
|
259
|
+
if (options?.emulateFocus !== false &&
|
|
260
|
+
!this.#disposed &&
|
|
261
|
+
!this.#focusEmulationRequested) {
|
|
262
|
+
// Prevent duplicate requests while pending and after success.
|
|
263
|
+
this.#focusEmulationRequested = true;
|
|
264
|
+
this.#initFocusEmulationNoThrow();
|
|
259
265
|
}
|
|
260
266
|
}
|
|
261
267
|
async #doInit() {
|
|
@@ -269,7 +275,9 @@ export class McpPage {
|
|
|
269
275
|
}
|
|
270
276
|
this.#pptrPage = page;
|
|
271
277
|
page.on('dialog', this.#dialogHandler);
|
|
272
|
-
this.#networkCollector = new NetworkCollector(page
|
|
278
|
+
this.#networkCollector = new NetworkCollector(page, {
|
|
279
|
+
maxNavigationSaved: this.#config.resolved.maxNavigationSaved,
|
|
280
|
+
});
|
|
273
281
|
this.#consoleCollector = new ConsoleCollector(page, collect => {
|
|
274
282
|
return {
|
|
275
283
|
console: event => {
|
|
@@ -282,20 +290,19 @@ export class McpPage {
|
|
|
282
290
|
collect(event);
|
|
283
291
|
},
|
|
284
292
|
};
|
|
285
|
-
});
|
|
293
|
+
}, { maxNavigationSaved: this.#config.resolved.maxNavigationSaved });
|
|
286
294
|
}
|
|
287
295
|
this.updateTimeouts();
|
|
288
|
-
await
|
|
289
|
-
this.#initDevToolsUniverseNoThrow(),
|
|
290
|
-
this.#initFocusEmulationNoThrow(),
|
|
291
|
-
]);
|
|
296
|
+
await this.#initDevToolsUniverseNoThrow();
|
|
292
297
|
if (this.#disposed) {
|
|
293
298
|
this.dispose();
|
|
294
299
|
}
|
|
295
300
|
}
|
|
296
|
-
|
|
297
|
-
//
|
|
301
|
+
#initFocusEmulationNoThrow() {
|
|
302
|
+
// Background pages need emulated focus for multi-agent workflows.
|
|
298
303
|
void this.pptrPage.emulateFocusedPage(true).catch(error => {
|
|
304
|
+
// Allow the next page operation to retry a transient failure.
|
|
305
|
+
this.#focusEmulationRequested = false;
|
|
299
306
|
logger?.('Error turning on focused page emulation', error);
|
|
300
307
|
});
|
|
301
308
|
}
|
|
@@ -306,17 +313,32 @@ export class McpPage {
|
|
|
306
313
|
try {
|
|
307
314
|
const session = await this.pptrPage.createCDPSession();
|
|
308
315
|
this.#devtoolsUniverse = await createTargetUniverse(session, {
|
|
309
|
-
sourceMaps: this.#sourceMaps,
|
|
316
|
+
sourceMaps: this.#config.resolved.sourceMaps,
|
|
310
317
|
});
|
|
311
318
|
}
|
|
312
319
|
catch (e) {
|
|
313
320
|
logger?.('Failed to initialize DevTools universe', e);
|
|
314
321
|
}
|
|
315
322
|
}
|
|
323
|
+
syncSourceMaps() {
|
|
324
|
+
if (!this.#devtoolsUniverse) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const sourceMaps = this.#config.resolved.sourceMaps;
|
|
328
|
+
this.#devtoolsUniverse.universe.settings
|
|
329
|
+
.resolve(DevTools.SDKSettings.jsSourceMapsEnabledSettingDescriptor)
|
|
330
|
+
.set(sourceMaps);
|
|
331
|
+
this.#devtoolsUniverse.universe.settings
|
|
332
|
+
.resolve(DevTools.SDKSettings.cssSourceMapsEnabledSettingDescriptor)
|
|
333
|
+
.set(sourceMaps);
|
|
334
|
+
}
|
|
316
335
|
get devtoolsUniverse() {
|
|
317
336
|
return this.#devtoolsUniverse;
|
|
318
337
|
}
|
|
319
338
|
getDialog() {
|
|
339
|
+
if (this.#dialog?.handled) {
|
|
340
|
+
this.#dialog = undefined;
|
|
341
|
+
}
|
|
320
342
|
return this.#dialog;
|
|
321
343
|
}
|
|
322
344
|
clearDialog() {
|
|
@@ -328,9 +350,16 @@ export class McpPage {
|
|
|
328
350
|
setScreenRecorder(data) {
|
|
329
351
|
this.#screenRecorder = data;
|
|
330
352
|
}
|
|
353
|
+
isRunningPerformanceTrace() {
|
|
354
|
+
return this.#isRunningPerformanceTrace;
|
|
355
|
+
}
|
|
356
|
+
setIsRunningPerformanceTrace(x) {
|
|
357
|
+
this.#isRunningPerformanceTrace = x;
|
|
358
|
+
}
|
|
331
359
|
throwIfDialogOpen() {
|
|
332
|
-
|
|
333
|
-
|
|
360
|
+
const dialog = this.getDialog();
|
|
361
|
+
if (dialog) {
|
|
362
|
+
throw new Error(`A dialog is open (${dialog.type()}: ${dialog.message()}).`);
|
|
334
363
|
}
|
|
335
364
|
}
|
|
336
365
|
#getDebuggingWebMcpToolGroups() {
|
|
@@ -352,13 +381,7 @@ export class McpPage {
|
|
|
352
381
|
},
|
|
353
382
|
];
|
|
354
383
|
}
|
|
355
|
-
|
|
356
|
-
return [
|
|
357
|
-
...this.#getDebuggingWebMcpToolGroups(),
|
|
358
|
-
...this.eventBasedThirdPartyTools,
|
|
359
|
-
];
|
|
360
|
-
}
|
|
361
|
-
async getToolGroups() {
|
|
384
|
+
async discoverThirdPartyDeveloperTools() {
|
|
362
385
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
363
386
|
try {
|
|
364
387
|
// Check if there is a `devtoolstooldiscovery` event listener
|
|
@@ -369,8 +392,7 @@ export class McpPage {
|
|
|
369
392
|
objectId: windowHandle.remoteObject().objectId,
|
|
370
393
|
});
|
|
371
394
|
if (listeners.find(l => l.type === 'devtoolstooldiscovery') === undefined) {
|
|
372
|
-
this
|
|
373
|
-
return this.getThirdPartyDeveloperTools();
|
|
395
|
+
return this.#getDebuggingWebMcpToolGroups();
|
|
374
396
|
}
|
|
375
397
|
const eventToolGroups = await this.pptrPage.evaluate(() => {
|
|
376
398
|
if (window.__dtmcp) {
|
|
@@ -445,8 +467,7 @@ export class McpPage {
|
|
|
445
467
|
replaceHtmlElementsWithUids(tool.inputSchema);
|
|
446
468
|
}
|
|
447
469
|
}
|
|
448
|
-
this
|
|
449
|
-
return this.getThirdPartyDeveloperTools();
|
|
470
|
+
return [...this.#getDebuggingWebMcpToolGroups(), ...eventToolGroups];
|
|
450
471
|
}
|
|
451
472
|
catch (e_1) {
|
|
452
473
|
env_1.error = e_1;
|
|
@@ -490,15 +511,17 @@ export class McpPage {
|
|
|
490
511
|
get commentBridge() {
|
|
491
512
|
return this.#commentBridge;
|
|
492
513
|
}
|
|
514
|
+
disposeCommentBridge() {
|
|
515
|
+
this.#commentBridge?.dispose();
|
|
516
|
+
this.#commentBridge = undefined;
|
|
517
|
+
}
|
|
493
518
|
/**
|
|
494
519
|
* Returns the comment bridge attached to the DevTools page, or undefined if
|
|
495
520
|
* the DevTools page does not support DevTools comments.
|
|
496
521
|
*/
|
|
497
522
|
async ensureDevToolsCommentBridge(devtoolsPage) {
|
|
498
523
|
if (!this.#commentBridge) {
|
|
499
|
-
this.#commentBridge = new DevToolsCommentBridge(
|
|
500
|
-
onNotification: this.#onNotification,
|
|
501
|
-
});
|
|
524
|
+
this.#commentBridge = new DevToolsCommentBridge();
|
|
502
525
|
}
|
|
503
526
|
const attached = await this.#commentBridge.attach(devtoolsPage);
|
|
504
527
|
return attached ? this.#commentBridge : undefined;
|
|
@@ -519,7 +542,9 @@ export class McpPage {
|
|
|
519
542
|
}
|
|
520
543
|
async openDevTools() {
|
|
521
544
|
const devtoolsPage = await this.pptrPage.openDevTools();
|
|
522
|
-
|
|
545
|
+
if (this.#config.resolved.devtoolsComments) {
|
|
546
|
+
await this.ensureDevToolsCommentBridge(devtoolsPage);
|
|
547
|
+
}
|
|
523
548
|
return devtoolsPage;
|
|
524
549
|
}
|
|
525
550
|
getConsoleData(includePreservedMessages) {
|
|
@@ -568,8 +593,15 @@ export class McpPage {
|
|
|
568
593
|
}
|
|
569
594
|
dispose() {
|
|
570
595
|
this.#disposed = true;
|
|
571
|
-
this.#
|
|
572
|
-
this
|
|
596
|
+
this.#isRunningPerformanceTrace = false;
|
|
597
|
+
this.disposeCommentBridge();
|
|
598
|
+
if (this.#screenRecorder) {
|
|
599
|
+
const { recorder } = this.#screenRecorder;
|
|
600
|
+
this.#screenRecorder = null;
|
|
601
|
+
void recorder.stop().catch(e => {
|
|
602
|
+
logger?.('Failed to stop screencast recording on dispose', e);
|
|
603
|
+
});
|
|
604
|
+
}
|
|
573
605
|
this.#pptrPage?.off('dialog', this.#dialogHandler);
|
|
574
606
|
this.#networkCollector?.dispose();
|
|
575
607
|
this.#consoleCollector?.dispose();
|
|
@@ -905,9 +937,10 @@ export class McpPage {
|
|
|
905
937
|
logger?.('No DevTools page detected');
|
|
906
938
|
return {};
|
|
907
939
|
}
|
|
908
|
-
|
|
940
|
+
if (this.#config.resolved.devtoolsComments) {
|
|
941
|
+
await this.ensureDevToolsCommentBridge(devtoolsPage);
|
|
942
|
+
}
|
|
909
943
|
const { cdpRequestId, cdpBackendNodeId } = await devtoolsPage.evaluate(async () => {
|
|
910
|
-
window.universe?.cd4aBridge?.setAgentAttached(true);
|
|
911
944
|
// @ts-expect-error no types
|
|
912
945
|
const UI = await import('/bundled/ui/legacy/legacy.js');
|
|
913
946
|
// @ts-expect-error no types
|
|
@@ -928,6 +961,19 @@ export class McpPage {
|
|
|
928
961
|
}
|
|
929
962
|
async restoreEmulation() {
|
|
930
963
|
const currentSetting = this.emulationSettings;
|
|
964
|
+
const { viewport } = currentSetting;
|
|
965
|
+
if (viewport) {
|
|
966
|
+
// Lighthouse's CDP session replaces the device metrics override and
|
|
967
|
+
// clears it on detach, and Chrome ignores an override identical to the
|
|
968
|
+
// last one this session sent. A different width first makes the real
|
|
969
|
+
// call take effect without a reload (`isMobile` and `hasTouch` stay the
|
|
970
|
+
// same). This also runs after snapshot audits and fires a resize event,
|
|
971
|
+
// so do not remove it as redundant.
|
|
972
|
+
await this.pptrPage.setViewport({
|
|
973
|
+
...viewport,
|
|
974
|
+
width: Math.max(1, viewport.width - 1),
|
|
975
|
+
});
|
|
976
|
+
}
|
|
931
977
|
await this.emulate(currentSetting);
|
|
932
978
|
}
|
|
933
979
|
async #emulateMediaFeatures(settings) {
|
|
@@ -991,7 +1037,7 @@ export class McpPage {
|
|
|
991
1037
|
newSettings.cpuThrottlingRate = options.cpuThrottlingRate;
|
|
992
1038
|
}
|
|
993
1039
|
if (!options.geolocation) {
|
|
994
|
-
await page.setGeolocation(
|
|
1040
|
+
await page.setGeolocation(null);
|
|
995
1041
|
delete newSettings.geolocation;
|
|
996
1042
|
}
|
|
997
1043
|
else {
|
|
@@ -1051,11 +1097,34 @@ export class McpPage {
|
|
|
1051
1097
|
delete newSettings.extraHttpHeaders;
|
|
1052
1098
|
}
|
|
1053
1099
|
}
|
|
1100
|
+
const previousViewport = this.emulationSettings.viewport;
|
|
1054
1101
|
this.emulationSettings = Object.keys(newSettings).length ? newSettings : {};
|
|
1055
1102
|
this.updateTimeouts();
|
|
1056
1103
|
// This should happen after updating the page timeouts.
|
|
1057
1104
|
// Setting the viewport can trigger a reload which we don't want to timeout.
|
|
1058
|
-
|
|
1105
|
+
try {
|
|
1106
|
+
await page.setViewport(newSettings.viewport ?? null);
|
|
1107
|
+
}
|
|
1108
|
+
catch (error) {
|
|
1109
|
+
if (previousViewport) {
|
|
1110
|
+
newSettings.viewport = previousViewport;
|
|
1111
|
+
}
|
|
1112
|
+
else {
|
|
1113
|
+
delete newSettings.viewport;
|
|
1114
|
+
}
|
|
1115
|
+
this.emulationSettings = Object.keys(newSettings).length
|
|
1116
|
+
? newSettings
|
|
1117
|
+
: {};
|
|
1118
|
+
throw error;
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
async clearNetworkConditions() {
|
|
1122
|
+
if (!this.emulationSettings.networkConditions) {
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1125
|
+
await this.#pptrPage?.emulateNetworkConditions(null);
|
|
1126
|
+
delete this.emulationSettings.networkConditions;
|
|
1127
|
+
this.updateTimeouts();
|
|
1059
1128
|
}
|
|
1060
1129
|
updateTimeouts() {
|
|
1061
1130
|
if (!this.#pptrPage) {
|
|
@@ -1071,23 +1140,84 @@ export class McpPage {
|
|
|
1071
1140
|
const networkMultiplier = getNetworkMultiplierFromString(this.networkConditions);
|
|
1072
1141
|
this.pptrPage.setDefaultNavigationTimeout(this.#navigationTimeout * networkMultiplier * cpuMultiplier);
|
|
1073
1142
|
}
|
|
1074
|
-
waitForTextOnPage(text,
|
|
1075
|
-
const
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1143
|
+
waitForTextOnPage(text, options = {}) {
|
|
1144
|
+
const { timeout, visible } = options;
|
|
1145
|
+
const page = this.pptrPage;
|
|
1146
|
+
const initialFrames = page.frames();
|
|
1147
|
+
const observedFrames = new Set(initialFrames);
|
|
1148
|
+
const controller = new AbortController();
|
|
1149
|
+
const locatorForFrames = (frames) => this.#locatorClass.race(frames.flatMap(frame => text.flatMap(value => {
|
|
1150
|
+
const locators = [
|
|
1151
|
+
frame.locator(`aria/${value}`),
|
|
1152
|
+
frame.locator(`text/${value}`),
|
|
1153
|
+
];
|
|
1154
|
+
return visible
|
|
1155
|
+
? locators.map(locator => locator.setVisibility('visible'))
|
|
1156
|
+
: locators;
|
|
1157
|
+
})));
|
|
1158
|
+
let initialLocator = locatorForFrames(initialFrames);
|
|
1080
1159
|
if (timeout) {
|
|
1081
|
-
|
|
1160
|
+
initialLocator = initialLocator.setTimeout(timeout);
|
|
1082
1161
|
}
|
|
1083
|
-
return
|
|
1162
|
+
return new Promise((resolve, reject) => {
|
|
1163
|
+
let settled = false;
|
|
1164
|
+
const cleanup = () => {
|
|
1165
|
+
if (settled) {
|
|
1166
|
+
return false;
|
|
1167
|
+
}
|
|
1168
|
+
settled = true;
|
|
1169
|
+
page.off('frameattached', onFrameAttached);
|
|
1170
|
+
controller.abort();
|
|
1171
|
+
return true;
|
|
1172
|
+
};
|
|
1173
|
+
const finish = (element) => {
|
|
1174
|
+
if (cleanup()) {
|
|
1175
|
+
resolve(element);
|
|
1176
|
+
}
|
|
1177
|
+
};
|
|
1178
|
+
const fail = (error) => {
|
|
1179
|
+
if (cleanup()) {
|
|
1180
|
+
reject(error);
|
|
1181
|
+
}
|
|
1182
|
+
};
|
|
1183
|
+
const onFrameAttached = (frame) => {
|
|
1184
|
+
if (observedFrames.has(frame)) {
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1187
|
+
observedFrames.add(frame);
|
|
1188
|
+
// The initial locator race does not include frames added later.
|
|
1189
|
+
// Watch each new frame until the initial race resolves or times out.
|
|
1190
|
+
// A timeout of 0 disables the frame timer; controller.abort() stops it.
|
|
1191
|
+
void locatorForFrames([frame])
|
|
1192
|
+
.setTimeout(0)
|
|
1193
|
+
.wait({ signal: controller.signal })
|
|
1194
|
+
.then(finish, error => {
|
|
1195
|
+
if (controller.signal.aborted) {
|
|
1196
|
+
return;
|
|
1197
|
+
}
|
|
1198
|
+
logger?.('Failed to wait for text in an attached frame', error);
|
|
1199
|
+
});
|
|
1200
|
+
};
|
|
1201
|
+
page.on('frameattached', onFrameAttached);
|
|
1202
|
+
void initialLocator.wait({ signal: controller.signal }).then(finish, fail);
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
lighthouseNavigation(flags) {
|
|
1206
|
+
return lighthouseNavigation(this.pptrPage, this.pptrPage.url(), {
|
|
1207
|
+
flags,
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
lighthouseSnapshot(flags) {
|
|
1211
|
+
return lighthouseSnapshot(this.pptrPage, {
|
|
1212
|
+
flags,
|
|
1213
|
+
});
|
|
1084
1214
|
}
|
|
1085
1215
|
/**
|
|
1086
1216
|
* We need to ignore favicon request as they make our test flaky
|
|
1087
1217
|
*/
|
|
1088
1218
|
async setUpNetworkCollectorForTesting() {
|
|
1089
1219
|
this.networkCollector.dispose();
|
|
1090
|
-
this.networkCollector = new NetworkCollector(this.pptrPage,
|
|
1220
|
+
this.networkCollector = new NetworkCollector(this.pptrPage, { maxNavigationSaved: this.#config.resolved.maxNavigationSaved }, collect => {
|
|
1091
1221
|
return {
|
|
1092
1222
|
request: req => {
|
|
1093
1223
|
if (req.url().includes('favicon.ico')) {
|