patchright-core 1.58.2 → 1.59.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/ThirdPartyNotices.txt +126 -650
- package/browsers.json +16 -14
- package/lib/bootstrap.js +77 -0
- package/lib/cli/browserActions.js +308 -0
- package/lib/cli/driver.js +3 -2
- package/lib/cli/installActions.js +171 -0
- package/lib/cli/program.js +47 -411
- package/lib/client/android.js +4 -4
- package/lib/client/api.js +3 -3
- package/lib/client/browser.js +8 -0
- package/lib/client/browserContext.js +22 -61
- package/lib/client/browserType.js +19 -51
- package/lib/client/cdpSession.js +6 -2
- package/lib/client/channelOwner.js +1 -1
- package/lib/client/clientHelper.js +2 -1
- package/lib/client/clock.js +0 -1
- package/lib/client/{webSocket.js → connect.js} +57 -7
- package/lib/client/connection.js +8 -4
- package/lib/client/consoleMessage.js +3 -0
- package/lib/client/debugger.js +57 -0
- package/lib/client/dialog.js +8 -1
- package/lib/client/disposable.js +76 -0
- package/lib/client/electron.js +1 -0
- package/lib/client/elementHandle.js +1 -4
- package/lib/client/events.js +3 -3
- package/lib/client/fetch.js +0 -1
- package/lib/client/frame.js +10 -23
- package/lib/client/harRouter.js +13 -1
- package/lib/client/jsHandle.js +4 -8
- package/lib/client/locator.js +13 -44
- package/lib/client/network.js +15 -16
- package/lib/client/page.js +41 -75
- package/lib/client/platform.js +0 -3
- package/lib/client/screencast.js +88 -0
- package/lib/client/selectors.js +3 -1
- package/lib/client/tracing.js +11 -5
- package/lib/client/video.js +13 -20
- package/lib/client/worker.js +6 -6
- package/lib/generated/bindingsControllerSource.js +1 -1
- package/lib/generated/clockSource.js +1 -1
- package/lib/generated/injectedScriptSource.js +1 -1
- package/lib/generated/pollingRecorderSource.js +1 -1
- package/lib/generated/storageScriptSource.js +1 -1
- package/lib/generated/utilityScriptSource.js +1 -1
- package/lib/mcpBundle.js +0 -6
- package/lib/mcpBundleImpl.js +91 -0
- package/lib/protocol/validator.js +224 -138
- package/lib/protocol/validatorPrimitives.js +1 -1
- package/lib/remote/playwrightConnection.js +10 -8
- package/lib/remote/playwrightPipeServer.js +100 -0
- package/lib/remote/playwrightServer.js +13 -8
- package/lib/remote/playwrightWebSocketServer.js +73 -0
- package/lib/remote/serverTransport.js +96 -0
- package/lib/server/android/android.js +2 -2
- package/lib/server/bidi/bidiBrowser.js +30 -8
- package/lib/server/bidi/bidiChromium.js +18 -5
- package/lib/server/bidi/bidiNetworkManager.js +39 -11
- package/lib/server/bidi/bidiPage.js +31 -15
- package/lib/server/bidi/third_party/firefoxPrefs.js +3 -1
- package/lib/server/browser.js +84 -21
- package/lib/server/browserContext.js +110 -58
- package/lib/server/browserType.js +14 -12
- package/lib/server/chromium/chromium.js +15 -12
- package/lib/server/chromium/chromiumSwitches.js +14 -2
- package/lib/server/chromium/crBrowser.js +20 -17
- package/lib/server/chromium/crCoverage.js +1 -13
- package/lib/server/chromium/crDevTools.js +1 -0
- package/lib/server/chromium/crNetworkManager.js +12 -267
- package/lib/server/chromium/crPage.js +67 -199
- package/lib/server/chromium/crServiceWorker.js +7 -14
- package/lib/server/clock.js +33 -41
- package/lib/server/console.js +5 -1
- package/lib/server/debugController.js +12 -6
- package/lib/server/debugger.js +40 -47
- package/lib/server/deviceDescriptorsSource.json +137 -137
- package/lib/server/dispatchers/browserContextDispatcher.js +29 -30
- package/lib/server/dispatchers/browserDispatcher.js +11 -5
- package/lib/server/dispatchers/browserTypeDispatcher.js +7 -0
- package/lib/server/dispatchers/cdpSessionDispatcher.js +4 -1
- package/lib/server/dispatchers/debuggerDispatcher.js +84 -0
- package/lib/server/dispatchers/dispatcher.js +1 -1
- package/lib/server/dispatchers/disposableDispatcher.js +39 -0
- package/lib/server/dispatchers/electronDispatcher.js +2 -1
- package/lib/server/dispatchers/frameDispatcher.js +6 -6
- package/lib/server/dispatchers/jsHandleDispatcher.js +2 -2
- package/lib/server/dispatchers/localUtilsDispatcher.js +37 -1
- package/lib/server/dispatchers/networkDispatchers.js +6 -5
- package/lib/server/dispatchers/pageDispatcher.js +101 -38
- package/lib/server/dispatchers/webSocketRouteDispatcher.js +4 -5
- package/lib/server/disposable.js +41 -0
- package/lib/server/dom.js +44 -26
- package/lib/server/download.js +3 -2
- package/lib/server/electron/electron.js +12 -7
- package/lib/server/firefox/ffBrowser.js +9 -19
- package/lib/server/firefox/ffInput.js +21 -5
- package/lib/server/firefox/ffNetworkManager.js +2 -2
- package/lib/server/firefox/ffPage.js +24 -27
- package/lib/server/frameSelectors.js +5 -172
- package/lib/server/frames.js +234 -687
- package/lib/server/har/harRecorder.js +2 -2
- package/lib/server/har/harTracer.js +5 -4
- package/lib/server/input.js +49 -4
- package/lib/server/instrumentation.js +5 -0
- package/lib/server/javascript.js +6 -26
- package/lib/server/launchApp.js +1 -3
- package/lib/server/localUtils.js +6 -6
- package/lib/server/network.js +9 -8
- package/lib/server/overlay.js +138 -0
- package/lib/server/page.js +157 -105
- package/lib/server/progress.js +6 -0
- package/lib/server/recorder/recorderApp.js +9 -8
- package/lib/server/recorder.js +76 -40
- package/lib/server/registry/index.js +55 -82
- package/lib/server/registry/nativeDeps.js +1 -0
- package/lib/server/screencast.js +90 -143
- package/lib/server/screenshotter.js +0 -6
- package/lib/server/trace/recorder/snapshotter.js +8 -17
- package/lib/server/trace/recorder/snapshotterInjected.js +82 -20
- package/lib/server/trace/recorder/tracing.js +87 -44
- package/lib/server/trace/viewer/traceViewer.js +3 -4
- package/lib/server/usKeyboardLayout.js +7 -0
- package/lib/server/utils/comparators.js +1 -1
- package/lib/server/utils/disposable.js +32 -0
- package/lib/server/utils/eventsHelper.js +3 -1
- package/lib/server/utils/fileUtils.js +16 -2
- package/lib/server/utils/happyEyeballs.js +15 -12
- package/lib/server/utils/hostPlatform.js +0 -15
- package/lib/server/utils/httpServer.js +5 -3
- package/lib/server/utils/network.js +2 -1
- package/lib/server/utils/nodePlatform.js +0 -6
- package/lib/server/utils/processLauncher.js +8 -6
- package/lib/server/utils/zipFile.js +2 -2
- package/lib/server/videoRecorder.js +82 -12
- package/lib/server/webkit/wkBrowser.js +1 -6
- package/lib/server/webkit/wkPage.js +27 -25
- package/lib/server/webkit/wkWorkers.js +2 -1
- package/lib/serverRegistry.js +156 -0
- package/lib/tools/backend/browserBackend.js +79 -0
- package/lib/tools/backend/common.js +63 -0
- package/lib/tools/backend/config.js +41 -0
- package/lib/tools/backend/console.js +66 -0
- package/lib/tools/backend/context.js +296 -0
- package/lib/tools/backend/cookies.js +152 -0
- package/lib/tools/backend/devtools.js +69 -0
- package/lib/tools/backend/dialogs.js +59 -0
- package/lib/tools/backend/evaluate.js +64 -0
- package/lib/tools/backend/files.js +60 -0
- package/lib/tools/backend/form.js +64 -0
- package/lib/tools/backend/keyboard.js +155 -0
- package/lib/tools/backend/logFile.js +95 -0
- package/lib/tools/backend/mouse.js +168 -0
- package/lib/tools/backend/navigate.js +106 -0
- package/lib/tools/backend/network.js +135 -0
- package/lib/tools/backend/pdf.js +48 -0
- package/lib/tools/backend/response.js +305 -0
- package/lib/tools/backend/route.js +140 -0
- package/lib/tools/backend/runCode.js +77 -0
- package/lib/tools/backend/screenshot.js +88 -0
- package/lib/tools/backend/sessionLog.js +74 -0
- package/lib/tools/backend/snapshot.js +208 -0
- package/lib/tools/backend/storage.js +68 -0
- package/lib/tools/backend/tab.js +445 -0
- package/lib/tools/backend/tabs.js +67 -0
- package/lib/tools/backend/tool.js +47 -0
- package/lib/tools/backend/tools.js +102 -0
- package/lib/tools/backend/tracing.js +78 -0
- package/lib/tools/backend/utils.js +83 -0
- package/lib/tools/backend/verify.js +151 -0
- package/lib/tools/backend/video.js +98 -0
- package/lib/tools/backend/wait.js +63 -0
- package/lib/tools/backend/webstorage.js +223 -0
- package/lib/tools/cli-client/cli.js +6 -0
- package/lib/tools/cli-client/help.json +399 -0
- package/lib/tools/cli-client/minimist.js +128 -0
- package/lib/tools/cli-client/program.js +350 -0
- package/lib/tools/cli-client/registry.js +176 -0
- package/lib/tools/cli-client/session.js +289 -0
- package/lib/tools/cli-client/skill/SKILL.md +328 -0
- package/lib/tools/cli-client/skill/references/element-attributes.md +23 -0
- package/lib/tools/cli-client/skill/references/playwright-tests.md +39 -0
- package/lib/tools/cli-client/skill/references/request-mocking.md +87 -0
- package/lib/tools/cli-client/skill/references/running-code.md +231 -0
- package/lib/tools/cli-client/skill/references/session-management.md +169 -0
- package/lib/tools/cli-client/skill/references/storage-state.md +275 -0
- package/lib/tools/cli-client/skill/references/test-generation.md +88 -0
- package/lib/tools/cli-client/skill/references/tracing.md +139 -0
- package/lib/tools/cli-client/skill/references/video-recording.md +143 -0
- package/lib/tools/cli-daemon/command.js +73 -0
- package/lib/tools/cli-daemon/commands.js +956 -0
- package/lib/tools/cli-daemon/daemon.js +157 -0
- package/lib/tools/cli-daemon/helpGenerator.js +177 -0
- package/lib/tools/cli-daemon/program.js +129 -0
- package/lib/tools/dashboard/appIcon.png +0 -0
- package/lib/tools/dashboard/dashboardApp.js +284 -0
- package/lib/tools/dashboard/dashboardController.js +296 -0
- package/lib/tools/exports.js +60 -0
- package/lib/tools/mcp/browserFactory.js +233 -0
- package/lib/tools/mcp/cdpRelay.js +352 -0
- package/lib/tools/mcp/cli-stub.js +7 -0
- package/lib/tools/mcp/config.d.js +16 -0
- package/lib/tools/mcp/config.js +446 -0
- package/lib/tools/mcp/configIni.js +189 -0
- package/lib/tools/mcp/extensionContextFactory.js +55 -0
- package/lib/tools/mcp/index.js +62 -0
- package/lib/tools/mcp/log.js +35 -0
- package/lib/tools/mcp/program.js +107 -0
- package/lib/tools/mcp/protocol.js +28 -0
- package/lib/tools/mcp/watchdog.js +44 -0
- package/lib/tools/trace/SKILL.md +171 -0
- package/lib/{server/trace/viewer/traceParser.js → tools/trace/installSkill.js} +15 -39
- package/lib/tools/trace/traceActions.js +142 -0
- package/lib/tools/trace/traceAttachments.js +69 -0
- package/lib/tools/trace/traceCli.js +87 -0
- package/lib/tools/trace/traceConsole.js +97 -0
- package/lib/tools/trace/traceErrors.js +55 -0
- package/lib/tools/trace/traceOpen.js +69 -0
- package/lib/tools/trace/traceParser.js +96 -0
- package/lib/tools/trace/traceRequests.js +182 -0
- package/lib/tools/trace/traceScreenshot.js +68 -0
- package/lib/tools/trace/traceSnapshot.js +149 -0
- package/lib/tools/trace/traceUtils.js +153 -0
- package/lib/tools/utils/connect.js +32 -0
- package/lib/tools/utils/mcp/http.js +152 -0
- package/lib/tools/utils/mcp/server.js +230 -0
- package/lib/tools/utils/mcp/tool.js +47 -0
- package/lib/tools/utils/socketConnection.js +108 -0
- package/lib/utils/isomorphic/formatUtils.js +64 -0
- package/lib/utils/isomorphic/jsonSchema.js +89 -0
- package/lib/utils/isomorphic/mimeType.js +7 -2
- package/lib/utils/isomorphic/protocolFormatter.js +2 -2
- package/lib/utils/isomorphic/protocolMetainfo.js +127 -106
- package/lib/utils/isomorphic/stringUtils.js +3 -3
- package/lib/utils/isomorphic/timeoutRunner.js +3 -3
- package/lib/utils/isomorphic/trace/snapshotRenderer.js +35 -42
- package/lib/utils/isomorphic/trace/traceLoader.js +15 -14
- package/lib/utils/isomorphic/trace/traceModel.js +3 -2
- package/lib/utils/isomorphic/trace/traceModernizer.js +1 -0
- package/lib/utils/isomorphic/urlMatch.js +54 -1
- package/lib/utils/isomorphic/utilityScriptSerializers.js +11 -0
- package/lib/utils.js +6 -2
- package/lib/utilsBundle.js +3 -21
- package/lib/utilsBundleImpl/index.js +132 -133
- package/lib/vite/dashboard/assets/index-BAOybkp8.js +50 -0
- package/lib/vite/dashboard/assets/index-CZAYOG76.css +1 -0
- package/lib/vite/dashboard/index.html +28 -0
- package/lib/vite/htmlReport/index.html +2 -70
- package/lib/vite/htmlReport/report.css +1 -0
- package/lib/vite/htmlReport/report.js +72 -0
- package/lib/vite/recorder/assets/{codeMirrorModule-CFUTFUO7.js → codeMirrorModule-C8KMvO9L.js} +20 -20
- package/lib/vite/recorder/assets/index-CqAYX1I3.js +193 -0
- package/lib/vite/recorder/index.html +1 -1
- package/lib/vite/traceViewer/assets/{codeMirrorModule-BVA4h_ZY.js → codeMirrorModule-DS0FLvoc.js} +20 -20
- package/lib/vite/traceViewer/assets/defaultSettingsView-GTWI-W_B.js +262 -0
- package/lib/vite/traceViewer/defaultSettingsView.B4dS75f0.css +1 -0
- package/lib/vite/traceViewer/{index.BVu7tZDe.css → index.CzXZzn5A.css} +1 -1
- package/lib/vite/traceViewer/{index.BtyWtaE-.js → index.Dtstcb7U.js} +1 -1
- package/lib/vite/traceViewer/index.html +4 -4
- package/lib/vite/traceViewer/sw.bundle.js +4 -4
- package/lib/vite/traceViewer/uiMode.Vipi55dB.js +6 -0
- package/lib/vite/traceViewer/uiMode.html +3 -3
- package/lib/zipBundleImpl.js +2 -2
- package/lib/zodBundle.js +39 -0
- package/lib/zodBundleImpl.js +40 -0
- package/package.json +6 -1
- package/types/protocol.d.ts +947 -51
- package/types/types.d.ts +854 -74
- package/lib/client/pageAgent.js +0 -64
- package/lib/mcpBundleImpl/index.js +0 -147
- package/lib/server/agent/actionRunner.js +0 -335
- package/lib/server/agent/actions.js +0 -128
- package/lib/server/agent/codegen.js +0 -111
- package/lib/server/agent/context.js +0 -150
- package/lib/server/agent/expectTools.js +0 -156
- package/lib/server/agent/pageAgent.js +0 -204
- package/lib/server/agent/performTools.js +0 -262
- package/lib/server/agent/tool.js +0 -109
- package/lib/server/dispatchers/pageAgentDispatcher.js +0 -96
- package/lib/server/pageBinding.js +0 -87
- package/lib/utils/isomorphic/oldUtilityScriptSerializers.js +0 -248
- package/lib/vite/recorder/assets/index-CVkBxsGf.js +0 -193
- package/lib/vite/traceViewer/assets/defaultSettingsView-CjfmcdOz.js +0 -266
- package/lib/vite/traceViewer/defaultSettingsView.7ch9cixO.css +0 -1
- package/lib/vite/traceViewer/uiMode.fyrXARf2.js +0 -5
- /package/lib/{server/utils → utils/isomorphic}/imageUtils.js +0 -0
- /package/lib/utils/isomorphic/{traceUtils.js → trace/traceUtils.js} +0 -0
package/lib/server/frames.js
CHANGED
|
@@ -33,8 +33,6 @@ __export(frames_exports, {
|
|
|
33
33
|
NavigationAbortedError: () => NavigationAbortedError
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(frames_exports);
|
|
36
|
-
var import_crExecutionContext = require("./chromium/crExecutionContext");
|
|
37
|
-
var import_dom = require("./dom");
|
|
38
36
|
var import_browserContext = require("./browserContext");
|
|
39
37
|
var dom = __toESM(require("./dom"));
|
|
40
38
|
var import_errors = require("./errors");
|
|
@@ -49,7 +47,6 @@ var import_progress = require("./progress");
|
|
|
49
47
|
var types = __toESM(require("./types"));
|
|
50
48
|
var import_utils = require("../utils");
|
|
51
49
|
var import_protocolError = require("./protocolError");
|
|
52
|
-
var import_debugLogger = require("./utils/debugLogger");
|
|
53
50
|
var import_eventsHelper = require("./utils/eventsHelper");
|
|
54
51
|
var import_selectorParser = require("../utils/isomorphic/selectorParser");
|
|
55
52
|
var import_manualPromise = require("../utils/isomorphic/manualPromise");
|
|
@@ -177,14 +174,11 @@ class FrameManager {
|
|
|
177
174
|
} else {
|
|
178
175
|
frame._currentDocument = { documentId, request: void 0 };
|
|
179
176
|
}
|
|
180
|
-
frame._iframeWorld = void 0;
|
|
181
|
-
frame._mainWorld = void 0;
|
|
182
|
-
frame._isolatedWorld = void 0;
|
|
183
177
|
frame._onClearLifecycle();
|
|
184
178
|
const navigationEvent = { url, name, newDocument: frame._currentDocument, isPublic: true };
|
|
185
179
|
this._fireInternalFrameNavigation(frame, navigationEvent);
|
|
186
180
|
if (!initial) {
|
|
187
|
-
|
|
181
|
+
frame.apiLog(` navigated to "${url}"`);
|
|
188
182
|
this._page.frameNavigatedToNewDocument(frame);
|
|
189
183
|
}
|
|
190
184
|
frame.setPendingDocument(keepPending);
|
|
@@ -200,7 +194,7 @@ class FrameManager {
|
|
|
200
194
|
frame._url = url;
|
|
201
195
|
const navigationEvent = { url, name: frame._name, isPublic: true };
|
|
202
196
|
this._fireInternalFrameNavigation(frame, navigationEvent);
|
|
203
|
-
|
|
197
|
+
frame.apiLog(` navigated to "${url}"`);
|
|
204
198
|
}
|
|
205
199
|
frameAbortedNavigation(frameId, errorText, documentId) {
|
|
206
200
|
const frame = this._frames.get(frameId);
|
|
@@ -403,7 +397,7 @@ class Frame extends import_instrumentation.SdkObject {
|
|
|
403
397
|
this._firedLifecycleEvents.add(event);
|
|
404
398
|
this.emit(Frame.Events.AddLifecycle, event);
|
|
405
399
|
if (this === this._page.mainFrame() && this._url !== "about:blank")
|
|
406
|
-
|
|
400
|
+
this.apiLog(` "${event}" event fired`);
|
|
407
401
|
this._page.mainFrame()._recalculateNetworkIdle();
|
|
408
402
|
}
|
|
409
403
|
_onClearLifecycle() {
|
|
@@ -457,11 +451,7 @@ class Frame extends import_instrumentation.SdkObject {
|
|
|
457
451
|
});
|
|
458
452
|
}
|
|
459
453
|
nonStallingEvaluateInExistingContext(expression, world) {
|
|
460
|
-
return this.raceAgainstEvaluationStallingEvents(
|
|
461
|
-
try {
|
|
462
|
-
await this._context(world);
|
|
463
|
-
} catch {
|
|
464
|
-
}
|
|
454
|
+
return this.raceAgainstEvaluationStallingEvents(() => {
|
|
465
455
|
const context = this._contextData.get(world)?.context;
|
|
466
456
|
if (!context)
|
|
467
457
|
throw new Error("Frame does not yet have the execution context");
|
|
@@ -479,7 +469,7 @@ class Frame extends import_instrumentation.SdkObject {
|
|
|
479
469
|
this._firedLifecycleEvents.add("networkidle");
|
|
480
470
|
this.emit(Frame.Events.AddLifecycle, "networkidle");
|
|
481
471
|
if (this === this._page.mainFrame() && this._url !== "about:blank")
|
|
482
|
-
|
|
472
|
+
this.apiLog(` "networkidle" event fired`);
|
|
483
473
|
}
|
|
484
474
|
if (frameThatAllowsRemovingNetworkIdle !== this && this._firedLifecycleEvents.has("networkidle") && !isNetworkIdle) {
|
|
485
475
|
this._firedLifecycleEvents.delete("networkidle");
|
|
@@ -587,74 +577,12 @@ class Frame extends import_instrumentation.SdkObject {
|
|
|
587
577
|
async frameElement() {
|
|
588
578
|
return this._page.delegate.getFrameElement(this);
|
|
589
579
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
}
|
|
597
|
-
var iframeExecutionContextId = await this._getFrameMainFrameContextId(client);
|
|
598
|
-
if (world == "main") {
|
|
599
|
-
if (this != this._page.mainFrame() && iframeExecutionContextId && this._iframeWorld == void 0) {
|
|
600
|
-
var executionContextId = iframeExecutionContextId;
|
|
601
|
-
var crContext = new import_crExecutionContext.CRExecutionContext(client, { id: executionContextId }, this._id);
|
|
602
|
-
this._iframeWorld = new import_dom.FrameExecutionContext(crContext, this, world);
|
|
603
|
-
this._page.delegate._sessionForFrame(this)._onExecutionContextCreated({
|
|
604
|
-
id: executionContextId,
|
|
605
|
-
origin: world,
|
|
606
|
-
name: world,
|
|
607
|
-
auxData: { isDefault: this === this._page.mainFrame(), type: "isolated", frameId: this._id }
|
|
608
|
-
});
|
|
609
|
-
} else if (this._mainWorld == void 0) {
|
|
610
|
-
var globalThis2 = await client._sendMayFail("Runtime.evaluate", {
|
|
611
|
-
expression: "globalThis",
|
|
612
|
-
serializationOptions: { serialization: "idOnly" }
|
|
613
|
-
});
|
|
614
|
-
if (!globalThis2) {
|
|
615
|
-
if (this.isDetached()) throw new Error("Frame was detached");
|
|
616
|
-
return;
|
|
617
|
-
}
|
|
618
|
-
var globalThisObjId = globalThis2["result"]["objectId"];
|
|
619
|
-
var executionContextId = parseInt(globalThisObjId.split(".")[1], 10);
|
|
620
|
-
var crContext = new import_crExecutionContext.CRExecutionContext(client, { id: executionContextId }, this._id);
|
|
621
|
-
this._mainWorld = new import_dom.FrameExecutionContext(crContext, this, world);
|
|
622
|
-
this._page.delegate._sessionForFrame(this)._onExecutionContextCreated({
|
|
623
|
-
id: executionContextId,
|
|
624
|
-
origin: world,
|
|
625
|
-
name: world,
|
|
626
|
-
auxData: { isDefault: this === this._page.mainFrame(), type: "isolated", frameId: this._id }
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
if (world != "main" && this._isolatedWorld == void 0) {
|
|
631
|
-
world = "utility";
|
|
632
|
-
var result = await client._sendMayFail("Page.createIsolatedWorld", {
|
|
633
|
-
frameId: this._id,
|
|
634
|
-
grantUniveralAccess: true,
|
|
635
|
-
worldName: world
|
|
636
|
-
});
|
|
637
|
-
if (!result) {
|
|
638
|
-
if (this.isDetached()) throw new Error("Frame was detached");
|
|
639
|
-
return;
|
|
640
|
-
}
|
|
641
|
-
var executionContextId = result.executionContextId;
|
|
642
|
-
var crContext = new import_crExecutionContext.CRExecutionContext(client, { id: executionContextId }, this._id);
|
|
643
|
-
this._isolatedWorld = new import_dom.FrameExecutionContext(crContext, this, world);
|
|
644
|
-
this._page.delegate._sessionForFrame(this)._onExecutionContextCreated({
|
|
645
|
-
id: executionContextId,
|
|
646
|
-
origin: world,
|
|
647
|
-
name: world,
|
|
648
|
-
auxData: { isDefault: this === this._page.mainFrame(), type: "isolated", frameId: this._id }
|
|
649
|
-
});
|
|
650
|
-
}
|
|
651
|
-
if (world != "main") {
|
|
652
|
-
return this._isolatedWorld;
|
|
653
|
-
} else if (this != this._page.mainFrame() && this._iframeWorld) {
|
|
654
|
-
return this._iframeWorld;
|
|
655
|
-
} else {
|
|
656
|
-
return this._mainWorld;
|
|
657
|
-
}
|
|
580
|
+
_context(world) {
|
|
581
|
+
return this._contextData.get(world).contextPromise.then((contextOrDestroyedReason) => {
|
|
582
|
+
if (contextOrDestroyedReason instanceof js.ExecutionContext)
|
|
583
|
+
return contextOrDestroyedReason;
|
|
584
|
+
throw new Error(contextOrDestroyedReason.destroyedReason);
|
|
585
|
+
});
|
|
658
586
|
}
|
|
659
587
|
_mainContext() {
|
|
660
588
|
return this._context("main");
|
|
@@ -666,23 +594,18 @@ class Frame extends import_instrumentation.SdkObject {
|
|
|
666
594
|
return this._context("utility");
|
|
667
595
|
}
|
|
668
596
|
async evaluateExpression(expression, options = {}, arg) {
|
|
669
|
-
const context = await this.
|
|
670
|
-
const value = await
|
|
597
|
+
const context = await this._context(options.world ?? "main");
|
|
598
|
+
const value = await context.evaluateExpression(expression, options, arg);
|
|
671
599
|
return value;
|
|
672
600
|
}
|
|
673
601
|
async evaluateExpressionHandle(expression, options = {}, arg) {
|
|
674
|
-
const context = await this.
|
|
675
|
-
const value = await
|
|
602
|
+
const context = await this._context(options.world ?? "main");
|
|
603
|
+
const value = await context.evaluateExpressionHandle(expression, options, arg);
|
|
676
604
|
return value;
|
|
677
605
|
}
|
|
678
606
|
async querySelector(selector, options) {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
return null;
|
|
682
|
-
if (handles.length > 1 && options?.strict)
|
|
683
|
-
throw new Error(`Strict mode: expected one element matching selector "${selector}", found ${handles.length}`);
|
|
684
|
-
return handles[0];
|
|
685
|
-
});
|
|
607
|
+
this.apiLog(` finding element using the selector "${selector}"`);
|
|
608
|
+
return this.selectors.query(selector, options);
|
|
686
609
|
}
|
|
687
610
|
async waitForSelector(progress, selector, performActionPreChecksAndLog, options, scope) {
|
|
688
611
|
if (options.visibility)
|
|
@@ -694,109 +617,77 @@ class Frame extends import_instrumentation.SdkObject {
|
|
|
694
617
|
throw new Error(`state: expected one of (attached|detached|visible|hidden)`);
|
|
695
618
|
if (performActionPreChecksAndLog)
|
|
696
619
|
progress.log(`waiting for ${this._asLocator(selector)}${state === "attached" ? "" : " to be " + state}`);
|
|
697
|
-
const promise = this.
|
|
698
|
-
if (
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
620
|
+
const promise = this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async (continuePolling) => {
|
|
621
|
+
if (performActionPreChecksAndLog)
|
|
622
|
+
await this._page.performActionPreChecks(progress);
|
|
623
|
+
const resolved = await progress.race(this.selectors.resolveInjectedForSelector(selector, options, scope));
|
|
624
|
+
if (!resolved) {
|
|
625
|
+
if (state === "hidden" || state === "detached")
|
|
626
|
+
return null;
|
|
627
|
+
return continuePolling;
|
|
705
628
|
}
|
|
706
|
-
const
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
629
|
+
const result = await progress.race(resolved.injected.evaluateHandle((injected, { info, root }) => {
|
|
630
|
+
if (root && !root.isConnected)
|
|
631
|
+
throw injected.createStacklessError("Element is not attached to the DOM");
|
|
632
|
+
const elements = injected.querySelectorAll(info.parsed, root || document);
|
|
633
|
+
const element2 = elements[0];
|
|
634
|
+
const visible2 = element2 ? injected.utils.isElementVisible(element2) : false;
|
|
635
|
+
let log2 = "";
|
|
636
|
+
if (elements.length > 1) {
|
|
637
|
+
if (info.strict)
|
|
638
|
+
throw injected.strictModeViolationError(info.parsed, elements);
|
|
639
|
+
log2 = ` locator resolved to ${elements.length} elements. Proceeding with the first one: ${injected.previewNode(elements[0])}`;
|
|
640
|
+
} else if (element2) {
|
|
641
|
+
log2 = ` locator resolved to ${visible2 ? "visible" : "hidden"} ${injected.previewNode(element2)}`;
|
|
717
642
|
}
|
|
643
|
+
injected.checkDeprecatedSelectorUsage(info.parsed, elements);
|
|
644
|
+
return { log: log2, element: element2, visible: visible2, attached: !!element2 };
|
|
645
|
+
}, { info: resolved.info, root: resolved.frame === this ? scope : void 0 }));
|
|
646
|
+
const { log, visible, attached } = await progress.race(result.evaluate((r) => ({ log: r.log, visible: r.visible, attached: r.attached })));
|
|
647
|
+
if (log)
|
|
648
|
+
progress.log(log);
|
|
649
|
+
const success = { attached, detached: !attached, visible, hidden: !visible }[state];
|
|
650
|
+
if (!success) {
|
|
651
|
+
result.dispose();
|
|
652
|
+
return continuePolling;
|
|
718
653
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
if (!
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
if (options.__testHookBeforeAdoptNode) await options.__testHookBeforeAdoptNode();
|
|
654
|
+
if (options.omitReturnValue) {
|
|
655
|
+
result.dispose();
|
|
656
|
+
return null;
|
|
657
|
+
}
|
|
658
|
+
const element = state === "attached" || state === "visible" ? await progress.race(result.evaluateHandle((r) => r.element)) : null;
|
|
659
|
+
result.dispose();
|
|
660
|
+
if (!element)
|
|
661
|
+
return null;
|
|
662
|
+
if (options.__testHookBeforeAdoptNode)
|
|
663
|
+
await progress.race(options.__testHookBeforeAdoptNode());
|
|
730
664
|
try {
|
|
731
|
-
|
|
665
|
+
const mainContext = await progress.race(resolved.frame._mainContext());
|
|
666
|
+
return await progress.race(element._adoptTo(mainContext));
|
|
732
667
|
} catch (e) {
|
|
733
|
-
return
|
|
668
|
+
return continuePolling;
|
|
734
669
|
}
|
|
735
|
-
}, "returnOnNotResolved");
|
|
736
|
-
const resultPromise = scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;
|
|
737
|
-
return resultPromise.catch((e) => {
|
|
738
|
-
if (this.isDetached() && e?.message?.includes("Execution context was destroyed"))
|
|
739
|
-
throw new Error("Frame was detached");
|
|
740
|
-
throw e;
|
|
741
670
|
});
|
|
671
|
+
return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;
|
|
742
672
|
}
|
|
743
673
|
async dispatchEvent(progress, selector, type, eventInit = {}, options, scope) {
|
|
744
|
-
|
|
745
|
-
const visited = /* @__PURE__ */ new WeakSet();
|
|
746
|
-
const collectHandles = (value) => {
|
|
747
|
-
if (!value || typeof value !== "object")
|
|
748
|
-
return;
|
|
749
|
-
if (value instanceof js.JSHandle) {
|
|
750
|
-
eventInitHandles.push(value);
|
|
751
|
-
return;
|
|
752
|
-
}
|
|
753
|
-
if (visited.has(value))
|
|
754
|
-
return;
|
|
755
|
-
visited.add(value);
|
|
756
|
-
if (Array.isArray(value)) {
|
|
757
|
-
for (const item of value)
|
|
758
|
-
collectHandles(item);
|
|
759
|
-
return;
|
|
760
|
-
}
|
|
761
|
-
for (const propertyValue of Object.values(value))
|
|
762
|
-
collectHandles(propertyValue);
|
|
763
|
-
};
|
|
764
|
-
collectHandles(eventInit);
|
|
765
|
-
const allHandlesFromSameFrame = eventInitHandles.length > 0 && eventInitHandles.every((handle) => handle._context?.frame === eventInitHandles[0]?._context?.frame);
|
|
766
|
-
const handlesFrame = eventInitHandles[0]?._context?.frame;
|
|
767
|
-
const canRetryInSecondaryContext = allHandlesFromSameFrame && (handlesFrame !== this || !selector.includes("internal:control=enter-frame"));
|
|
768
|
-
const callback = (injectedScript, element, data) => {
|
|
674
|
+
await this._callOnElementOnceMatches(progress, selector, (injectedScript, element, data) => {
|
|
769
675
|
injectedScript.dispatchEvent(element, data.type, data.eventInit);
|
|
770
|
-
};
|
|
771
|
-
try {
|
|
772
|
-
await this._callOnElementOnceMatches(progress, selector, callback, { type, eventInit }, { mainWorld: true, ...options }, scope);
|
|
773
|
-
} catch (e) {
|
|
774
|
-
if ("JSHandles can be evaluated only in the context they were created!" === e.message && canRetryInSecondaryContext) {
|
|
775
|
-
await this._callOnElementOnceMatches(progress, selector, callback, { type, eventInit }, { ...options }, scope);
|
|
776
|
-
return;
|
|
777
|
-
}
|
|
778
|
-
throw e;
|
|
779
|
-
}
|
|
676
|
+
}, { type, eventInit }, { mainWorld: true, ...options }, scope);
|
|
780
677
|
}
|
|
781
678
|
async evalOnSelector(selector, strict, expression, isFunction, arg, scope) {
|
|
782
679
|
const handle = await this.selectors.query(selector, { strict }, scope);
|
|
783
680
|
if (!handle)
|
|
784
|
-
throw new Error(
|
|
785
|
-
const result = await handle.evaluateExpression(expression, { isFunction }, arg
|
|
681
|
+
throw new Error(`Failed to find element matching selector "${selector}"`);
|
|
682
|
+
const result = await handle.evaluateExpression(expression, { isFunction }, arg);
|
|
786
683
|
handle.dispose();
|
|
787
684
|
return result;
|
|
788
685
|
}
|
|
789
|
-
async evalOnSelectorAll(selector, expression, isFunction, arg, scope
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
arrayHandle.dispose();
|
|
795
|
-
return result;
|
|
796
|
-
} catch (e) {
|
|
797
|
-
if ("JSHandles can be evaluated only in the context they were created!" === e.message) return await this.evalOnSelectorAll(selector, expression, isFunction, arg, scope, isolatedContext);
|
|
798
|
-
throw e;
|
|
799
|
-
}
|
|
686
|
+
async evalOnSelectorAll(selector, expression, isFunction, arg, scope) {
|
|
687
|
+
const arrayHandle = await this.selectors.queryArrayInMainWorld(selector, scope);
|
|
688
|
+
const result = await arrayHandle.evaluateExpression(expression, { isFunction }, arg);
|
|
689
|
+
arrayHandle.dispose();
|
|
690
|
+
return result;
|
|
800
691
|
}
|
|
801
692
|
async maskSelectors(selectors, color) {
|
|
802
693
|
const context = await this._utilityContext();
|
|
@@ -806,30 +697,16 @@ class Frame extends import_instrumentation.SdkObject {
|
|
|
806
697
|
}, { parsed: selectors, color });
|
|
807
698
|
}
|
|
808
699
|
async querySelectorAll(selector) {
|
|
809
|
-
|
|
810
|
-
const progress = {
|
|
811
|
-
log: (message) => metadata.log.push(message),
|
|
812
|
-
metadata,
|
|
813
|
-
race: (promise) => Promise.race(Array.isArray(promise) ? promise : [promise])
|
|
814
|
-
};
|
|
815
|
-
return await this._retryWithoutProgress(progress, selector, { strict: null, performActionPreChecks: false }, async (result) => {
|
|
816
|
-
if (!result || !result[0]) return [];
|
|
817
|
-
return result[1];
|
|
818
|
-
}, "returnAll", null);
|
|
700
|
+
return this.selectors.queryAll(selector);
|
|
819
701
|
}
|
|
820
702
|
async queryCount(selector, options) {
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
if (!result) return 0;
|
|
829
|
-
const handle = result[0];
|
|
830
|
-
const handles = result[1];
|
|
831
|
-
return handle ? handles.length : 0;
|
|
832
|
-
}, "returnAll", null);
|
|
703
|
+
try {
|
|
704
|
+
return await this.selectors.queryCount(selector, options);
|
|
705
|
+
} catch (e) {
|
|
706
|
+
if (this.isNonRetriableError(e))
|
|
707
|
+
throw e;
|
|
708
|
+
return 0;
|
|
709
|
+
}
|
|
833
710
|
}
|
|
834
711
|
async content() {
|
|
835
712
|
try {
|
|
@@ -849,19 +726,27 @@ class Frame extends import_instrumentation.SdkObject {
|
|
|
849
726
|
}
|
|
850
727
|
}
|
|
851
728
|
async setContent(progress, html, options) {
|
|
729
|
+
const tag = `--playwright--set--content--${this._id}--${++this._setContentCounter}--`;
|
|
852
730
|
await this.raceNavigationAction(progress, async () => {
|
|
853
731
|
const waitUntil = options.waitUntil === void 0 ? "load" : options.waitUntil;
|
|
854
732
|
progress.log(`setting frame content, waiting until "${waitUntil}"`);
|
|
855
|
-
const
|
|
733
|
+
const context = await progress.race(this._utilityContext());
|
|
734
|
+
const tagPromise = new import_manualPromise.ManualPromise();
|
|
735
|
+
this._page.frameManager._consoleMessageTags.set(tag, () => {
|
|
856
736
|
this._onClearLifecycle();
|
|
857
|
-
|
|
858
|
-
});
|
|
859
|
-
const setContentPromise = this._page.delegate._sessionForFrame(this)._client.send("Page.setDocumentContent", {
|
|
860
|
-
frameId: this._id,
|
|
861
|
-
html
|
|
737
|
+
tagPromise.resolve();
|
|
862
738
|
});
|
|
863
|
-
|
|
739
|
+
const lifecyclePromise = progress.race(tagPromise).then(() => this.waitForLoadState(progress, waitUntil));
|
|
740
|
+
const contentPromise = progress.race(context.evaluate(({ html: html2, tag: tag2 }) => {
|
|
741
|
+
document.open();
|
|
742
|
+
console.debug(tag2);
|
|
743
|
+
document.write(html2);
|
|
744
|
+
document.close();
|
|
745
|
+
}, { html, tag }));
|
|
746
|
+
await Promise.all([contentPromise, lifecyclePromise]);
|
|
864
747
|
return null;
|
|
748
|
+
}).finally(() => {
|
|
749
|
+
this._page.frameManager._consoleMessageTags.delete(tag);
|
|
865
750
|
});
|
|
866
751
|
}
|
|
867
752
|
name() {
|
|
@@ -1021,11 +906,58 @@ class Frame extends import_instrumentation.SdkObject {
|
|
|
1021
906
|
return true;
|
|
1022
907
|
return false;
|
|
1023
908
|
}
|
|
1024
|
-
async _retryWithProgressIfNotConnected(progress, selector, options, action
|
|
1025
|
-
|
|
1026
|
-
|
|
909
|
+
async _retryWithProgressIfNotConnected(progress, selector, options, action) {
|
|
910
|
+
progress.log(`waiting for ${this._asLocator(selector)}`);
|
|
911
|
+
const noAutoWaiting = options.__testHookNoAutoWaiting ?? options.noAutoWaiting;
|
|
912
|
+
const performActionPreChecks = (options.performActionPreChecks ?? !options.force) && !noAutoWaiting;
|
|
1027
913
|
return this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async (continuePolling) => {
|
|
1028
|
-
|
|
914
|
+
if (performActionPreChecks)
|
|
915
|
+
await this._page.performActionPreChecks(progress);
|
|
916
|
+
const resolved = await progress.race(this.selectors.resolveInjectedForSelector(selector, { strict: options.strict }));
|
|
917
|
+
if (!resolved) {
|
|
918
|
+
if (noAutoWaiting)
|
|
919
|
+
throw new dom.NonRecoverableDOMError("Element(s) not found");
|
|
920
|
+
return continuePolling;
|
|
921
|
+
}
|
|
922
|
+
const result = await progress.race(resolved.injected.evaluateHandle((injected, { info, callId }) => {
|
|
923
|
+
const elements = injected.querySelectorAll(info.parsed, document);
|
|
924
|
+
if (callId)
|
|
925
|
+
injected.markTargetElements(new Set(elements), callId);
|
|
926
|
+
const element2 = elements[0];
|
|
927
|
+
let log2 = "";
|
|
928
|
+
if (elements.length > 1) {
|
|
929
|
+
if (info.strict)
|
|
930
|
+
throw injected.strictModeViolationError(info.parsed, elements);
|
|
931
|
+
log2 = ` locator resolved to ${elements.length} elements. Proceeding with the first one: ${injected.previewNode(elements[0])}`;
|
|
932
|
+
} else if (element2) {
|
|
933
|
+
log2 = ` locator resolved to ${injected.previewNode(element2)}`;
|
|
934
|
+
}
|
|
935
|
+
injected.checkDeprecatedSelectorUsage(info.parsed, elements);
|
|
936
|
+
return { log: log2, success: !!element2, element: element2 };
|
|
937
|
+
}, { info: resolved.info, callId: progress.metadata.id }));
|
|
938
|
+
const { log, success } = await progress.race(result.evaluate((r) => ({ log: r.log, success: r.success })));
|
|
939
|
+
if (log)
|
|
940
|
+
progress.log(log);
|
|
941
|
+
if (!success) {
|
|
942
|
+
if (noAutoWaiting)
|
|
943
|
+
throw new dom.NonRecoverableDOMError("Element(s) not found");
|
|
944
|
+
result.dispose();
|
|
945
|
+
return continuePolling;
|
|
946
|
+
}
|
|
947
|
+
const element = await progress.race(result.evaluateHandle((r) => r.element));
|
|
948
|
+
result.dispose();
|
|
949
|
+
try {
|
|
950
|
+
const result2 = await action(element);
|
|
951
|
+
if (result2 === "error:notconnected") {
|
|
952
|
+
if (noAutoWaiting)
|
|
953
|
+
throw new dom.NonRecoverableDOMError("Element is not attached to the DOM");
|
|
954
|
+
progress.log("element was detached from the DOM, retrying");
|
|
955
|
+
return continuePolling;
|
|
956
|
+
}
|
|
957
|
+
return result2;
|
|
958
|
+
} finally {
|
|
959
|
+
element?.dispose();
|
|
960
|
+
}
|
|
1029
961
|
});
|
|
1030
962
|
}
|
|
1031
963
|
async rafrafTimeoutScreenshotElementWithProgress(progress, selector, timeout, options) {
|
|
@@ -1158,56 +1090,17 @@ class Frame extends import_instrumentation.SdkObject {
|
|
|
1158
1090
|
}
|
|
1159
1091
|
async isVisibleInternal(progress, selector, options = {}, scope) {
|
|
1160
1092
|
try {
|
|
1161
|
-
const
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
const scopeParentNode = scope.parentNode || scope;
|
|
1170
|
-
if (scopeParentNode.constructor.name == "ElementHandle") {
|
|
1171
|
-
return await scopeParentNode.evaluateInUtility(([injected, node, { scope: handle2 }]) => {
|
|
1172
|
-
const state = handle2 ? injected.elementState(handle2, "visible") : {
|
|
1173
|
-
matches: false,
|
|
1174
|
-
received: "error:notconnected"
|
|
1175
|
-
};
|
|
1176
|
-
return state.matches;
|
|
1177
|
-
}, { scope });
|
|
1178
|
-
} else {
|
|
1179
|
-
return await scopeParentNode.evaluate((injected, node, { scope: handle2 }) => {
|
|
1180
|
-
const state = handle2 ? injected.elementState(handle2, "visible") : {
|
|
1181
|
-
matches: false,
|
|
1182
|
-
received: "error:notconnected"
|
|
1183
|
-
};
|
|
1184
|
-
return state.matches;
|
|
1185
|
-
}, { scope });
|
|
1186
|
-
}
|
|
1187
|
-
} else {
|
|
1188
|
-
return await this._retryWithoutProgress(progress2, selector, { ...options, performActionPreChecks: false }, async (handle) => {
|
|
1189
|
-
if (!handle) return false;
|
|
1190
|
-
if (handle.parentNode.constructor.name == "ElementHandle") {
|
|
1191
|
-
return await handle.parentNode.evaluateInUtility(([injected, node, { handle: handle2 }]) => {
|
|
1192
|
-
const state = handle2 ? injected.elementState(handle2, "visible") : {
|
|
1193
|
-
matches: false,
|
|
1194
|
-
received: "error:notconnected"
|
|
1195
|
-
};
|
|
1196
|
-
return state.matches;
|
|
1197
|
-
}, { handle });
|
|
1198
|
-
} else {
|
|
1199
|
-
return await handle.parentNode.evaluate((injected, { handle: handle2 }) => {
|
|
1200
|
-
const state = handle2 ? injected.elementState(handle2, "visible") : {
|
|
1201
|
-
matches: false,
|
|
1202
|
-
received: "error:notconnected"
|
|
1203
|
-
};
|
|
1204
|
-
return state.matches;
|
|
1205
|
-
}, { handle });
|
|
1206
|
-
}
|
|
1207
|
-
}, "returnOnNotResolved", null);
|
|
1208
|
-
}
|
|
1093
|
+
const resolved = await progress.race(this.selectors.resolveInjectedForSelector(selector, options, scope));
|
|
1094
|
+
if (!resolved)
|
|
1095
|
+
return false;
|
|
1096
|
+
return await progress.race(resolved.injected.evaluate((injected, { info, root }) => {
|
|
1097
|
+
const element = injected.querySelector(info.parsed, root || document, info.strict);
|
|
1098
|
+
const state = element ? injected.elementState(element, "visible") : { matches: false, received: "error:notconnected" };
|
|
1099
|
+
return state.matches;
|
|
1100
|
+
}, { info: resolved.info, root: resolved.frame === this ? scope : void 0 }));
|
|
1209
1101
|
} catch (e) {
|
|
1210
|
-
if (this.isNonRetriableError(e))
|
|
1102
|
+
if (this.isNonRetriableError(e))
|
|
1103
|
+
throw e;
|
|
1211
1104
|
return false;
|
|
1212
1105
|
}
|
|
1213
1106
|
}
|
|
@@ -1251,9 +1144,6 @@ class Frame extends import_instrumentation.SdkObject {
|
|
|
1251
1144
|
async waitForTimeout(progress, timeout) {
|
|
1252
1145
|
return progress.wait(timeout);
|
|
1253
1146
|
}
|
|
1254
|
-
async ariaSnapshot(progress, selector) {
|
|
1255
|
-
return await this._retryWithProgressIfNotConnected(progress, selector, { strict: true, performActionPreChecks: true }, (handle) => progress.race(handle.ariaSnapshot()));
|
|
1256
|
-
}
|
|
1257
1147
|
async expect(progress, selector, options) {
|
|
1258
1148
|
progress.log(`${(0, import_utils.renderTitleForCall)(progress.metadata)}${options.timeoutForLogs ? ` with timeout ${options.timeoutForLogs}ms` : ""}`);
|
|
1259
1149
|
const lastIntermediateResult = { isSet: false };
|
|
@@ -1303,63 +1193,27 @@ class Frame extends import_instrumentation.SdkObject {
|
|
|
1303
1193
|
}
|
|
1304
1194
|
async _expectInternal(progress, selector, options, lastIntermediateResult, noAbort) {
|
|
1305
1195
|
const race = (p) => noAbort ? p : progress.race(p);
|
|
1306
|
-
const
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
return { matches: false };
|
|
1328
|
-
if (options.isNot && options.expression === "to.be.in.viewport")
|
|
1329
|
-
return { matches: false };
|
|
1330
|
-
if (options.expression === "to.have.text.array") {
|
|
1331
|
-
if (options.expectedText.length === 0)
|
|
1332
|
-
return { matches: true, received: [] };
|
|
1333
|
-
if (options.isNot && options.expectedText.length !== 0)
|
|
1334
|
-
return { matches: false, received: [] };
|
|
1335
|
-
}
|
|
1336
|
-
return { matches: options.isNot, missingReceived: true };
|
|
1337
|
-
}
|
|
1338
|
-
const handle = result[0];
|
|
1339
|
-
const handles = result[1];
|
|
1340
|
-
if (handle.parentNode.constructor.name == "ElementHandle") {
|
|
1341
|
-
return await handle.parentNode.evaluateInUtility(async ([injected, node, { handle: handle2, options: options2, handles: handles2 }]) => {
|
|
1342
|
-
return await injected.expect(handle2, options2, handles2);
|
|
1343
|
-
}, { handle, options, handles });
|
|
1344
|
-
} else {
|
|
1345
|
-
return await handle.parentNode.evaluate(async (injected, { handle: handle2, options: options2, handles: handles2 }) => {
|
|
1346
|
-
return await injected.expect(handle2, options2, handles2);
|
|
1347
|
-
}, { handle, options, handles });
|
|
1348
|
-
}
|
|
1349
|
-
};
|
|
1350
|
-
if (noAbort) {
|
|
1351
|
-
var { log, matches, received, missingReceived } = await this._retryWithoutProgress(progress, selector, { strict: !isArray, performActionPreChecks: false }, action, "returnAll", null);
|
|
1352
|
-
} else {
|
|
1353
|
-
var { log, matches, received, missingReceived } = await race(this._retryWithProgressIfNotConnected(progress, selector, { strict: !isArray, performActionPreChecks: false, __patchrightSkipRetryLogWaiting: true }, action, "returnAll"));
|
|
1354
|
-
}
|
|
1355
|
-
} else {
|
|
1356
|
-
const world = options.expression === "to.have.property" ? "main" : "utility";
|
|
1357
|
-
const context = await race(this._context(world));
|
|
1358
|
-
const injected = await race(context.injectedScript());
|
|
1359
|
-
var { matches, received, missingReceived } = await race(injected.evaluate(async (injected2, { options: options2, callId }) => {
|
|
1360
|
-
return { ...await injected2.expect(void 0, options2, []) };
|
|
1361
|
-
}, { options, callId: progress.metadata.id }));
|
|
1362
|
-
}
|
|
1196
|
+
const selectorInFrame = selector ? await race(this.selectors.resolveFrameForSelector(selector, { strict: true })) : void 0;
|
|
1197
|
+
const { frame, info } = selectorInFrame || { frame: this, info: void 0 };
|
|
1198
|
+
const world = options.expression === "to.have.property" ? "main" : info?.world ?? "utility";
|
|
1199
|
+
const context = await race(frame._context(world));
|
|
1200
|
+
const injected = await race(context.injectedScript());
|
|
1201
|
+
const { log, matches, received, missingReceived } = await race(injected.evaluate(async (injected2, { info: info2, options: options2, callId }) => {
|
|
1202
|
+
const elements = info2 ? injected2.querySelectorAll(info2.parsed, document) : [];
|
|
1203
|
+
if (callId)
|
|
1204
|
+
injected2.markTargetElements(new Set(elements), callId);
|
|
1205
|
+
const isArray = options2.expression === "to.have.count" || options2.expression.endsWith(".array");
|
|
1206
|
+
let log2 = "";
|
|
1207
|
+
if (isArray)
|
|
1208
|
+
log2 = ` locator resolved to ${elements.length} element${elements.length === 1 ? "" : "s"}`;
|
|
1209
|
+
else if (elements.length > 1)
|
|
1210
|
+
throw injected2.strictModeViolationError(info2.parsed, elements);
|
|
1211
|
+
else if (elements.length)
|
|
1212
|
+
log2 = ` locator resolved to ${injected2.previewNode(elements[0])}`;
|
|
1213
|
+
if (info2)
|
|
1214
|
+
injected2.checkDeprecatedSelectorUsage(info2.parsed, elements);
|
|
1215
|
+
return { log: log2, ...await injected2.expect(elements[0], options2, elements) };
|
|
1216
|
+
}, { info, options, callId: progress.metadata.id }));
|
|
1363
1217
|
if (log)
|
|
1364
1218
|
progress.log(log);
|
|
1365
1219
|
if (matches === options.isNot) {
|
|
@@ -1370,11 +1224,8 @@ class Frame extends import_instrumentation.SdkObject {
|
|
|
1370
1224
|
lastIntermediateResult.received = received;
|
|
1371
1225
|
}
|
|
1372
1226
|
lastIntermediateResult.isSet = true;
|
|
1373
|
-
if (!missingReceived)
|
|
1374
|
-
|
|
1375
|
-
if (rendered !== void 0)
|
|
1376
|
-
progress.log(' unexpected value "' + rendered + '"');
|
|
1377
|
-
}
|
|
1227
|
+
if (!missingReceived && !Array.isArray(received))
|
|
1228
|
+
progress.log(` unexpected value "${renderUnexpectedValue(options.expression, received)}"`);
|
|
1378
1229
|
}
|
|
1379
1230
|
return { matches, received };
|
|
1380
1231
|
}
|
|
@@ -1430,7 +1281,7 @@ class Frame extends import_instrumentation.SdkObject {
|
|
|
1430
1281
|
return { result, abort: () => aborted = true };
|
|
1431
1282
|
}, { expression, isFunction, polling: options.pollingInterval, arg }));
|
|
1432
1283
|
try {
|
|
1433
|
-
return await progress.race(
|
|
1284
|
+
return await progress.race(handle.evaluateHandle((h) => h.result));
|
|
1434
1285
|
} catch (error) {
|
|
1435
1286
|
await handle.evaluate((h) => h.abort()).catch(() => {
|
|
1436
1287
|
});
|
|
@@ -1451,8 +1302,17 @@ class Frame extends import_instrumentation.SdkObject {
|
|
|
1451
1302
|
return JSON.parse(handle.rawValue());
|
|
1452
1303
|
}
|
|
1453
1304
|
async title() {
|
|
1454
|
-
|
|
1455
|
-
|
|
1305
|
+
try {
|
|
1306
|
+
return await this.raceAgainstEvaluationStallingEvents(async () => {
|
|
1307
|
+
const context = await this._utilityContext();
|
|
1308
|
+
return await context.evaluate(() => document.title);
|
|
1309
|
+
});
|
|
1310
|
+
} catch {
|
|
1311
|
+
const url = this.pendingDocument()?.request?.url();
|
|
1312
|
+
if (url)
|
|
1313
|
+
return `Loading ${url}`;
|
|
1314
|
+
return "";
|
|
1315
|
+
}
|
|
1456
1316
|
}
|
|
1457
1317
|
async rafrafTimeout(progress, timeout) {
|
|
1458
1318
|
if (timeout === 0)
|
|
@@ -1476,112 +1336,33 @@ class Frame extends import_instrumentation.SdkObject {
|
|
|
1476
1336
|
data.context.contextDestroyed("Frame was detached");
|
|
1477
1337
|
data.contextPromise.resolve({ destroyedReason: "Frame was detached" });
|
|
1478
1338
|
}
|
|
1479
|
-
if (this._mainWorld)
|
|
1480
|
-
this._mainWorld.contextDestroyed("Frame was detached");
|
|
1481
|
-
if (this._iframeWorld)
|
|
1482
|
-
this._iframeWorld.contextDestroyed("Frame was detached");
|
|
1483
|
-
if (this._isolatedWorld)
|
|
1484
|
-
this._isolatedWorld.contextDestroyed("Frame was detached");
|
|
1485
1339
|
if (this._parentFrame)
|
|
1486
1340
|
this._parentFrame._childFrames.delete(this);
|
|
1487
1341
|
this._parentFrame = null;
|
|
1488
1342
|
}
|
|
1489
1343
|
async _callOnElementOnceMatches(progress, selector, body, taskData, options, scope) {
|
|
1490
1344
|
const callbackText = body.toString();
|
|
1491
|
-
progress.log(
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
})();
|
|
1513
|
-
} else {
|
|
1514
|
-
promise = scopeParentNode.evaluateInUtility(([injected, node, { callbackText: callbackText2, scope: handle2, taskData: taskData2 }]) => {
|
|
1515
|
-
const callback = injected.eval(callbackText2);
|
|
1516
|
-
return callback(injected, handle2, taskData2);
|
|
1517
|
-
}, {
|
|
1518
|
-
callbackText,
|
|
1519
|
-
scope,
|
|
1520
|
-
taskData
|
|
1521
|
-
});
|
|
1522
|
-
}
|
|
1523
|
-
} else {
|
|
1524
|
-
promise = scopeParentNode.evaluate((injected, { callbackText: callbackText2, scope: handle2, taskData: taskData2 }) => {
|
|
1525
|
-
const callback = injected.eval(callbackText2);
|
|
1526
|
-
return callback(injected, handle2, taskData2);
|
|
1527
|
-
}, {
|
|
1528
|
-
callbackText,
|
|
1529
|
-
scope,
|
|
1530
|
-
taskData
|
|
1531
|
-
});
|
|
1532
|
-
}
|
|
1533
|
-
} else {
|
|
1534
|
-
promise = this._retryWithProgressIfNotConnected(progress, selector, { ...options, performActionPreChecks: false }, async (handle) => {
|
|
1535
|
-
if (handle.parentNode.constructor.name == "ElementHandle") {
|
|
1536
|
-
if (options?.mainWorld) {
|
|
1537
|
-
const mainContext = await handle._frame._mainContext();
|
|
1538
|
-
const adoptedHandle = await this._page.delegate.adoptElementHandle(handle, mainContext);
|
|
1539
|
-
try {
|
|
1540
|
-
return await mainContext.evaluate(([injected, node, { callbackText: callbackText2, handle: handle2, taskData: taskData2 }]) => {
|
|
1541
|
-
const callback = injected.eval(callbackText2);
|
|
1542
|
-
return callback(injected, handle2, taskData2);
|
|
1543
|
-
}, [
|
|
1544
|
-
await mainContext.injectedScript(),
|
|
1545
|
-
adoptedHandle,
|
|
1546
|
-
{ callbackText, handle: adoptedHandle, taskData }
|
|
1547
|
-
]);
|
|
1548
|
-
} finally {
|
|
1549
|
-
adoptedHandle.dispose();
|
|
1550
|
-
}
|
|
1551
|
-
}
|
|
1552
|
-
const [taskScope] = Object.values(taskData?.eventInit ?? {});
|
|
1553
|
-
if (taskScope) {
|
|
1554
|
-
const taskScopeContext = taskScope._context;
|
|
1555
|
-
const adoptedHandle = await handle._adoptTo(taskScopeContext);
|
|
1556
|
-
return await taskScopeContext.evaluate(([injected, node, { callbackText: callbackText2, adoptedHandle: handle2, taskData: taskData2 }]) => {
|
|
1557
|
-
const callback = injected.eval(callbackText2);
|
|
1558
|
-
return callback(injected, handle2, taskData2);
|
|
1559
|
-
}, [
|
|
1560
|
-
await taskScopeContext.injectedScript(),
|
|
1561
|
-
adoptedHandle,
|
|
1562
|
-
{ callbackText, adoptedHandle, taskData }
|
|
1563
|
-
]);
|
|
1564
|
-
}
|
|
1565
|
-
return await handle.parentNode.evaluateInUtility(([injected, node, { callbackText: callbackText2, handle: handle2, taskData: taskData2 }]) => {
|
|
1566
|
-
const callback = injected.eval(callbackText2);
|
|
1567
|
-
return callback(injected, handle2, taskData2);
|
|
1568
|
-
}, {
|
|
1569
|
-
callbackText,
|
|
1570
|
-
handle,
|
|
1571
|
-
taskData
|
|
1572
|
-
});
|
|
1573
|
-
} else {
|
|
1574
|
-
return await handle.parentNode.evaluate((injected, { callbackText: callbackText2, handle: handle2, taskData: taskData2 }) => {
|
|
1575
|
-
const callback = injected.eval(callbackText2);
|
|
1576
|
-
return callback(injected, handle2, taskData2);
|
|
1577
|
-
}, {
|
|
1578
|
-
callbackText,
|
|
1579
|
-
handle,
|
|
1580
|
-
taskData
|
|
1581
|
-
});
|
|
1582
|
-
}
|
|
1583
|
-
});
|
|
1584
|
-
}
|
|
1345
|
+
progress.log(`waiting for ${this._asLocator(selector)}`);
|
|
1346
|
+
const promise = this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async (continuePolling) => {
|
|
1347
|
+
const resolved = await progress.race(this.selectors.resolveInjectedForSelector(selector, options, scope));
|
|
1348
|
+
if (!resolved)
|
|
1349
|
+
return continuePolling;
|
|
1350
|
+
const { log, success, value } = await progress.race(resolved.injected.evaluate((injected, { info, callbackText: callbackText2, taskData: taskData2, callId, root }) => {
|
|
1351
|
+
const callback = injected.eval(callbackText2);
|
|
1352
|
+
const element = injected.querySelector(info.parsed, root || document, info.strict);
|
|
1353
|
+
if (!element)
|
|
1354
|
+
return { success: false };
|
|
1355
|
+
const log2 = ` locator resolved to ${injected.previewNode(element)}`;
|
|
1356
|
+
if (callId)
|
|
1357
|
+
injected.markTargetElements(/* @__PURE__ */ new Set([element]), callId);
|
|
1358
|
+
return { log: log2, success: true, value: callback(injected, element, taskData2) };
|
|
1359
|
+
}, { info: resolved.info, callbackText, taskData, callId: progress.metadata.id, root: resolved.frame === this ? scope : void 0 }));
|
|
1360
|
+
if (log)
|
|
1361
|
+
progress.log(log);
|
|
1362
|
+
if (!success)
|
|
1363
|
+
return continuePolling;
|
|
1364
|
+
return value;
|
|
1365
|
+
});
|
|
1585
1366
|
return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;
|
|
1586
1367
|
}
|
|
1587
1368
|
_setContext(world, context) {
|
|
@@ -1631,266 +1412,32 @@ class Frame extends import_instrumentation.SdkObject {
|
|
|
1631
1412
|
injectedScript.extend(source2, arg2);
|
|
1632
1413
|
}, { source, arg });
|
|
1633
1414
|
}
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
backendNodeId: globalDocument.backendNodeId
|
|
1643
|
-
});
|
|
1644
|
-
if (describedNode && describedNode.node.contentDocument) {
|
|
1645
|
-
var resolvedNode = await client._sendMayFail("DOM.resolveNode", {
|
|
1646
|
-
backendNodeId: describedNode.node.contentDocument.backendNodeId
|
|
1647
|
-
});
|
|
1648
|
-
if (resolvedNode && resolvedNode.object && resolvedNode.object.objectId) {
|
|
1649
|
-
var _executionContextId = parseInt(resolvedNode.object.objectId.split(".")[1], 10);
|
|
1650
|
-
return _executionContextId;
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
} catch (e) {
|
|
1655
|
-
}
|
|
1656
|
-
return 0;
|
|
1657
|
-
}
|
|
1658
|
-
async _retryWithoutProgress(progress, selector, options, action, returnAction, continuePolling) {
|
|
1659
|
-
if (options.performActionPreChecks) await this._page.performActionPreChecks(progress);
|
|
1660
|
-
const resolved = await this.selectors.resolveInjectedForSelector(selector, { strict: options.strict }, options.__patchrightInitialScope);
|
|
1661
|
-
if (!resolved) {
|
|
1662
|
-
if (returnAction === "returnOnNotResolved" || returnAction === "returnAll") {
|
|
1663
|
-
const result2 = await action(null);
|
|
1664
|
-
return result2 === "internal:continuepolling" ? continuePolling : result2;
|
|
1665
|
-
}
|
|
1666
|
-
return continuePolling;
|
|
1667
|
-
}
|
|
1668
|
-
try {
|
|
1669
|
-
var client = this._page.delegate._sessionForFrame(resolved.frame)._client;
|
|
1670
|
-
} catch (e) {
|
|
1671
|
-
var client = this._page.delegate._mainFrameSession._client;
|
|
1672
|
-
}
|
|
1673
|
-
var utilityContext = await resolved.frame._utilityContext();
|
|
1674
|
-
var mainContext = await resolved.frame._mainContext();
|
|
1675
|
-
const documentNode = await client._sendMayFail("Runtime.evaluate", {
|
|
1676
|
-
expression: "document",
|
|
1677
|
-
serializationOptions: {
|
|
1678
|
-
serialization: "idOnly"
|
|
1679
|
-
},
|
|
1680
|
-
contextId: utilityContext.delegate._contextId
|
|
1681
|
-
});
|
|
1682
|
-
if (!documentNode) return continuePolling;
|
|
1683
|
-
let documentScope = new dom.ElementHandle(utilityContext, documentNode.result.objectId);
|
|
1684
|
-
let initialScope = documentScope;
|
|
1685
|
-
if (resolved.scope) {
|
|
1686
|
-
const scopeBackendNodeId = resolved.scope._objectId ? (await client._sendMayFail("DOM.describeNode", { objectId: resolved.scope._objectId }))?.node?.backendNodeId : null;
|
|
1687
|
-
if (scopeBackendNodeId) {
|
|
1688
|
-
const scopeInUtility = await client._sendMayFail("DOM.resolveNode", { backendNodeId: scopeBackendNodeId, executionContextId: utilityContext.delegate._contextId });
|
|
1689
|
-
if (scopeInUtility?.object?.objectId)
|
|
1690
|
-
initialScope = new dom.ElementHandle(utilityContext, scopeInUtility.object.objectId);
|
|
1691
|
-
}
|
|
1692
|
-
}
|
|
1693
|
-
progress.__patchrightInitialScope = resolved.scope;
|
|
1694
|
-
const parsedSnapshot = options.__patchrightWaitForSelector ? JSON.parse(JSON.stringify(resolved.info.parsed)) : null;
|
|
1695
|
-
let currentScopingElements;
|
|
1696
|
-
try {
|
|
1697
|
-
currentScopingElements = await this._customFindElementsByParsed(resolved, client, mainContext, initialScope, progress, resolved.info.parsed);
|
|
1698
|
-
} catch (e) {
|
|
1699
|
-
if ("JSHandles can be evaluated only in the context they were created!" === e.message) return continuePolling;
|
|
1700
|
-
if (e instanceof TypeError && e.message.includes("is not a function")) return continuePolling;
|
|
1701
|
-
await progress.race(resolved.injected.evaluateHandle((injected, { error }) => {
|
|
1702
|
-
throw error;
|
|
1703
|
-
}, { error: e }));
|
|
1704
|
-
}
|
|
1705
|
-
if (currentScopingElements.length == 0) {
|
|
1706
|
-
if (options.__testHookNoAutoWaiting || options.noAutoWaiting)
|
|
1707
|
-
throw new dom.NonRecoverableDOMError("Element(s) not found");
|
|
1708
|
-
if (parsedSnapshot && (returnAction === "returnOnNotResolved" || returnAction === "returnAll")) {
|
|
1709
|
-
const elementCount = await resolved.injected.evaluate((injected, { parsed }) => {
|
|
1710
|
-
return injected.querySelectorAll(parsed, document).length;
|
|
1711
|
-
}, { parsed: parsedSnapshot }).catch(() => 0);
|
|
1712
|
-
if (elementCount > 0)
|
|
1713
|
-
return continuePolling;
|
|
1714
|
-
}
|
|
1715
|
-
if (returnAction === "returnOnNotResolved" || returnAction === "returnAll") {
|
|
1716
|
-
const result2 = await action(null);
|
|
1717
|
-
return result2 === "internal:continuepolling" ? continuePolling : result2;
|
|
1718
|
-
}
|
|
1719
|
-
return continuePolling;
|
|
1720
|
-
}
|
|
1721
|
-
const resultElement = currentScopingElements[0];
|
|
1722
|
-
await resultElement._initializePreview().catch(() => {
|
|
1723
|
-
});
|
|
1724
|
-
let visibilityQualifier = "";
|
|
1725
|
-
if (options && options.__patchrightWaitForSelector) {
|
|
1726
|
-
visibilityQualifier = await resultElement.evaluateInUtility(([injected, node]) => injected.utils.isElementVisible(node) ? "visible" : "hidden", {}).catch(() => "");
|
|
1727
|
-
}
|
|
1728
|
-
if (currentScopingElements.length > 1) {
|
|
1729
|
-
if (resolved.info.strict) {
|
|
1730
|
-
await progress.race(resolved.injected.evaluateHandle((injected, {
|
|
1731
|
-
info,
|
|
1732
|
-
elements
|
|
1733
|
-
}) => {
|
|
1734
|
-
throw injected.strictModeViolationError(info.parsed, elements);
|
|
1735
|
-
}, {
|
|
1736
|
-
info: resolved.info,
|
|
1737
|
-
elements: currentScopingElements
|
|
1738
|
-
}));
|
|
1739
|
-
}
|
|
1740
|
-
progress.log(" locator resolved to " + currentScopingElements.length + " elements. Proceeding with the first one: " + resultElement.preview());
|
|
1741
|
-
} else if (resultElement) {
|
|
1742
|
-
progress.log(" locator resolved to " + (visibilityQualifier ? visibilityQualifier + " " : "") + resultElement.preview().replace("JSHandle@", ""));
|
|
1415
|
+
async ariaSnapshot(progress, options = {}) {
|
|
1416
|
+
if (options.selector && options.track)
|
|
1417
|
+
throw new Error("Cannot specify both selector and track options");
|
|
1418
|
+
if (options.selector && options.mode !== "ai") {
|
|
1419
|
+
const snapshot2 = await this._retryWithProgressIfNotConnected(progress, options.selector, { strict: true, performActionPreChecks: true }, async (handle) => {
|
|
1420
|
+
return await progress.race(handle.evaluateInUtility(([injected, element, opts]) => injected.ariaSnapshot(element, opts), { mode: "default", depth: options.depth }));
|
|
1421
|
+
});
|
|
1422
|
+
return { snapshot: snapshot2 };
|
|
1743
1423
|
}
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
} else if (result === "internal:continuepolling") {
|
|
1755
|
-
return continuePolling;
|
|
1756
|
-
}
|
|
1757
|
-
if (parsedSnapshot && result === null && (options.state === "hidden" || options.state === "detached")) {
|
|
1758
|
-
const visibleCount = await resolved.injected.evaluate((injected, { parsed }) => {
|
|
1759
|
-
const elements = injected.querySelectorAll(parsed, document);
|
|
1760
|
-
return elements.filter((e) => injected.utils.isElementVisible(e)).length;
|
|
1761
|
-
}, { parsed: parsedSnapshot }).catch(() => 0);
|
|
1762
|
-
if (visibleCount > 0)
|
|
1763
|
-
return continuePolling;
|
|
1764
|
-
}
|
|
1765
|
-
return result;
|
|
1766
|
-
} finally {
|
|
1424
|
+
let targetFrame;
|
|
1425
|
+
let info;
|
|
1426
|
+
if (options.selector) {
|
|
1427
|
+
const resolved = await this.selectors.resolveInjectedForSelector(options.selector, { strict: true });
|
|
1428
|
+
if (!resolved)
|
|
1429
|
+
throw new Error(`Selector "${options.selector}" did not resolve to any element`);
|
|
1430
|
+
targetFrame = resolved.frame;
|
|
1431
|
+
info = resolved.info;
|
|
1432
|
+
} else {
|
|
1433
|
+
targetFrame = this;
|
|
1767
1434
|
}
|
|
1435
|
+
const result = await (0, import_page.ariaSnapshotForFrame)(progress, targetFrame, { ...options, info });
|
|
1436
|
+
const snapshot = options.track && result.incremental ? result.incremental.join("\n") : result.full.join("\n");
|
|
1437
|
+
return { snapshot };
|
|
1768
1438
|
}
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
var currentScopingElements = [documentScope];
|
|
1772
|
-
while (parsed.parts.length > 0) {
|
|
1773
|
-
var part = parsed.parts.shift();
|
|
1774
|
-
parsedEdits.parts = [part];
|
|
1775
|
-
var elements = [];
|
|
1776
|
-
var elementsIndexes = [];
|
|
1777
|
-
if (part.name == "nth") {
|
|
1778
|
-
const partNth = Number(part.body);
|
|
1779
|
-
if (currentScopingElements.length == 0) return [];
|
|
1780
|
-
if (partNth > currentScopingElements.length - 1 || partNth < -(currentScopingElements.length - 1)) {
|
|
1781
|
-
if (parsed.capture !== void 0) throw new Error("Can't query n-th element in a request with the capture.");
|
|
1782
|
-
return [];
|
|
1783
|
-
} else {
|
|
1784
|
-
currentScopingElements = [currentScopingElements.at(partNth)];
|
|
1785
|
-
continue;
|
|
1786
|
-
}
|
|
1787
|
-
} else if (part.name == "internal:or") {
|
|
1788
|
-
var orredElements = await this._customFindElementsByParsed(resolved, client, context, documentScope, progress, part.body.parsed);
|
|
1789
|
-
elements = currentScopingElements.concat(orredElements);
|
|
1790
|
-
} else if (part.name == "internal:and") {
|
|
1791
|
-
var andedElements = await this._customFindElementsByParsed(resolved, client, context, documentScope, progress, part.body.parsed);
|
|
1792
|
-
const backendNodeIds = new Set(andedElements.map((item) => item.backendNodeId));
|
|
1793
|
-
elements = currentScopingElements.filter((item) => backendNodeIds.has(item.backendNodeId));
|
|
1794
|
-
} else {
|
|
1795
|
-
for (const scope of currentScopingElements) {
|
|
1796
|
-
let findClosedShadowRoots2 = function(node, results = []) {
|
|
1797
|
-
if (!node || typeof node !== "object") return results;
|
|
1798
|
-
if (node.shadowRoots && Array.isArray(node.shadowRoots)) {
|
|
1799
|
-
for (const shadowRoot2 of node.shadowRoots) {
|
|
1800
|
-
if (shadowRoot2.shadowRootType === "closed" && shadowRoot2.backendNodeId) {
|
|
1801
|
-
results.push(shadowRoot2.backendNodeId);
|
|
1802
|
-
}
|
|
1803
|
-
findClosedShadowRoots2(shadowRoot2, results);
|
|
1804
|
-
}
|
|
1805
|
-
}
|
|
1806
|
-
if (node.nodeName !== "IFRAME" && node.children && Array.isArray(node.children)) {
|
|
1807
|
-
for (const child of node.children) {
|
|
1808
|
-
findClosedShadowRoots2(child, results);
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
|
-
return results;
|
|
1812
|
-
};
|
|
1813
|
-
var findClosedShadowRoots = findClosedShadowRoots2;
|
|
1814
|
-
const describedScope = await client.send("DOM.describeNode", {
|
|
1815
|
-
objectId: scope._objectId,
|
|
1816
|
-
depth: -1,
|
|
1817
|
-
pierce: true
|
|
1818
|
-
});
|
|
1819
|
-
var queryingElements = [];
|
|
1820
|
-
var shadowRootBackendIds = findClosedShadowRoots2(describedScope.node);
|
|
1821
|
-
var shadowRoots = [];
|
|
1822
|
-
for (var shadowRootBackendId of shadowRootBackendIds) {
|
|
1823
|
-
var resolvedShadowRoot = await client.send("DOM.resolveNode", {
|
|
1824
|
-
backendNodeId: shadowRootBackendId,
|
|
1825
|
-
contextId: context.delegate._contextId
|
|
1826
|
-
});
|
|
1827
|
-
shadowRoots.push(new dom.ElementHandle(context, resolvedShadowRoot.object.objectId));
|
|
1828
|
-
}
|
|
1829
|
-
for (var shadowRoot of shadowRoots) {
|
|
1830
|
-
const shadowElements = await shadowRoot.evaluateHandleInUtility(([injected, node, { parsed: parsed2, callId }]) => {
|
|
1831
|
-
const elements2 = injected.querySelectorAll(parsed2, node);
|
|
1832
|
-
if (callId) injected.markTargetElements(new Set(elements2), callId);
|
|
1833
|
-
return elements2;
|
|
1834
|
-
}, {
|
|
1835
|
-
parsed: parsedEdits,
|
|
1836
|
-
callId: progress.metadata.id
|
|
1837
|
-
});
|
|
1838
|
-
const shadowElementsAmount = await shadowElements.getProperty("length");
|
|
1839
|
-
queryingElements.push([shadowElements, shadowElementsAmount, shadowRoot]);
|
|
1840
|
-
}
|
|
1841
|
-
const rootElements = await scope.evaluateHandleInUtility(([injected, node, { parsed: parsed2, callId }]) => {
|
|
1842
|
-
const elements2 = injected.querySelectorAll(parsed2, node);
|
|
1843
|
-
if (callId) injected.markTargetElements(new Set(elements2), callId);
|
|
1844
|
-
return elements2;
|
|
1845
|
-
}, {
|
|
1846
|
-
parsed: parsedEdits,
|
|
1847
|
-
callId: progress.metadata.id
|
|
1848
|
-
});
|
|
1849
|
-
const rootElementsAmount = await rootElements.getProperty("length");
|
|
1850
|
-
queryingElements.push([rootElements, rootElementsAmount, scope]);
|
|
1851
|
-
for (var queryedElement of queryingElements) {
|
|
1852
|
-
var elementsToCheck = queryedElement[0];
|
|
1853
|
-
var elementsAmount = await queryedElement[1].jsonValue();
|
|
1854
|
-
var parentNode = queryedElement[2];
|
|
1855
|
-
for (var i = 0; i < elementsAmount; i++) {
|
|
1856
|
-
if (parentNode.constructor.name == "ElementHandle") {
|
|
1857
|
-
var elementToCheck = await parentNode.evaluateHandleInUtility(([injected, node, { index, elementsToCheck: elementsToCheck2 }]) => {
|
|
1858
|
-
return elementsToCheck2[index];
|
|
1859
|
-
}, { index: i, elementsToCheck });
|
|
1860
|
-
} else {
|
|
1861
|
-
var elementToCheck = await parentNode.evaluateHandle((injected, { index, elementsToCheck: elementsToCheck2 }) => {
|
|
1862
|
-
return elementsToCheck2[index];
|
|
1863
|
-
}, { index: i, elementsToCheck });
|
|
1864
|
-
}
|
|
1865
|
-
elementToCheck.parentNode = parentNode;
|
|
1866
|
-
var resolvedElement = await client.send("DOM.describeNode", {
|
|
1867
|
-
objectId: elementToCheck._objectId,
|
|
1868
|
-
depth: -1
|
|
1869
|
-
});
|
|
1870
|
-
elementToCheck.backendNodeId = resolvedElement.node.backendNodeId;
|
|
1871
|
-
elementToCheck.nodePosition = this.selectors._findElementPositionInDomTree(elementToCheck, describedScope.node, context, "");
|
|
1872
|
-
elements.push(elementToCheck);
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
}
|
|
1877
|
-
const getParts = (pos) => (pos || "").split(".").filter(Boolean).map(Number);
|
|
1878
|
-
elements.sort((a, b) => {
|
|
1879
|
-
const partA = getParts(a.nodePosition);
|
|
1880
|
-
const partB = getParts(b.nodePosition);
|
|
1881
|
-
const maxLength = Math.max(partA.length, partB.length);
|
|
1882
|
-
for (let i2 = 0; i2 < maxLength; i2++) {
|
|
1883
|
-
const aVal = partA[i2] ?? -1;
|
|
1884
|
-
const bVal = partB[i2] ?? -1;
|
|
1885
|
-
if (aVal !== bVal) return aVal - bVal;
|
|
1886
|
-
}
|
|
1887
|
-
return 0;
|
|
1888
|
-
});
|
|
1889
|
-
currentScopingElements = Array.from(
|
|
1890
|
-
new Map(elements.map((e) => [e.backendNodeId, e])).values()
|
|
1891
|
-
);
|
|
1892
|
-
}
|
|
1893
|
-
return currentScopingElements;
|
|
1439
|
+
_asLocator(selector) {
|
|
1440
|
+
return (0, import_utils.asLocator)(this._page.browserContext._browser.sdkLanguage(), selector);
|
|
1894
1441
|
}
|
|
1895
1442
|
}
|
|
1896
1443
|
class SignalBarrier {
|