rebrowser-playwright-core 1.49.1 → 1.52.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 +381 -55
- package/bin/reinstall_msedge_beta_linux.sh +6 -0
- package/bin/reinstall_msedge_dev_linux.sh +6 -0
- package/bin/reinstall_msedge_stable_linux.sh +6 -0
- package/browsers.json +28 -13
- package/index.js +0 -1
- package/lib/androidServerImpl.js +42 -48
- package/lib/browserServerImpl.js +60 -64
- package/lib/cli/driver.js +71 -69
- package/lib/cli/program.js +314 -354
- package/lib/cli/programWithTestStub.js +51 -44
- package/lib/client/accessibility.js +31 -32
- package/lib/client/android.js +146 -254
- package/lib/client/api.js +135 -283
- package/lib/client/artifact.js +39 -39
- package/lib/client/browser.js +59 -68
- package/lib/client/browserContext.js +302 -322
- package/lib/client/browserType.js +95 -143
- package/lib/client/cdpSession.js +29 -31
- package/lib/client/channelOwner.js +109 -139
- package/lib/client/clientHelper.js +49 -42
- package/lib/client/clientInstrumentation.js +40 -35
- package/lib/client/clientStackTrace.js +69 -0
- package/lib/client/clock.js +36 -36
- package/lib/client/connection.js +203 -218
- package/lib/client/consoleMessage.js +33 -33
- package/lib/client/coverage.js +25 -22
- package/lib/client/dialog.js +30 -31
- package/lib/client/download.js +25 -25
- package/lib/client/electron.js +74 -76
- package/lib/client/elementHandle.js +126 -163
- package/lib/client/errors.js +53 -53
- package/lib/client/eventEmitter.js +127 -127
- package/lib/client/events.js +72 -68
- package/lib/client/fetch.js +154 -178
- package/lib/client/fileChooser.js +25 -24
- package/lib/client/fileUtils.js +34 -0
- package/lib/client/frame.js +189 -307
- package/lib/client/harRouter.js +44 -56
- package/lib/client/input.js +40 -69
- package/lib/client/jsHandle.js +55 -71
- package/lib/client/jsonPipe.js +27 -23
- package/lib/client/localUtils.js +53 -28
- package/lib/client/locator.js +144 -230
- package/lib/client/network.js +285 -301
- package/lib/client/page.js +273 -312
- package/lib/client/platform.js +74 -0
- package/lib/client/playwright.js +62 -57
- package/lib/client/selectors.js +51 -43
- package/lib/client/stream.js +30 -45
- package/lib/client/timeoutSettings.js +75 -0
- package/lib/client/tracing.js +49 -82
- package/lib/client/types.js +26 -22
- package/lib/client/video.js +35 -27
- package/lib/client/waiter.js +71 -91
- package/lib/client/webError.js +25 -23
- package/lib/client/webSocket.js +111 -0
- package/lib/client/worker.js +48 -56
- package/lib/client/writableStream.js +28 -43
- package/lib/generated/clockSource.js +26 -5
- package/lib/generated/consoleApiSource.js +26 -5
- package/lib/generated/injectedScriptSource.js +26 -5
- package/lib/generated/pollingRecorderSource.js +26 -5
- package/lib/generated/utilityScriptSource.js +26 -5
- package/lib/generated/webSocketMockSource.js +375 -4
- package/lib/inProcessFactory.js +53 -48
- package/lib/inprocess.js +2 -19
- package/lib/outofprocess.js +53 -42
- package/lib/protocol/debug.js +209 -25
- package/lib/protocol/serializers.js +153 -134
- package/lib/protocol/validator.js +2712 -2667
- package/lib/protocol/validatorPrimitives.js +115 -75
- package/lib/remote/playwrightConnection.js +144 -152
- package/lib/remote/playwrightServer.js +106 -77
- package/lib/server/accessibility.js +44 -37
- package/lib/server/android/android.js +216 -206
- package/lib/server/android/backendAdb.js +89 -82
- package/lib/server/artifact.js +78 -55
- package/lib/server/bidi/bidiBrowser.js +227 -158
- package/lib/server/bidi/bidiChromium.js +106 -78
- package/lib/server/bidi/bidiConnection.js +66 -83
- package/lib/server/bidi/bidiExecutionContext.js +161 -97
- package/lib/server/bidi/bidiFirefox.js +76 -68
- package/lib/server/bidi/bidiInput.js +90 -102
- package/lib/server/bidi/bidiNetworkManager.js +141 -159
- package/lib/server/bidi/bidiOverCdp.js +57 -58
- package/lib/server/bidi/bidiPage.js +262 -261
- package/lib/server/bidi/bidiPdf.js +52 -86
- package/lib/server/bidi/third_party/bidiCommands.d.js +22 -0
- package/lib/server/bidi/third_party/bidiDeserializer.js +55 -50
- package/lib/server/bidi/third_party/bidiKeyboard.js +241 -223
- package/lib/server/bidi/third_party/bidiProtocol.js +144 -131
- package/lib/server/bidi/third_party/bidiSerializer.js +67 -63
- package/lib/server/bidi/third_party/firefoxPrefs.js +149 -111
- package/lib/server/browser.js +76 -84
- package/lib/server/browserContext.js +343 -360
- package/lib/server/browserType.js +169 -181
- package/lib/server/callLog.js +82 -0
- package/lib/server/chromium/chromium.js +212 -190
- package/lib/server/chromium/chromiumSwitches.js +99 -44
- package/lib/server/chromium/crAccessibility.js +157 -131
- package/lib/server/chromium/crBrowser.js +262 -280
- package/lib/server/chromium/crConnection.js +121 -178
- package/lib/server/chromium/crCoverage.js +113 -127
- package/lib/server/chromium/crDevTools.js +64 -55
- package/lib/server/chromium/crDragDrop.js +62 -79
- package/lib/server/chromium/crExecutionContext.js +100 -91
- package/lib/server/chromium/crInput.js +101 -88
- package/lib/server/chromium/crNetworkManager.js +269 -370
- package/lib/server/chromium/crPage.js +509 -597
- package/lib/server/chromium/crPdf.js +54 -86
- package/lib/server/chromium/crProtocolHelper.js +92 -80
- package/lib/server/chromium/crServiceWorker.js +85 -69
- package/lib/server/chromium/defaultFontFamilies.js +152 -135
- package/lib/server/chromium/protocol.d.js +16 -0
- package/lib/server/chromium/videoRecorder.js +65 -99
- package/lib/server/clock.js +58 -46
- package/lib/server/codegen/csharp.js +191 -156
- package/lib/server/codegen/java.js +163 -125
- package/lib/server/codegen/javascript.js +166 -143
- package/lib/server/codegen/jsonl.js +33 -29
- package/lib/server/codegen/language.js +75 -52
- package/lib/server/codegen/languages.js +65 -27
- package/lib/server/codegen/python.js +141 -125
- package/lib/server/codegen/types.js +15 -4
- package/lib/server/console.js +28 -32
- package/lib/server/cookieStore.js +105 -86
- package/lib/server/debugController.js +102 -154
- package/lib/server/debugger.js +82 -78
- package/lib/server/deviceDescriptors.js +37 -24
- package/lib/server/deviceDescriptorsSource.json +131 -131
- package/lib/server/dialog.js +36 -35
- package/lib/server/dispatchers/androidDispatcher.js +196 -107
- package/lib/server/dispatchers/artifactDispatcher.js +62 -62
- package/lib/server/dispatchers/browserContextDispatcher.js +177 -217
- package/lib/server/dispatchers/browserDispatcher.js +78 -97
- package/lib/server/dispatchers/browserTypeDispatcher.js +35 -35
- package/lib/server/dispatchers/cdpSessionDispatcher.js +32 -36
- package/lib/server/dispatchers/debugControllerDispatcher.js +48 -64
- package/lib/server/dispatchers/dialogDispatcher.js +30 -27
- package/lib/server/dispatchers/dispatcher.js +180 -229
- package/lib/server/dispatchers/electronDispatcher.js +54 -57
- package/lib/server/dispatchers/elementHandlerDispatcher.js +79 -116
- package/lib/server/dispatchers/frameDispatcher.js +93 -162
- package/lib/server/dispatchers/jsHandleDispatcher.js +49 -66
- package/lib/server/dispatchers/jsonPipeDispatcher.js +35 -36
- package/lib/server/dispatchers/localUtilsDispatcher.js +107 -365
- package/lib/server/dispatchers/networkDispatchers.js +92 -109
- package/lib/server/dispatchers/pageDispatcher.js +130 -169
- package/lib/server/dispatchers/playwrightDispatcher.js +69 -76
- package/lib/server/dispatchers/selectorsDispatcher.js +28 -24
- package/lib/server/dispatchers/streamDispatcher.js +42 -44
- package/lib/server/dispatchers/tracingDispatcher.js +36 -41
- package/lib/server/dispatchers/webSocketRouteDispatcher.js +100 -135
- package/lib/server/dispatchers/writableStreamDispatcher.js +54 -39
- package/lib/server/dom.js +424 -443
- package/lib/server/download.js +45 -35
- package/lib/server/electron/electron.js +156 -175
- package/lib/server/electron/loader.js +8 -36
- package/lib/server/errors.js +47 -46
- package/lib/server/fetch.js +302 -331
- package/lib/server/fileChooser.js +25 -24
- package/lib/server/fileUploadUtils.js +66 -57
- package/lib/server/firefox/ffAccessibility.js +153 -131
- package/lib/server/firefox/ffBrowser.js +218 -274
- package/lib/server/firefox/ffConnection.js +63 -84
- package/lib/server/firefox/ffExecutionContext.js +103 -77
- package/lib/server/firefox/ffInput.js +72 -63
- package/lib/server/firefox/ffNetworkManager.js +131 -110
- package/lib/server/firefox/ffPage.js +244 -302
- package/lib/server/firefox/firefox.js +76 -69
- package/lib/server/firefox/protocol.d.js +16 -0
- package/lib/server/formData.js +107 -35
- package/lib/server/frameSelectors.js +77 -111
- package/lib/server/frames.js +719 -855
- package/lib/server/har/harRecorder.js +85 -77
- package/lib/server/har/harTracer.js +288 -224
- package/lib/server/harBackend.js +157 -0
- package/lib/server/helper.js +56 -59
- package/lib/server/index.js +59 -106
- package/lib/server/input.js +136 -166
- package/lib/server/instrumentation.js +49 -44
- package/lib/server/javascript.js +157 -151
- package/lib/server/launchApp.js +92 -73
- package/lib/server/localUtils.js +211 -0
- package/lib/server/macEditingCommands.js +141 -137
- package/lib/server/network.js +263 -297
- package/lib/server/page.js +351 -434
- package/lib/server/pageBinding.js +88 -0
- package/lib/server/pipeTransport.js +49 -45
- package/lib/server/playwright.js +60 -67
- package/lib/server/progress.js +56 -51
- package/lib/server/protocolError.js +34 -31
- package/lib/server/recorder/chat.js +161 -0
- package/lib/server/recorder/contextRecorder.js +135 -148
- package/lib/server/recorder/recorderApp.js +129 -132
- package/lib/server/recorder/recorderCollection.js +57 -57
- package/lib/server/recorder/recorderFrontend.js +15 -4
- package/lib/server/recorder/recorderRunner.js +80 -100
- package/lib/server/recorder/recorderUtils.js +59 -72
- package/lib/server/recorder/throttledFile.js +42 -31
- package/lib/server/recorder.js +186 -190
- package/lib/server/registry/browserFetcher.js +107 -100
- package/lib/server/registry/dependencies.js +247 -198
- package/lib/server/registry/index.js +928 -709
- package/lib/server/registry/nativeDeps.js +1073 -461
- package/lib/server/registry/oopDownloadBrowserMain.js +57 -75
- package/lib/server/screenshotter.js +166 -182
- package/lib/server/selectors.js +85 -46
- package/lib/server/socksClientCertificatesInterceptor.js +166 -185
- package/lib/server/socksInterceptor.js +62 -67
- package/lib/server/storageScript.js +154 -0
- package/lib/server/timeoutSettings.js +89 -0
- package/lib/server/trace/recorder/snapshotter.js +70 -88
- package/lib/server/trace/recorder/snapshotterInjected.js +246 -218
- package/lib/server/trace/recorder/tracing.js +324 -327
- package/lib/server/trace/test/inMemorySnapshotter.js +46 -52
- package/lib/server/trace/viewer/traceViewer.js +172 -137
- package/lib/server/transport.js +125 -133
- package/lib/server/types.js +26 -22
- package/lib/server/usKeyboardLayout.js +135 -545
- package/lib/server/utils/ascii.js +44 -0
- package/lib/server/utils/comparators.js +161 -0
- package/lib/server/utils/crypto.js +216 -0
- package/lib/server/utils/debug.js +47 -0
- package/lib/server/utils/debugLogger.js +114 -0
- package/lib/server/utils/env.js +68 -0
- package/lib/server/utils/eventsHelper.js +39 -0
- package/lib/server/utils/expectUtils.js +38 -0
- package/lib/server/utils/fileUtils.js +191 -0
- package/lib/server/utils/happyEyeballs.js +207 -0
- package/lib/server/utils/hostPlatform.js +109 -0
- package/lib/server/utils/httpServer.js +218 -0
- package/lib/server/utils/image_tools/colorUtils.js +89 -0
- package/lib/{image_tools → server/utils/image_tools}/compare.js +44 -43
- package/lib/server/utils/image_tools/imageChannel.js +78 -0
- package/lib/{image_tools → server/utils/image_tools}/stats.js +40 -40
- package/lib/server/utils/linuxUtils.js +71 -0
- package/lib/server/utils/network.js +217 -0
- package/lib/server/utils/nodePlatform.js +148 -0
- package/lib/server/utils/pipeTransport.js +84 -0
- package/lib/server/utils/processLauncher.js +238 -0
- package/lib/server/utils/profiler.js +65 -0
- package/lib/server/utils/socksProxy.js +511 -0
- package/lib/server/utils/spawnAsync.js +41 -0
- package/lib/server/utils/task.js +51 -0
- package/lib/server/utils/userAgent.js +98 -0
- package/lib/server/utils/wsServer.js +132 -0
- package/lib/server/utils/zipFile.js +74 -0
- package/lib/server/utils/zones.js +57 -0
- package/lib/server/webkit/protocol.d.js +16 -0
- package/lib/server/webkit/webkit.js +76 -63
- package/lib/server/webkit/wkAccessibility.js +161 -118
- package/lib/server/webkit/wkBrowser.js +163 -180
- package/lib/server/webkit/wkConnection.js +59 -83
- package/lib/server/webkit/wkExecutionContext.js +96 -73
- package/lib/server/webkit/wkInput.js +87 -75
- package/lib/server/webkit/wkInterceptableRequest.js +102 -95
- package/lib/server/webkit/wkPage.js +536 -647
- package/lib/server/webkit/wkProvisionalPage.js +45 -56
- package/lib/server/webkit/wkWorkers.js +77 -77
- package/lib/utils/isomorphic/ariaSnapshot.js +245 -128
- package/lib/utils/isomorphic/assert.js +31 -0
- package/lib/utils/isomorphic/builtins.js +90 -0
- package/lib/utils/isomorphic/colors.js +72 -0
- package/lib/utils/isomorphic/cssParser.js +123 -127
- package/lib/utils/isomorphic/cssTokenizer.js +436 -364
- package/lib/utils/isomorphic/headers.js +53 -0
- package/lib/utils/isomorphic/locatorGenerators.js +344 -349
- package/lib/utils/isomorphic/locatorParser.js +103 -106
- package/lib/utils/isomorphic/locatorUtils.js +63 -44
- package/lib/utils/isomorphic/manualPromise.js +115 -0
- package/lib/utils/isomorphic/mimeType.js +453 -22
- package/lib/utils/isomorphic/multimap.js +81 -0
- package/lib/utils/isomorphic/rtti.js +43 -0
- package/lib/utils/isomorphic/selectorParser.js +183 -193
- package/lib/utils/isomorphic/semaphore.js +54 -0
- package/lib/utils/isomorphic/stackTrace.js +158 -0
- package/lib/utils/isomorphic/stringUtils.js +113 -106
- package/lib/utils/isomorphic/time.js +44 -0
- package/lib/utils/isomorphic/timeoutRunner.js +67 -0
- package/lib/utils/isomorphic/traceUtils.js +52 -32
- package/lib/utils/isomorphic/types.js +16 -0
- package/lib/utils/isomorphic/urlMatch.js +114 -71
- package/lib/utils/isomorphic/utilityScriptSerializers.js +248 -0
- package/lib/utils.js +101 -0
- package/lib/utilsBundle.js +101 -76
- package/lib/utilsBundleImpl/index.js +114 -116
- package/lib/vite/htmlReport/index.html +26 -20
- package/lib/vite/recorder/assets/{codeMirrorModule-C5j27SYZ.js → codeMirrorModule-DVQi6prl.js} +13 -13
- package/lib/vite/recorder/assets/index-97EUAAbk.js +184 -0
- package/lib/vite/recorder/assets/{index-iA1aAGZg.css → index-eHBmevrY.css} +1 -1
- package/lib/vite/recorder/index.html +2 -2
- package/lib/vite/traceViewer/assets/codeMirrorModule-DwAiTpyC.js +24 -0
- package/lib/vite/traceViewer/assets/defaultSettingsView-DkkRvn5X.js +265 -0
- package/lib/vite/traceViewer/assets/{xtermModule-BeNbaIVa.js → xtermModule-BoAIEibi.js} +7 -7
- package/lib/vite/traceViewer/defaultSettingsView.QdHITyLI.css +1 -0
- package/lib/vite/traceViewer/index.DvtSwn6E.js +2 -0
- package/lib/vite/traceViewer/index.html +4 -7
- package/lib/vite/traceViewer/sw.bundle.js +3 -3
- package/lib/vite/traceViewer/{uiMode.voC1ZiOQ.css → uiMode.BatfzHMG.css} +1 -1
- package/lib/vite/traceViewer/uiMode.Sdytl9wc.js +5 -0
- package/lib/vite/traceViewer/uiMode.html +4 -7
- package/lib/zipBundle.js +32 -23
- package/lib/zipBundleImpl.js +4 -4
- package/package.json +7 -7
- package/types/protocol.d.ts +819 -127
- package/types/types.d.ts +181 -69
- package/bin/PrintDeps.exe +0 -0
- package/bin/README.md +0 -2
- package/lib/common/socksProxy.js +0 -569
- package/lib/common/timeoutSettings.js +0 -73
- package/lib/common/types.js +0 -5
- package/lib/image_tools/colorUtils.js +0 -98
- package/lib/image_tools/imageChannel.js +0 -70
- package/lib/protocol/transport.js +0 -82
- package/lib/server/ariaSnapshot.js +0 -33
- package/lib/server/isomorphic/utilityScriptSerializers.js +0 -226
- package/lib/server/recorder/recorderInTraceViewer.js +0 -144
- package/lib/utils/ascii.js +0 -31
- package/lib/utils/comparators.js +0 -153
- package/lib/utils/crypto.js +0 -171
- package/lib/utils/debug.js +0 -46
- package/lib/utils/debugLogger.js +0 -91
- package/lib/utils/env.js +0 -49
- package/lib/utils/eventsHelper.js +0 -38
- package/lib/utils/expectUtils.js +0 -33
- package/lib/utils/fileUtils.js +0 -205
- package/lib/utils/happy-eyeballs.js +0 -194
- package/lib/utils/headers.js +0 -52
- package/lib/utils/hostPlatform.js +0 -139
- package/lib/utils/httpServer.js +0 -237
- package/lib/utils/index.js +0 -368
- package/lib/utils/isomorphic/recorderUtils.js +0 -227
- package/lib/utils/linuxUtils.js +0 -78
- package/lib/utils/manualPromise.js +0 -109
- package/lib/utils/multimap.js +0 -75
- package/lib/utils/network.js +0 -160
- package/lib/utils/processLauncher.js +0 -248
- package/lib/utils/profiler.js +0 -53
- package/lib/utils/rtti.js +0 -44
- package/lib/utils/semaphore.js +0 -51
- package/lib/utils/sequence.js +0 -64
- package/lib/utils/spawnAsync.js +0 -45
- package/lib/utils/stackTrace.js +0 -134
- package/lib/utils/task.js +0 -58
- package/lib/utils/time.js +0 -37
- package/lib/utils/timeoutRunner.js +0 -66
- package/lib/utils/traceUtils.js +0 -44
- package/lib/utils/userAgent.js +0 -105
- package/lib/utils/wsServer.js +0 -127
- package/lib/utils/zipFile.js +0 -75
- package/lib/utils/zones.js +0 -71
- package/lib/vite/recorder/assets/index-m0XdVJHe.js +0 -184
- package/lib/vite/traceViewer/assets/codeMirrorModule-BBCX0spr.js +0 -24
- package/lib/vite/traceViewer/assets/inspectorTab-B4Iw34Ow.js +0 -68
- package/lib/vite/traceViewer/assets/testServerConnection-DeE2kSzz.js +0 -1
- package/lib/vite/traceViewer/assets/workbench-DFlGYqou.js +0 -9
- package/lib/vite/traceViewer/embedded.CmarehFk.js +0 -2
- package/lib/vite/traceViewer/embedded.html +0 -18
- package/lib/vite/traceViewer/embedded.w7WN2u1R.css +0 -1
- package/lib/vite/traceViewer/index.FBucu_gE.js +0 -2
- package/lib/vite/traceViewer/inspectorTab.DEOUW62d.css +0 -1
- package/lib/vite/traceViewer/recorder.B_SY1GJM.css +0 -0
- package/lib/vite/traceViewer/recorder.CW_rzcEp.js +0 -2
- package/lib/vite/traceViewer/recorder.html +0 -17
- package/lib/vite/traceViewer/uiMode.CDUVjusr.js +0 -5
- package/lib/vite/traceViewer/workbench.C-zR9ysA.css +0 -1
- /package/lib/vite/recorder/assets/{codeMirrorModule-ez37Vkbh.css → codeMirrorModule-C3UTv-Ge.css} +0 -0
- /package/lib/vite/traceViewer/{codeMirrorModule.ez37Vkbh.css → codeMirrorModule.C3UTv-Ge.css} +0 -0
- /package/lib/vite/traceViewer/{index.CrbWWHbf.css → index.CFOW-Ezb.css} +0 -0
- /package/lib/vite/traceViewer/{xtermModule.DSXBckUd.css → xtermModule.Beg8tuEN.css} +0 -0
package/lib/server/frames.js
CHANGED
|
@@ -1,75 +1,83 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty
|
|
4
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var frames_exports = {};
|
|
30
|
+
__export(frames_exports, {
|
|
31
|
+
Frame: () => Frame,
|
|
32
|
+
FrameManager: () => FrameManager,
|
|
33
|
+
NavigationAbortedError: () => NavigationAbortedError
|
|
5
34
|
});
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
27
|
-
/**
|
|
28
|
-
* Copyright 2017 Google Inc. All rights reserved.
|
|
29
|
-
* Modifications copyright (c) Microsoft Corporation.
|
|
30
|
-
*
|
|
31
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
32
|
-
* you may not use this file except in compliance with the License.
|
|
33
|
-
* You may obtain a copy of the License at
|
|
34
|
-
*
|
|
35
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
36
|
-
*
|
|
37
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
38
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
39
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
40
|
-
* See the License for the specific language governing permissions and
|
|
41
|
-
* limitations under the License.
|
|
42
|
-
*/
|
|
43
|
-
|
|
35
|
+
module.exports = __toCommonJS(frames_exports);
|
|
36
|
+
var import_browserContext = require("./browserContext");
|
|
37
|
+
var dom = __toESM(require("./dom"));
|
|
38
|
+
var import_errors = require("./errors");
|
|
39
|
+
var import_fileUploadUtils = require("./fileUploadUtils");
|
|
40
|
+
var import_frameSelectors = require("./frameSelectors");
|
|
41
|
+
var import_helper = require("./helper");
|
|
42
|
+
var import_instrumentation = require("./instrumentation");
|
|
43
|
+
var js = __toESM(require("./javascript"));
|
|
44
|
+
var network = __toESM(require("./network"));
|
|
45
|
+
var import_page = require("./page");
|
|
46
|
+
var import_progress = require("./progress");
|
|
47
|
+
var types = __toESM(require("./types"));
|
|
48
|
+
var import_utils = require("../utils");
|
|
49
|
+
var import_protocolError = require("./protocolError");
|
|
50
|
+
var import_debugLogger = require("./utils/debugLogger");
|
|
51
|
+
var import_eventsHelper = require("./utils/eventsHelper");
|
|
52
|
+
var import_selectorParser = require("../utils/isomorphic/selectorParser");
|
|
53
|
+
var import_manualPromise = require("../utils/isomorphic/manualPromise");
|
|
54
|
+
var import_callLog = require("./callLog");
|
|
44
55
|
class NavigationAbortedError extends Error {
|
|
45
56
|
constructor(documentId, message) {
|
|
46
57
|
super(message);
|
|
47
|
-
this.documentId = void 0;
|
|
48
58
|
this.documentId = documentId;
|
|
49
59
|
}
|
|
50
60
|
}
|
|
51
|
-
|
|
52
|
-
const kDummyFrameId = '<dummy>';
|
|
61
|
+
const kDummyFrameId = "<dummy>";
|
|
53
62
|
class FrameManager {
|
|
54
63
|
constructor(page) {
|
|
55
|
-
this.
|
|
56
|
-
this.
|
|
57
|
-
this.
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
60
|
-
this._webSockets = new Map();
|
|
61
|
-
this._openedDialogs = new Set();
|
|
64
|
+
this._frames = /* @__PURE__ */ new Map();
|
|
65
|
+
this._consoleMessageTags = /* @__PURE__ */ new Map();
|
|
66
|
+
this._signalBarriers = /* @__PURE__ */ new Set();
|
|
67
|
+
this._webSockets = /* @__PURE__ */ new Map();
|
|
68
|
+
this._openedDialogs = /* @__PURE__ */ new Set();
|
|
62
69
|
this._closeAllOpeningDialogs = false;
|
|
63
70
|
this._page = page;
|
|
64
|
-
this._mainFrame =
|
|
71
|
+
this._mainFrame = void 0;
|
|
65
72
|
}
|
|
66
73
|
createDummyMainFrameIfNeeded() {
|
|
67
|
-
if (!this._mainFrame)
|
|
74
|
+
if (!this._mainFrame)
|
|
75
|
+
this.frameAttached(kDummyFrameId, null);
|
|
68
76
|
}
|
|
69
77
|
dispose() {
|
|
70
78
|
for (const frame of this._frames.values()) {
|
|
71
79
|
frame._stopNetworkIdleTimer();
|
|
72
|
-
frame._invalidateNonStallingEvaluations(
|
|
80
|
+
frame._invalidateNonStallingEvaluations("Target crashed");
|
|
73
81
|
}
|
|
74
82
|
}
|
|
75
83
|
mainFrame() {
|
|
@@ -81,7 +89,8 @@ class FrameManager {
|
|
|
81
89
|
return frames;
|
|
82
90
|
function collect(frame) {
|
|
83
91
|
frames.push(frame);
|
|
84
|
-
for (const subframe of frame.childFrames())
|
|
92
|
+
for (const subframe of frame.childFrames())
|
|
93
|
+
collect(subframe);
|
|
85
94
|
}
|
|
86
95
|
}
|
|
87
96
|
frame(frameId) {
|
|
@@ -91,55 +100,55 @@ class FrameManager {
|
|
|
91
100
|
const parentFrame = parentFrameId ? this._frames.get(parentFrameId) : null;
|
|
92
101
|
if (!parentFrame) {
|
|
93
102
|
if (this._mainFrame) {
|
|
94
|
-
// Update frame id to retain frame identity on cross-process navigation.
|
|
95
103
|
this._frames.delete(this._mainFrame._id);
|
|
96
104
|
this._mainFrame._id = frameId;
|
|
97
105
|
} else {
|
|
98
|
-
(0,
|
|
106
|
+
(0, import_utils.assert)(!this._frames.has(frameId));
|
|
99
107
|
this._mainFrame = new Frame(this._page, frameId, parentFrame);
|
|
100
108
|
}
|
|
101
109
|
this._frames.set(frameId, this._mainFrame);
|
|
102
110
|
return this._mainFrame;
|
|
103
111
|
} else {
|
|
104
|
-
(0,
|
|
112
|
+
(0, import_utils.assert)(!this._frames.has(frameId));
|
|
105
113
|
const frame = new Frame(this._page, frameId, parentFrame);
|
|
106
114
|
this._frames.set(frameId, frame);
|
|
107
|
-
this._page.emit(
|
|
115
|
+
this._page.emit(import_page.Page.Events.FrameAttached, frame);
|
|
108
116
|
return frame;
|
|
109
117
|
}
|
|
110
118
|
}
|
|
111
119
|
async waitForSignalsCreatedBy(progress, waitAfter, action) {
|
|
112
|
-
if (!waitAfter)
|
|
120
|
+
if (!waitAfter)
|
|
121
|
+
return action();
|
|
113
122
|
const barrier = new SignalBarrier(progress);
|
|
114
123
|
this._signalBarriers.add(barrier);
|
|
115
|
-
if (progress)
|
|
124
|
+
if (progress)
|
|
125
|
+
progress.cleanupWhenAborted(() => this._signalBarriers.delete(barrier));
|
|
116
126
|
const result = await action();
|
|
117
127
|
await this._page._delegate.inputActionEpilogue();
|
|
118
128
|
await barrier.waitFor();
|
|
119
129
|
this._signalBarriers.delete(barrier);
|
|
120
|
-
|
|
121
|
-
await new Promise((0, _utils.makeWaitForNextTask)());
|
|
130
|
+
await new Promise((0, import_utils.makeWaitForNextTask)());
|
|
122
131
|
return result;
|
|
123
132
|
}
|
|
124
133
|
frameWillPotentiallyRequestNavigation() {
|
|
125
|
-
for (const barrier of this._signalBarriers)
|
|
134
|
+
for (const barrier of this._signalBarriers)
|
|
135
|
+
barrier.retain();
|
|
126
136
|
}
|
|
127
137
|
frameDidPotentiallyRequestNavigation() {
|
|
128
|
-
for (const barrier of this._signalBarriers)
|
|
138
|
+
for (const barrier of this._signalBarriers)
|
|
139
|
+
barrier.release();
|
|
129
140
|
}
|
|
130
141
|
frameRequestedNavigation(frameId, documentId) {
|
|
131
142
|
const frame = this._frames.get(frameId);
|
|
132
|
-
if (!frame)
|
|
133
|
-
|
|
143
|
+
if (!frame)
|
|
144
|
+
return;
|
|
145
|
+
for (const barrier of this._signalBarriers)
|
|
146
|
+
barrier.addFrameNavigation(frame);
|
|
134
147
|
if (frame.pendingDocument() && frame.pendingDocument().documentId === documentId) {
|
|
135
|
-
// Do not override request with undefined.
|
|
136
148
|
return;
|
|
137
149
|
}
|
|
138
|
-
const request = documentId ? Array.from(frame._inflightRequests).find(
|
|
139
|
-
frame.setPendingDocument({
|
|
140
|
-
documentId,
|
|
141
|
-
request
|
|
142
|
-
});
|
|
150
|
+
const request = documentId ? Array.from(frame._inflightRequests).find((request2) => request2._documentId === documentId) : void 0;
|
|
151
|
+
frame.setPendingDocument({ documentId, request });
|
|
143
152
|
}
|
|
144
153
|
frameCommittedNewDocumentNavigation(frameId, url, name, documentId, initial) {
|
|
145
154
|
const frame = this._frames.get(frameId);
|
|
@@ -150,69 +159,47 @@ class FrameManager {
|
|
|
150
159
|
let keepPending;
|
|
151
160
|
const pendingDocument = frame.pendingDocument();
|
|
152
161
|
if (pendingDocument) {
|
|
153
|
-
if (pendingDocument.documentId ===
|
|
154
|
-
// Pending with unknown documentId - assume it is the one being committed.
|
|
162
|
+
if (pendingDocument.documentId === void 0) {
|
|
155
163
|
pendingDocument.documentId = documentId;
|
|
156
164
|
}
|
|
157
165
|
if (pendingDocument.documentId === documentId) {
|
|
158
|
-
// Committing a pending document.
|
|
159
166
|
frame._currentDocument = pendingDocument;
|
|
160
167
|
} else {
|
|
161
|
-
// Sometimes, we already have a new pending when the old one commits.
|
|
162
|
-
// An example would be Chromium error page followed by a new navigation request,
|
|
163
|
-
// where the error page commit arrives after Network.requestWillBeSent for the
|
|
164
|
-
// new navigation.
|
|
165
|
-
// We commit, but keep the pending request since it's not done yet.
|
|
166
168
|
keepPending = pendingDocument;
|
|
167
|
-
frame._currentDocument = {
|
|
168
|
-
documentId,
|
|
169
|
-
request: undefined
|
|
170
|
-
};
|
|
169
|
+
frame._currentDocument = { documentId, request: void 0 };
|
|
171
170
|
}
|
|
172
|
-
frame.setPendingDocument(
|
|
171
|
+
frame.setPendingDocument(void 0);
|
|
173
172
|
} else {
|
|
174
|
-
|
|
175
|
-
frame._currentDocument = {
|
|
176
|
-
documentId,
|
|
177
|
-
request: undefined
|
|
178
|
-
};
|
|
173
|
+
frame._currentDocument = { documentId, request: void 0 };
|
|
179
174
|
}
|
|
180
175
|
frame._onClearLifecycle();
|
|
181
|
-
const navigationEvent = {
|
|
182
|
-
url,
|
|
183
|
-
name,
|
|
184
|
-
newDocument: frame._currentDocument,
|
|
185
|
-
isPublic: true
|
|
186
|
-
};
|
|
176
|
+
const navigationEvent = { url, name, newDocument: frame._currentDocument, isPublic: true };
|
|
187
177
|
this._fireInternalFrameNavigation(frame, navigationEvent);
|
|
188
178
|
if (!initial) {
|
|
189
|
-
|
|
179
|
+
import_debugLogger.debugLogger.log("api", ` navigated to "${url}"`);
|
|
190
180
|
this._page.frameNavigatedToNewDocument(frame);
|
|
191
181
|
}
|
|
192
|
-
// Restore pending if any - see comments above about keepPending.
|
|
193
182
|
frame.setPendingDocument(keepPending);
|
|
194
183
|
}
|
|
195
184
|
frameCommittedSameDocumentNavigation(frameId, url) {
|
|
196
185
|
const frame = this._frames.get(frameId);
|
|
197
|
-
if (!frame)
|
|
186
|
+
if (!frame)
|
|
187
|
+
return;
|
|
198
188
|
const pending = frame.pendingDocument();
|
|
199
|
-
if (pending && pending.documentId ===
|
|
200
|
-
|
|
201
|
-
frame.setPendingDocument(undefined);
|
|
189
|
+
if (pending && pending.documentId === void 0 && pending.request === void 0) {
|
|
190
|
+
frame.setPendingDocument(void 0);
|
|
202
191
|
}
|
|
203
192
|
frame._url = url;
|
|
204
|
-
const navigationEvent = {
|
|
205
|
-
url,
|
|
206
|
-
name: frame._name,
|
|
207
|
-
isPublic: true
|
|
208
|
-
};
|
|
193
|
+
const navigationEvent = { url, name: frame._name, isPublic: true };
|
|
209
194
|
this._fireInternalFrameNavigation(frame, navigationEvent);
|
|
210
|
-
|
|
195
|
+
import_debugLogger.debugLogger.log("api", ` navigated to "${url}"`);
|
|
211
196
|
}
|
|
212
197
|
frameAbortedNavigation(frameId, errorText, documentId) {
|
|
213
198
|
const frame = this._frames.get(frameId);
|
|
214
|
-
if (!frame || !frame.pendingDocument())
|
|
215
|
-
|
|
199
|
+
if (!frame || !frame.pendingDocument())
|
|
200
|
+
return;
|
|
201
|
+
if (documentId !== void 0 && frame.pendingDocument().documentId !== documentId)
|
|
202
|
+
return;
|
|
216
203
|
const navigationEvent = {
|
|
217
204
|
url: frame._url,
|
|
218
205
|
name: frame._name,
|
|
@@ -220,7 +207,7 @@ class FrameManager {
|
|
|
220
207
|
error: new NavigationAbortedError(documentId, errorText),
|
|
221
208
|
isPublic: !(documentId && frame._redirectedNavigations.has(documentId))
|
|
222
209
|
};
|
|
223
|
-
frame.setPendingDocument(
|
|
210
|
+
frame.setPendingDocument(void 0);
|
|
224
211
|
this._fireInternalFrameNavigation(frame, navigationEvent);
|
|
225
212
|
}
|
|
226
213
|
frameDetached(frameId) {
|
|
@@ -232,105 +219,119 @@ class FrameManager {
|
|
|
232
219
|
}
|
|
233
220
|
frameLifecycleEvent(frameId, event) {
|
|
234
221
|
const frame = this._frames.get(frameId);
|
|
235
|
-
if (frame)
|
|
222
|
+
if (frame)
|
|
223
|
+
frame._onLifecycleEvent(event);
|
|
236
224
|
}
|
|
237
225
|
requestStarted(request, route) {
|
|
238
226
|
const frame = request.frame();
|
|
239
227
|
this._inflightRequestStarted(request);
|
|
240
|
-
if (request._documentId)
|
|
241
|
-
documentId: request._documentId,
|
|
242
|
-
request
|
|
243
|
-
});
|
|
228
|
+
if (request._documentId)
|
|
229
|
+
frame.setPendingDocument({ documentId: request._documentId, request });
|
|
244
230
|
if (request._isFavicon) {
|
|
245
|
-
route
|
|
246
|
-
|
|
247
|
-
}).catch(() => {});
|
|
231
|
+
route?.abort("aborted").catch(() => {
|
|
232
|
+
});
|
|
248
233
|
return;
|
|
249
234
|
}
|
|
250
|
-
this._page.emitOnContext(
|
|
235
|
+
this._page.emitOnContext(import_browserContext.BrowserContext.Events.Request, request);
|
|
251
236
|
if (route) {
|
|
252
|
-
var _this$_page$_serverRe, _this$_page, _this$_page$_clientRe, _this$_page2, _this$_page$_browserC, _this$_page$_browserC2;
|
|
253
237
|
const r = new network.Route(request, route);
|
|
254
|
-
if (
|
|
255
|
-
|
|
256
|
-
if (
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
238
|
+
if (this._page._serverRequestInterceptor?.(r, request))
|
|
239
|
+
return;
|
|
240
|
+
if (this._page._clientRequestInterceptor?.(r, request))
|
|
241
|
+
return;
|
|
242
|
+
if (this._page._browserContext._requestInterceptor?.(r, request))
|
|
243
|
+
return;
|
|
244
|
+
r.continue({ isFallback: true }).catch(() => {
|
|
245
|
+
});
|
|
260
246
|
}
|
|
261
247
|
}
|
|
262
248
|
requestReceivedResponse(response) {
|
|
263
|
-
if (response.request()._isFavicon)
|
|
264
|
-
|
|
249
|
+
if (response.request()._isFavicon)
|
|
250
|
+
return;
|
|
251
|
+
this._page.emitOnContext(import_browserContext.BrowserContext.Events.Response, response);
|
|
265
252
|
}
|
|
266
253
|
reportRequestFinished(request, response) {
|
|
267
254
|
this._inflightRequestFinished(request);
|
|
268
|
-
if (request._isFavicon)
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
response
|
|
272
|
-
});
|
|
255
|
+
if (request._isFavicon)
|
|
256
|
+
return;
|
|
257
|
+
this._page.emitOnContext(import_browserContext.BrowserContext.Events.RequestFinished, { request, response });
|
|
273
258
|
}
|
|
274
259
|
requestFailed(request, canceled) {
|
|
275
260
|
const frame = request.frame();
|
|
276
261
|
this._inflightRequestFinished(request);
|
|
277
262
|
if (frame.pendingDocument() && frame.pendingDocument().request === request) {
|
|
278
263
|
let errorText = request.failure().errorText;
|
|
279
|
-
if (canceled)
|
|
264
|
+
if (canceled)
|
|
265
|
+
errorText += "; maybe frame was detached?";
|
|
280
266
|
this.frameAbortedNavigation(frame._id, errorText, frame.pendingDocument().documentId);
|
|
281
267
|
}
|
|
282
|
-
if (request._isFavicon)
|
|
283
|
-
|
|
268
|
+
if (request._isFavicon)
|
|
269
|
+
return;
|
|
270
|
+
this._page.emitOnContext(import_browserContext.BrowserContext.Events.RequestFailed, request);
|
|
284
271
|
}
|
|
285
272
|
dialogDidOpen(dialog) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
if (this._closeAllOpeningDialogs)
|
|
273
|
+
for (const frame of this._frames.values())
|
|
274
|
+
frame._invalidateNonStallingEvaluations("JavaScript dialog interrupted evaluation");
|
|
275
|
+
if (this._closeAllOpeningDialogs)
|
|
276
|
+
dialog.close().then(() => {
|
|
277
|
+
});
|
|
278
|
+
else
|
|
279
|
+
this._openedDialogs.add(dialog);
|
|
289
280
|
}
|
|
290
281
|
dialogWillClose(dialog) {
|
|
291
282
|
this._openedDialogs.delete(dialog);
|
|
292
283
|
}
|
|
293
284
|
async closeOpenDialogs() {
|
|
294
|
-
await Promise.all([...this._openedDialogs].map(dialog => dialog.close())).catch(() => {
|
|
285
|
+
await Promise.all([...this._openedDialogs].map((dialog) => dialog.close())).catch(() => {
|
|
286
|
+
});
|
|
295
287
|
this._openedDialogs.clear();
|
|
296
288
|
}
|
|
297
289
|
setCloseAllOpeningDialogs(closeDialogs) {
|
|
298
290
|
this._closeAllOpeningDialogs = closeDialogs;
|
|
299
291
|
}
|
|
300
292
|
removeChildFramesRecursively(frame) {
|
|
301
|
-
for (const child of frame.childFrames())
|
|
293
|
+
for (const child of frame.childFrames())
|
|
294
|
+
this._removeFramesRecursively(child);
|
|
302
295
|
}
|
|
303
296
|
_removeFramesRecursively(frame) {
|
|
304
297
|
this.removeChildFramesRecursively(frame);
|
|
305
298
|
frame._onDetached();
|
|
306
299
|
this._frames.delete(frame._id);
|
|
307
|
-
if (!this._page.isClosed())
|
|
300
|
+
if (!this._page.isClosed())
|
|
301
|
+
this._page.emit(import_page.Page.Events.FrameDetached, frame);
|
|
308
302
|
}
|
|
309
303
|
_inflightRequestFinished(request) {
|
|
310
304
|
const frame = request.frame();
|
|
311
|
-
if (request._isFavicon)
|
|
312
|
-
|
|
305
|
+
if (request._isFavicon)
|
|
306
|
+
return;
|
|
307
|
+
if (!frame._inflightRequests.has(request))
|
|
308
|
+
return;
|
|
313
309
|
frame._inflightRequests.delete(request);
|
|
314
|
-
if (frame._inflightRequests.size === 0)
|
|
310
|
+
if (frame._inflightRequests.size === 0)
|
|
311
|
+
frame._startNetworkIdleTimer();
|
|
315
312
|
}
|
|
316
313
|
_inflightRequestStarted(request) {
|
|
317
314
|
const frame = request.frame();
|
|
318
|
-
if (request._isFavicon)
|
|
315
|
+
if (request._isFavicon)
|
|
316
|
+
return;
|
|
319
317
|
frame._inflightRequests.add(request);
|
|
320
|
-
if (frame._inflightRequests.size === 1)
|
|
318
|
+
if (frame._inflightRequests.size === 1)
|
|
319
|
+
frame._stopNetworkIdleTimer();
|
|
321
320
|
}
|
|
322
321
|
interceptConsoleMessage(message) {
|
|
323
|
-
if (message.type() !==
|
|
322
|
+
if (message.type() !== "debug")
|
|
323
|
+
return false;
|
|
324
324
|
const tag = message.text();
|
|
325
325
|
const handler = this._consoleMessageTags.get(tag);
|
|
326
|
-
if (!handler)
|
|
326
|
+
if (!handler)
|
|
327
|
+
return false;
|
|
327
328
|
this._consoleMessageTags.delete(tag);
|
|
328
329
|
handler();
|
|
329
330
|
return true;
|
|
330
331
|
}
|
|
331
332
|
clearWebSockets(frame) {
|
|
332
|
-
|
|
333
|
-
|
|
333
|
+
if (frame.parentFrame())
|
|
334
|
+
return;
|
|
334
335
|
this._webSockets.clear();
|
|
335
336
|
}
|
|
336
337
|
onWebSocketCreated(requestId, url) {
|
|
@@ -339,121 +340,130 @@ class FrameManager {
|
|
|
339
340
|
}
|
|
340
341
|
onWebSocketRequest(requestId) {
|
|
341
342
|
const ws = this._webSockets.get(requestId);
|
|
342
|
-
if (ws && ws.markAsNotified())
|
|
343
|
+
if (ws && ws.markAsNotified())
|
|
344
|
+
this._page.emit(import_page.Page.Events.WebSocket, ws);
|
|
343
345
|
}
|
|
344
346
|
onWebSocketResponse(requestId, status, statusText) {
|
|
345
347
|
const ws = this._webSockets.get(requestId);
|
|
346
|
-
if (status < 400)
|
|
347
|
-
|
|
348
|
+
if (status < 400)
|
|
349
|
+
return;
|
|
350
|
+
if (ws)
|
|
351
|
+
ws.error(`${statusText}: ${status}`);
|
|
348
352
|
}
|
|
349
353
|
onWebSocketFrameSent(requestId, opcode, data) {
|
|
350
354
|
const ws = this._webSockets.get(requestId);
|
|
351
|
-
if (ws)
|
|
355
|
+
if (ws)
|
|
356
|
+
ws.frameSent(opcode, data);
|
|
352
357
|
}
|
|
353
358
|
webSocketFrameReceived(requestId, opcode, data) {
|
|
354
359
|
const ws = this._webSockets.get(requestId);
|
|
355
|
-
if (ws)
|
|
360
|
+
if (ws)
|
|
361
|
+
ws.frameReceived(opcode, data);
|
|
356
362
|
}
|
|
357
363
|
webSocketClosed(requestId) {
|
|
358
364
|
const ws = this._webSockets.get(requestId);
|
|
359
|
-
if (ws)
|
|
365
|
+
if (ws)
|
|
366
|
+
ws.closed();
|
|
360
367
|
this._webSockets.delete(requestId);
|
|
361
368
|
}
|
|
362
369
|
webSocketError(requestId, errorMessage) {
|
|
363
370
|
const ws = this._webSockets.get(requestId);
|
|
364
|
-
if (ws)
|
|
371
|
+
if (ws)
|
|
372
|
+
ws.error(errorMessage);
|
|
365
373
|
}
|
|
366
374
|
_fireInternalFrameNavigation(frame, event) {
|
|
367
375
|
frame.emit(Frame.Events.InternalNavigation, event);
|
|
368
376
|
}
|
|
369
377
|
}
|
|
370
|
-
|
|
371
|
-
class Frame extends _instrumentation.SdkObject {
|
|
378
|
+
class Frame extends import_instrumentation.SdkObject {
|
|
372
379
|
constructor(page, id, parentFrame) {
|
|
373
|
-
super(page,
|
|
374
|
-
this.
|
|
375
|
-
this._firedLifecycleEvents = new Set();
|
|
380
|
+
super(page, "frame");
|
|
381
|
+
this._firedLifecycleEvents = /* @__PURE__ */ new Set();
|
|
376
382
|
this._firedNetworkIdleSelf = false;
|
|
377
|
-
this.
|
|
378
|
-
this.
|
|
379
|
-
this.
|
|
380
|
-
this.
|
|
381
|
-
this.
|
|
382
|
-
this._contextData = new Map();
|
|
383
|
-
this._childFrames = new Set();
|
|
384
|
-
this._name = '';
|
|
385
|
-
this._inflightRequests = new Set();
|
|
386
|
-
this._networkIdleTimer = void 0;
|
|
383
|
+
this._url = "";
|
|
384
|
+
this._contextData = /* @__PURE__ */ new Map();
|
|
385
|
+
this._childFrames = /* @__PURE__ */ new Set();
|
|
386
|
+
this._name = "";
|
|
387
|
+
this._inflightRequests = /* @__PURE__ */ new Set();
|
|
387
388
|
this._setContentCounter = 0;
|
|
388
|
-
this._detachedScope = new
|
|
389
|
-
this._raceAgainstEvaluationStallingEventsPromises = new Set();
|
|
390
|
-
this._redirectedNavigations = new Map();
|
|
391
|
-
// documentId -> data
|
|
392
|
-
this.selectors = void 0;
|
|
389
|
+
this._detachedScope = new import_utils.LongStandingScope();
|
|
390
|
+
this._raceAgainstEvaluationStallingEventsPromises = /* @__PURE__ */ new Set();
|
|
391
|
+
this._redirectedNavigations = /* @__PURE__ */ new Map();
|
|
393
392
|
this.attribution.frame = this;
|
|
394
393
|
this._id = id;
|
|
395
394
|
this._page = page;
|
|
396
395
|
this._parentFrame = parentFrame;
|
|
397
|
-
this._currentDocument = {
|
|
398
|
-
|
|
399
|
-
|
|
396
|
+
this._currentDocument = { documentId: void 0, request: void 0 };
|
|
397
|
+
this.selectors = new import_frameSelectors.FrameSelectors(this);
|
|
398
|
+
this._contextData.set("main", { contextPromise: new import_manualPromise.ManualPromise(), context: null });
|
|
399
|
+
this._contextData.set("utility", { contextPromise: new import_manualPromise.ManualPromise(), context: null });
|
|
400
|
+
this._setContext("main", null);
|
|
401
|
+
this._setContext("utility", null);
|
|
402
|
+
if (this._parentFrame)
|
|
403
|
+
this._parentFrame._childFrames.add(this);
|
|
404
|
+
this._firedLifecycleEvents.add("commit");
|
|
405
|
+
if (id !== kDummyFrameId)
|
|
406
|
+
this._startNetworkIdleTimer();
|
|
407
|
+
}
|
|
408
|
+
static {
|
|
409
|
+
this.Events = {
|
|
410
|
+
InternalNavigation: "internalnavigation",
|
|
411
|
+
AddLifecycle: "addlifecycle",
|
|
412
|
+
RemoveLifecycle: "removelifecycle"
|
|
400
413
|
};
|
|
401
|
-
this.selectors = new _frameSelectors.FrameSelectors(this);
|
|
402
|
-
this._contextData.set('main', {
|
|
403
|
-
contextPromise: new _manualPromise.ManualPromise(),
|
|
404
|
-
context: null
|
|
405
|
-
});
|
|
406
|
-
this._contextData.set('utility', {
|
|
407
|
-
contextPromise: new _manualPromise.ManualPromise(),
|
|
408
|
-
context: null
|
|
409
|
-
});
|
|
410
|
-
this._setContext('main', null);
|
|
411
|
-
this._setContext('utility', null);
|
|
412
|
-
if (this._parentFrame) this._parentFrame._childFrames.add(this);
|
|
413
|
-
this._firedLifecycleEvents.add('commit');
|
|
414
|
-
if (id !== kDummyFrameId) this._startNetworkIdleTimer();
|
|
415
414
|
}
|
|
416
415
|
isDetached() {
|
|
417
416
|
return this._detachedScope.isClosed();
|
|
418
417
|
}
|
|
419
418
|
_onLifecycleEvent(event) {
|
|
420
|
-
if (this._firedLifecycleEvents.has(event))
|
|
419
|
+
if (this._firedLifecycleEvents.has(event))
|
|
420
|
+
return;
|
|
421
421
|
this._firedLifecycleEvents.add(event);
|
|
422
422
|
this.emit(Frame.Events.AddLifecycle, event);
|
|
423
|
-
if (this === this._page.mainFrame() && this._url !==
|
|
423
|
+
if (this === this._page.mainFrame() && this._url !== "about:blank")
|
|
424
|
+
import_debugLogger.debugLogger.log("api", ` "${event}" event fired`);
|
|
424
425
|
this._page.mainFrame()._recalculateNetworkIdle();
|
|
425
426
|
}
|
|
426
427
|
_onClearLifecycle() {
|
|
427
|
-
for (const event of this._firedLifecycleEvents)
|
|
428
|
+
for (const event of this._firedLifecycleEvents)
|
|
429
|
+
this.emit(Frame.Events.RemoveLifecycle, event);
|
|
428
430
|
this._firedLifecycleEvents.clear();
|
|
429
|
-
|
|
430
|
-
this._inflightRequests = new Set(Array.from(this._inflightRequests).filter(request => request === this._currentDocument.request));
|
|
431
|
+
this._inflightRequests = new Set(Array.from(this._inflightRequests).filter((request) => request === this._currentDocument.request));
|
|
431
432
|
this._stopNetworkIdleTimer();
|
|
432
|
-
if (this._inflightRequests.size === 0)
|
|
433
|
+
if (this._inflightRequests.size === 0)
|
|
434
|
+
this._startNetworkIdleTimer();
|
|
433
435
|
this._page.mainFrame()._recalculateNetworkIdle(this);
|
|
434
|
-
this._onLifecycleEvent(
|
|
436
|
+
this._onLifecycleEvent("commit");
|
|
435
437
|
const crSession = (this._page._delegate._sessions.get(this._id) || this._page._delegate._mainFrameSession)._client;
|
|
436
|
-
crSession.emit(
|
|
438
|
+
crSession.emit("Runtime.executionContextsCleared");
|
|
437
439
|
}
|
|
438
440
|
setPendingDocument(documentInfo) {
|
|
439
441
|
this._pendingDocument = documentInfo;
|
|
440
|
-
if (documentInfo)
|
|
442
|
+
if (documentInfo)
|
|
443
|
+
this._invalidateNonStallingEvaluations("Navigation interrupted the evaluation");
|
|
441
444
|
}
|
|
442
445
|
pendingDocument() {
|
|
443
446
|
return this._pendingDocument;
|
|
444
447
|
}
|
|
445
448
|
_invalidateNonStallingEvaluations(message) {
|
|
446
|
-
if (!this._raceAgainstEvaluationStallingEventsPromises.size)
|
|
449
|
+
if (!this._raceAgainstEvaluationStallingEventsPromises.size)
|
|
450
|
+
return;
|
|
447
451
|
const error = new Error(message);
|
|
448
|
-
for (const promise of this._raceAgainstEvaluationStallingEventsPromises)
|
|
452
|
+
for (const promise of this._raceAgainstEvaluationStallingEventsPromises)
|
|
453
|
+
promise.reject(error);
|
|
449
454
|
}
|
|
450
455
|
async raceAgainstEvaluationStallingEvents(cb) {
|
|
451
|
-
if (this._pendingDocument)
|
|
452
|
-
|
|
453
|
-
|
|
456
|
+
if (this._pendingDocument)
|
|
457
|
+
throw new Error("Frame is currently attempting a navigation");
|
|
458
|
+
if (this._page._frameManager._openedDialogs.size)
|
|
459
|
+
throw new Error("Open JavaScript dialog prevents evaluation");
|
|
460
|
+
const promise = new import_manualPromise.ManualPromise();
|
|
454
461
|
this._raceAgainstEvaluationStallingEventsPromises.add(promise);
|
|
455
462
|
try {
|
|
456
|
-
return await Promise.race([
|
|
463
|
+
return await Promise.race([
|
|
464
|
+
cb(),
|
|
465
|
+
promise
|
|
466
|
+
]);
|
|
457
467
|
} finally {
|
|
458
468
|
this._raceAgainstEvaluationStallingEventsPromises.delete(promise);
|
|
459
469
|
}
|
|
@@ -461,41 +471,42 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
461
471
|
nonStallingRawEvaluateInExistingMainContext(expression) {
|
|
462
472
|
return this.raceAgainstEvaluationStallingEvents(() => {
|
|
463
473
|
const context = this._existingMainContext();
|
|
464
|
-
if (!context)
|
|
474
|
+
if (!context)
|
|
475
|
+
throw new Error("Frame does not yet have a main execution context");
|
|
465
476
|
return context.rawEvaluateJSON(expression);
|
|
466
477
|
});
|
|
467
478
|
}
|
|
468
479
|
nonStallingEvaluateInExistingContext(expression, world) {
|
|
469
480
|
return this.raceAgainstEvaluationStallingEvents(() => {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
return context.evaluateExpression(expression, {
|
|
474
|
-
isFunction: false
|
|
475
|
-
});
|
|
481
|
+
const context = this._contextData.get(world)?.context;
|
|
482
|
+
if (!context)
|
|
483
|
+
throw new Error("Frame does not yet have the execution context");
|
|
484
|
+
return context.evaluateExpression(expression, { isFunction: false });
|
|
476
485
|
});
|
|
477
486
|
}
|
|
478
487
|
_recalculateNetworkIdle(frameThatAllowsRemovingNetworkIdle) {
|
|
479
488
|
let isNetworkIdle = this._firedNetworkIdleSelf;
|
|
480
489
|
for (const child of this._childFrames) {
|
|
481
490
|
child._recalculateNetworkIdle(frameThatAllowsRemovingNetworkIdle);
|
|
482
|
-
|
|
483
|
-
|
|
491
|
+
if (!child._firedLifecycleEvents.has("networkidle"))
|
|
492
|
+
isNetworkIdle = false;
|
|
484
493
|
}
|
|
485
|
-
if (isNetworkIdle && !this._firedLifecycleEvents.has(
|
|
486
|
-
this._firedLifecycleEvents.add(
|
|
487
|
-
this.emit(Frame.Events.AddLifecycle,
|
|
488
|
-
if (this === this._page.mainFrame() && this._url !==
|
|
494
|
+
if (isNetworkIdle && !this._firedLifecycleEvents.has("networkidle")) {
|
|
495
|
+
this._firedLifecycleEvents.add("networkidle");
|
|
496
|
+
this.emit(Frame.Events.AddLifecycle, "networkidle");
|
|
497
|
+
if (this === this._page.mainFrame() && this._url !== "about:blank")
|
|
498
|
+
import_debugLogger.debugLogger.log("api", ` "networkidle" event fired`);
|
|
489
499
|
}
|
|
490
|
-
if (frameThatAllowsRemovingNetworkIdle !== this && this._firedLifecycleEvents.has(
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
this._firedLifecycleEvents.delete('networkidle');
|
|
494
|
-
this.emit(Frame.Events.RemoveLifecycle, 'networkidle');
|
|
500
|
+
if (frameThatAllowsRemovingNetworkIdle !== this && this._firedLifecycleEvents.has("networkidle") && !isNetworkIdle) {
|
|
501
|
+
this._firedLifecycleEvents.delete("networkidle");
|
|
502
|
+
this.emit(Frame.Events.RemoveLifecycle, "networkidle");
|
|
495
503
|
}
|
|
496
504
|
}
|
|
497
505
|
async raceNavigationAction(progress, options, action) {
|
|
498
|
-
return
|
|
506
|
+
return import_utils.LongStandingScope.raceMultiple([
|
|
507
|
+
this._detachedScope,
|
|
508
|
+
this._page.openScope
|
|
509
|
+
], action().catch((e) => {
|
|
499
510
|
if (e instanceof NavigationAbortedError && e.documentId) {
|
|
500
511
|
const data = this._redirectedNavigations.get(e.documentId);
|
|
501
512
|
if (data) {
|
|
@@ -507,91 +518,100 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
507
518
|
}));
|
|
508
519
|
}
|
|
509
520
|
redirectNavigation(url, documentId, referer) {
|
|
510
|
-
const controller = new
|
|
521
|
+
const controller = new import_progress.ProgressController((0, import_instrumentation.serverSideCallMetadata)(), this);
|
|
511
522
|
const data = {
|
|
512
523
|
url,
|
|
513
|
-
gotoPromise: controller.run(progress => this._gotoAction(progress, url, {
|
|
514
|
-
referer
|
|
515
|
-
}), 0)
|
|
524
|
+
gotoPromise: controller.run((progress) => this._gotoAction(progress, url, { referer }), 0)
|
|
516
525
|
};
|
|
517
526
|
this._redirectedNavigations.set(documentId, data);
|
|
518
527
|
data.gotoPromise.finally(() => this._redirectedNavigations.delete(documentId));
|
|
519
528
|
}
|
|
520
529
|
async goto(metadata, url, options = {}) {
|
|
521
|
-
const constructedNavigationURL = (0,
|
|
522
|
-
const controller = new
|
|
523
|
-
return controller.run(progress => this._goto(progress, constructedNavigationURL, options), this._page._timeoutSettings.navigationTimeout(options));
|
|
530
|
+
const constructedNavigationURL = (0, import_utils.constructURLBasedOnBaseURL)(this._page._browserContext._options.baseURL, url);
|
|
531
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
532
|
+
return controller.run((progress) => this._goto(progress, constructedNavigationURL, options), this._page._timeoutSettings.navigationTimeout(options));
|
|
524
533
|
}
|
|
525
534
|
async _goto(progress, url, options) {
|
|
526
535
|
return this.raceNavigationAction(progress, options, async () => this._gotoAction(progress, url, options));
|
|
527
536
|
}
|
|
528
537
|
async _gotoAction(progress, url, options) {
|
|
529
|
-
const waitUntil = verifyLifecycle(
|
|
538
|
+
const waitUntil = verifyLifecycle("waitUntil", options.waitUntil === void 0 ? "load" : options.waitUntil);
|
|
530
539
|
progress.log(`navigating to "${url}", waiting until "${waitUntil}"`);
|
|
531
540
|
const headers = this._page.extraHTTPHeaders() || [];
|
|
532
|
-
const refererHeader = headers.find(h => h.name.toLowerCase() ===
|
|
533
|
-
let referer = refererHeader ? refererHeader.value :
|
|
534
|
-
if (options.referer !==
|
|
535
|
-
if (referer !==
|
|
541
|
+
const refererHeader = headers.find((h) => h.name.toLowerCase() === "referer");
|
|
542
|
+
let referer = refererHeader ? refererHeader.value : void 0;
|
|
543
|
+
if (options.referer !== void 0) {
|
|
544
|
+
if (referer !== void 0 && referer !== options.referer)
|
|
545
|
+
throw new Error('"referer" is already specified as extra HTTP header');
|
|
536
546
|
referer = options.referer;
|
|
537
547
|
}
|
|
538
|
-
url =
|
|
548
|
+
url = import_helper.helper.completeUserURL(url);
|
|
539
549
|
const navigationEvents = [];
|
|
540
|
-
const collectNavigations = arg => navigationEvents.push(arg);
|
|
550
|
+
const collectNavigations = (arg) => navigationEvents.push(arg);
|
|
541
551
|
this.on(Frame.Events.InternalNavigation, collectNavigations);
|
|
542
|
-
const navigateResult = await this._page._delegate.navigateFrame(this, url, referer).finally(
|
|
552
|
+
const navigateResult = await this._page._delegate.navigateFrame(this, url, referer).finally(
|
|
553
|
+
() => this.off(Frame.Events.InternalNavigation, collectNavigations)
|
|
554
|
+
);
|
|
543
555
|
let event;
|
|
544
556
|
if (navigateResult.newDocumentId) {
|
|
545
|
-
const predicate =
|
|
546
|
-
|
|
547
|
-
// did commit and replaced the expected document.
|
|
548
|
-
return event.newDocument && (event.newDocument.documentId === navigateResult.newDocumentId || !event.error);
|
|
557
|
+
const predicate = (event2) => {
|
|
558
|
+
return event2.newDocument && (event2.newDocument.documentId === navigateResult.newDocumentId || !event2.error);
|
|
549
559
|
};
|
|
550
560
|
const events = navigationEvents.filter(predicate);
|
|
551
|
-
if (events.length)
|
|
561
|
+
if (events.length)
|
|
562
|
+
event = events[0];
|
|
563
|
+
else
|
|
564
|
+
event = await import_helper.helper.waitForEvent(progress, this, Frame.Events.InternalNavigation, predicate).promise;
|
|
552
565
|
if (event.newDocument.documentId !== navigateResult.newDocumentId) {
|
|
553
|
-
// This is just a sanity check. In practice, new navigation should
|
|
554
|
-
// cancel the previous one and report "request cancelled"-like error.
|
|
555
566
|
throw new NavigationAbortedError(navigateResult.newDocumentId, `Navigation to "${url}" is interrupted by another navigation to "${event.url}"`);
|
|
556
567
|
}
|
|
557
|
-
if (event.error)
|
|
568
|
+
if (event.error)
|
|
569
|
+
throw event.error;
|
|
558
570
|
} else {
|
|
559
|
-
|
|
560
|
-
const predicate = e => !e.newDocument;
|
|
571
|
+
const predicate = (e) => !e.newDocument;
|
|
561
572
|
const events = navigationEvents.filter(predicate);
|
|
562
|
-
if (events.length)
|
|
573
|
+
if (events.length)
|
|
574
|
+
event = events[0];
|
|
575
|
+
else
|
|
576
|
+
event = await import_helper.helper.waitForEvent(progress, this, Frame.Events.InternalNavigation, predicate).promise;
|
|
563
577
|
}
|
|
564
|
-
if (!this._firedLifecycleEvents.has(waitUntil))
|
|
565
|
-
|
|
578
|
+
if (!this._firedLifecycleEvents.has(waitUntil))
|
|
579
|
+
await import_helper.helper.waitForEvent(progress, this, Frame.Events.AddLifecycle, (e) => e === waitUntil).promise;
|
|
580
|
+
const request = event.newDocument ? event.newDocument.request : void 0;
|
|
566
581
|
const response = request ? request._finalRequest().response() : null;
|
|
567
582
|
return response;
|
|
568
583
|
}
|
|
569
584
|
async _waitForNavigation(progress, requiresNewDocument, options) {
|
|
570
|
-
const waitUntil = verifyLifecycle(
|
|
585
|
+
const waitUntil = verifyLifecycle("waitUntil", options.waitUntil === void 0 ? "load" : options.waitUntil);
|
|
571
586
|
progress.log(`waiting for navigation until "${waitUntil}"`);
|
|
572
|
-
const navigationEvent = await
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
if (requiresNewDocument && !event.newDocument)
|
|
587
|
+
const navigationEvent = await import_helper.helper.waitForEvent(progress, this, Frame.Events.InternalNavigation, (event) => {
|
|
588
|
+
if (event.error)
|
|
589
|
+
return true;
|
|
590
|
+
if (requiresNewDocument && !event.newDocument)
|
|
591
|
+
return false;
|
|
576
592
|
progress.log(` navigated to "${this._url}"`);
|
|
577
593
|
return true;
|
|
578
594
|
}).promise;
|
|
579
|
-
if (navigationEvent.error)
|
|
580
|
-
|
|
581
|
-
|
|
595
|
+
if (navigationEvent.error)
|
|
596
|
+
throw navigationEvent.error;
|
|
597
|
+
if (!this._firedLifecycleEvents.has(waitUntil))
|
|
598
|
+
await import_helper.helper.waitForEvent(progress, this, Frame.Events.AddLifecycle, (e) => e === waitUntil).promise;
|
|
599
|
+
const request = navigationEvent.newDocument ? navigationEvent.newDocument.request : void 0;
|
|
582
600
|
return request ? request._finalRequest().response() : null;
|
|
583
601
|
}
|
|
584
602
|
async _waitForLoadState(progress, state) {
|
|
585
|
-
const waitUntil = verifyLifecycle(
|
|
586
|
-
if (!this._firedLifecycleEvents.has(waitUntil))
|
|
603
|
+
const waitUntil = verifyLifecycle("state", state);
|
|
604
|
+
if (!this._firedLifecycleEvents.has(waitUntil))
|
|
605
|
+
await import_helper.helper.waitForEvent(progress, this, Frame.Events.AddLifecycle, (e) => e === waitUntil).promise;
|
|
587
606
|
}
|
|
588
607
|
async frameElement() {
|
|
589
608
|
return this._page._delegate.getFrameElement(this);
|
|
590
609
|
}
|
|
591
610
|
_context(world, useContextPromise = false) {
|
|
592
|
-
if (process.env[
|
|
593
|
-
return this._contextData.get(world).contextPromise.then(contextOrDestroyedReason => {
|
|
594
|
-
if (contextOrDestroyedReason instanceof js.ExecutionContext)
|
|
611
|
+
if (process.env["REBROWSER_PATCHES_RUNTIME_FIX_MODE"] === "0" || this._contextData.get(world).context || useContextPromise) {
|
|
612
|
+
return this._contextData.get(world).contextPromise.then((contextOrDestroyedReason) => {
|
|
613
|
+
if (contextOrDestroyedReason instanceof js.ExecutionContext)
|
|
614
|
+
return contextOrDestroyedReason;
|
|
595
615
|
throw new Error(contextOrDestroyedReason.destroyedReason);
|
|
596
616
|
});
|
|
597
617
|
}
|
|
@@ -602,109 +622,85 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
602
622
|
frame: this
|
|
603
623
|
}).then(() => {
|
|
604
624
|
return this._context(world, true);
|
|
605
|
-
}).catch(error => {
|
|
606
|
-
if (error.message.includes(
|
|
607
|
-
// ignore, frame is already gone
|
|
625
|
+
}).catch((error) => {
|
|
626
|
+
if (error.message.includes("No frame for given id found")) {
|
|
608
627
|
return {
|
|
609
|
-
destroyedReason:
|
|
628
|
+
destroyedReason: "Frame was detached"
|
|
610
629
|
};
|
|
611
630
|
}
|
|
612
|
-
|
|
613
|
-
console.error(
|
|
631
|
+
import_debugLogger.debugLogger.log("error", error);
|
|
632
|
+
console.error("[rebrowser-patches][frames._context] cannot get world, error:", error);
|
|
614
633
|
});
|
|
615
634
|
}
|
|
616
635
|
_mainContext() {
|
|
617
|
-
return this._context(
|
|
636
|
+
return this._context("main");
|
|
618
637
|
}
|
|
619
638
|
_existingMainContext() {
|
|
620
|
-
|
|
621
|
-
return ((_this$_contextData$ge2 = this._contextData.get('main')) === null || _this$_contextData$ge2 === void 0 ? void 0 : _this$_contextData$ge2.context) || null;
|
|
639
|
+
return this._contextData.get("main")?.context || null;
|
|
622
640
|
}
|
|
623
641
|
_utilityContext() {
|
|
624
|
-
return this._context(
|
|
642
|
+
return this._context("utility");
|
|
625
643
|
}
|
|
626
644
|
async evaluateExpression(expression, options = {}, arg) {
|
|
627
|
-
|
|
628
|
-
const context = await this._context((_options$world = options.world) !== null && _options$world !== void 0 ? _options$world : 'main');
|
|
645
|
+
const context = await this._context(options.world ?? "main");
|
|
629
646
|
const value = await context.evaluateExpression(expression, options, arg);
|
|
630
647
|
return value;
|
|
631
648
|
}
|
|
632
649
|
async evaluateExpressionHandle(expression, options = {}, arg) {
|
|
633
|
-
|
|
634
|
-
const context = await this._context((_options$world2 = options.world) !== null && _options$world2 !== void 0 ? _options$world2 : 'main');
|
|
650
|
+
const context = await this._context(options.world ?? "main");
|
|
635
651
|
const value = await context.evaluateExpressionHandle(expression, options, arg);
|
|
636
652
|
return value;
|
|
637
653
|
}
|
|
638
654
|
async querySelector(selector, options) {
|
|
639
|
-
|
|
655
|
+
import_debugLogger.debugLogger.log("api", ` finding element using the selector "${selector}"`);
|
|
640
656
|
return this.selectors.query(selector, options);
|
|
641
657
|
}
|
|
642
658
|
async waitForSelector(metadata, selector, options, scope) {
|
|
643
|
-
const controller = new
|
|
644
|
-
if (options.visibility)
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
} = options;
|
|
649
|
-
if (![
|
|
650
|
-
|
|
651
|
-
|
|
659
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
660
|
+
if (options.visibility)
|
|
661
|
+
throw new Error("options.visibility is not supported, did you mean options.state?");
|
|
662
|
+
if (options.waitFor && options.waitFor !== "visible")
|
|
663
|
+
throw new Error("options.waitFor is not supported, did you mean options.state?");
|
|
664
|
+
const { state = "visible" } = options;
|
|
665
|
+
if (!["attached", "detached", "visible", "hidden"].includes(state))
|
|
666
|
+
throw new Error(`state: expected one of (attached|detached|visible|hidden)`);
|
|
667
|
+
return controller.run(async (progress) => {
|
|
668
|
+
progress.log(`waiting for ${this._asLocator(selector)}${state === "attached" ? "" : " to be " + state}`);
|
|
652
669
|
return await this.waitForSelectorInternal(progress, selector, true, options, scope);
|
|
653
670
|
}, this._page._timeoutSettings.timeout(options));
|
|
654
671
|
}
|
|
655
672
|
async waitForSelectorInternal(progress, selector, performActionPreChecks, options, scope) {
|
|
656
|
-
const {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
if (performActionPreChecks) await this._page.performActionPreChecks(progress);
|
|
673
|
+
const { state = "visible" } = options;
|
|
674
|
+
const promise = this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async (continuePolling) => {
|
|
675
|
+
if (performActionPreChecks)
|
|
676
|
+
await this._page.performActionPreChecks(progress);
|
|
661
677
|
const resolved = await this.selectors.resolveInjectedForSelector(selector, options, scope);
|
|
662
678
|
progress.throwIfAborted();
|
|
663
679
|
if (!resolved) {
|
|
664
|
-
if (state ===
|
|
680
|
+
if (state === "hidden" || state === "detached")
|
|
681
|
+
return null;
|
|
665
682
|
return continuePolling;
|
|
666
683
|
}
|
|
667
|
-
const result = await resolved.injected.evaluateHandle((injected, {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
}) => {
|
|
671
|
-
if (root && !root.isConnected) throw injected.createStacklessError('Element is not attached to the DOM');
|
|
684
|
+
const result = await resolved.injected.evaluateHandle((injected, { info, root }) => {
|
|
685
|
+
if (root && !root.isConnected)
|
|
686
|
+
throw injected.createStacklessError("Element is not attached to the DOM");
|
|
672
687
|
const elements = injected.querySelectorAll(info.parsed, root || document);
|
|
673
|
-
const
|
|
674
|
-
const
|
|
675
|
-
let
|
|
688
|
+
const element2 = elements[0];
|
|
689
|
+
const visible2 = element2 ? injected.utils.isElementVisible(element2) : false;
|
|
690
|
+
let log2 = "";
|
|
676
691
|
if (elements.length > 1) {
|
|
677
|
-
if (info.strict)
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
692
|
+
if (info.strict)
|
|
693
|
+
throw injected.strictModeViolationError(info.parsed, elements);
|
|
694
|
+
log2 = ` locator resolved to ${elements.length} elements. Proceeding with the first one: ${injected.previewNode(elements[0])}`;
|
|
695
|
+
} else if (element2) {
|
|
696
|
+
log2 = ` locator resolved to ${visible2 ? "visible" : "hidden"} ${injected.previewNode(element2)}`;
|
|
681
697
|
}
|
|
682
|
-
return {
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
}, {
|
|
689
|
-
info: resolved.info,
|
|
690
|
-
root: resolved.frame === this ? scope : undefined
|
|
691
|
-
});
|
|
692
|
-
const {
|
|
693
|
-
log,
|
|
694
|
-
visible,
|
|
695
|
-
attached
|
|
696
|
-
} = await result.evaluate(r => ({
|
|
697
|
-
log: r.log,
|
|
698
|
-
visible: r.visible,
|
|
699
|
-
attached: r.attached
|
|
700
|
-
}));
|
|
701
|
-
if (log) progress.log(log);
|
|
702
|
-
const success = {
|
|
703
|
-
attached,
|
|
704
|
-
detached: !attached,
|
|
705
|
-
visible,
|
|
706
|
-
hidden: !visible
|
|
707
|
-
}[state];
|
|
698
|
+
return { log: log2, element: element2, visible: visible2, attached: !!element2 };
|
|
699
|
+
}, { info: resolved.info, root: resolved.frame === this ? scope : void 0 });
|
|
700
|
+
const { log, visible, attached } = await result.evaluate((r) => ({ log: r.log, visible: r.visible, attached: r.attached }));
|
|
701
|
+
if (log)
|
|
702
|
+
progress.log(log);
|
|
703
|
+
const success = { attached, detached: !attached, visible, hidden: !visible }[state];
|
|
708
704
|
if (!success) {
|
|
709
705
|
result.dispose();
|
|
710
706
|
return continuePolling;
|
|
@@ -713,10 +709,12 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
713
709
|
result.dispose();
|
|
714
710
|
return null;
|
|
715
711
|
}
|
|
716
|
-
const element = state ===
|
|
712
|
+
const element = state === "attached" || state === "visible" ? await result.evaluateHandle((r) => r.element) : null;
|
|
717
713
|
result.dispose();
|
|
718
|
-
if (!element)
|
|
719
|
-
|
|
714
|
+
if (!element)
|
|
715
|
+
return null;
|
|
716
|
+
if (options.__testHookBeforeAdoptNode)
|
|
717
|
+
await options.__testHookBeforeAdoptNode();
|
|
720
718
|
try {
|
|
721
719
|
return await element._adoptTo(await resolved.frame._mainContext());
|
|
722
720
|
} catch (e) {
|
|
@@ -728,45 +726,28 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
728
726
|
async dispatchEvent(metadata, selector, type, eventInit = {}, options = {}, scope) {
|
|
729
727
|
await this._callOnElementOnceMatches(metadata, selector, (injectedScript, element, data) => {
|
|
730
728
|
injectedScript.dispatchEvent(element, data.type, data.eventInit);
|
|
731
|
-
}, {
|
|
732
|
-
type,
|
|
733
|
-
eventInit
|
|
734
|
-
}, {
|
|
735
|
-
mainWorld: true,
|
|
736
|
-
...options
|
|
737
|
-
}, scope);
|
|
729
|
+
}, { type, eventInit }, { mainWorld: true, ...options }, scope);
|
|
738
730
|
}
|
|
739
731
|
async evalOnSelector(selector, strict, expression, isFunction, arg, scope) {
|
|
740
|
-
const handle = await this.selectors.query(selector, {
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
const result = await handle.evaluateExpression(expression, {
|
|
745
|
-
isFunction
|
|
746
|
-
}, arg);
|
|
732
|
+
const handle = await this.selectors.query(selector, { strict }, scope);
|
|
733
|
+
if (!handle)
|
|
734
|
+
throw new Error(`Failed to find element matching selector "${selector}"`);
|
|
735
|
+
const result = await handle.evaluateExpression(expression, { isFunction }, arg);
|
|
747
736
|
handle.dispose();
|
|
748
737
|
return result;
|
|
749
738
|
}
|
|
750
739
|
async evalOnSelectorAll(selector, expression, isFunction, arg, scope) {
|
|
751
740
|
const arrayHandle = await this.selectors.queryArrayInMainWorld(selector, scope);
|
|
752
|
-
const result = await arrayHandle.evaluateExpression(expression, {
|
|
753
|
-
isFunction
|
|
754
|
-
}, arg);
|
|
741
|
+
const result = await arrayHandle.evaluateExpression(expression, { isFunction }, arg);
|
|
755
742
|
arrayHandle.dispose();
|
|
756
743
|
return result;
|
|
757
744
|
}
|
|
758
745
|
async maskSelectors(selectors, color) {
|
|
759
746
|
const context = await this._utilityContext();
|
|
760
747
|
const injectedScript = await context.injectedScript();
|
|
761
|
-
await injectedScript.evaluate((injected, {
|
|
762
|
-
parsed,
|
|
763
|
-
|
|
764
|
-
}) => {
|
|
765
|
-
injected.maskSelectors(parsed, color);
|
|
766
|
-
}, {
|
|
767
|
-
parsed: selectors,
|
|
768
|
-
color: color
|
|
769
|
-
});
|
|
748
|
+
await injectedScript.evaluate((injected, { parsed, color: color2 }) => {
|
|
749
|
+
injected.maskSelectors(parsed, color2);
|
|
750
|
+
}, { parsed: selectors, color });
|
|
770
751
|
}
|
|
771
752
|
async querySelectorAll(selector) {
|
|
772
753
|
return this.selectors.queryAll(selector);
|
|
@@ -778,58 +759,54 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
778
759
|
try {
|
|
779
760
|
const context = await this._utilityContext();
|
|
780
761
|
return await context.evaluate(() => {
|
|
781
|
-
let retVal =
|
|
782
|
-
if (document.doctype)
|
|
783
|
-
|
|
762
|
+
let retVal = "";
|
|
763
|
+
if (document.doctype)
|
|
764
|
+
retVal = new XMLSerializer().serializeToString(document.doctype);
|
|
765
|
+
if (document.documentElement)
|
|
766
|
+
retVal += document.documentElement.outerHTML;
|
|
784
767
|
return retVal;
|
|
785
768
|
});
|
|
786
769
|
} catch (e) {
|
|
787
|
-
if (js.isJavaScriptErrorInEvaluate(e) || (0,
|
|
770
|
+
if (js.isJavaScriptErrorInEvaluate(e) || (0, import_protocolError.isSessionClosedError)(e))
|
|
771
|
+
throw e;
|
|
788
772
|
throw new Error(`Unable to retrieve content because the page is navigating and changing the content.`);
|
|
789
773
|
}
|
|
790
774
|
}
|
|
791
775
|
async setContent(metadata, html, options = {}) {
|
|
792
|
-
const controller = new
|
|
793
|
-
return controller.run(async progress => {
|
|
776
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
777
|
+
return controller.run(async (progress) => {
|
|
794
778
|
await this.raceNavigationAction(progress, options, async () => {
|
|
795
|
-
const waitUntil = options.waitUntil ===
|
|
779
|
+
const waitUntil = options.waitUntil === void 0 ? "load" : options.waitUntil;
|
|
796
780
|
progress.log(`setting frame content, waiting until "${waitUntil}"`);
|
|
797
781
|
const tag = `--playwright--set--content--${this._id}--${++this._setContentCounter}--`;
|
|
798
782
|
const context = await this._utilityContext();
|
|
799
783
|
const lifecyclePromise = new Promise((resolve, reject) => {
|
|
800
784
|
this._page._frameManager._consoleMessageTags.set(tag, () => {
|
|
801
|
-
// Clear lifecycle right after document.open() - see 'tag' below.
|
|
802
785
|
this._onClearLifecycle();
|
|
803
786
|
this._waitForLoadState(progress, waitUntil).then(resolve).catch(reject);
|
|
804
787
|
});
|
|
805
788
|
});
|
|
806
|
-
const contentPromise = context.evaluate(({
|
|
807
|
-
html,
|
|
808
|
-
tag
|
|
809
|
-
}) => {
|
|
789
|
+
const contentPromise = context.evaluate(({ html: html2, tag: tag2 }) => {
|
|
810
790
|
document.open();
|
|
811
|
-
console.debug(
|
|
812
|
-
document.write(
|
|
791
|
+
console.debug(tag2);
|
|
792
|
+
document.write(html2);
|
|
813
793
|
document.close();
|
|
814
|
-
}, {
|
|
815
|
-
html,
|
|
816
|
-
tag
|
|
817
|
-
});
|
|
794
|
+
}, { html, tag });
|
|
818
795
|
await Promise.all([contentPromise, lifecyclePromise]);
|
|
819
796
|
return null;
|
|
820
797
|
});
|
|
821
798
|
}, this._page._timeoutSettings.navigationTimeout(options));
|
|
822
799
|
}
|
|
823
800
|
name() {
|
|
824
|
-
return this._name ||
|
|
801
|
+
return this._name || "";
|
|
825
802
|
}
|
|
826
803
|
url() {
|
|
827
804
|
return this._url;
|
|
828
805
|
}
|
|
829
806
|
origin() {
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
return
|
|
807
|
+
if (!this._url.startsWith("http"))
|
|
808
|
+
return;
|
|
809
|
+
return network.parseURL(this._url)?.origin;
|
|
833
810
|
}
|
|
834
811
|
parentFrame() {
|
|
835
812
|
return this._parentFrame;
|
|
@@ -841,44 +818,41 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
841
818
|
const {
|
|
842
819
|
url = null,
|
|
843
820
|
content = null,
|
|
844
|
-
type =
|
|
821
|
+
type = ""
|
|
845
822
|
} = params;
|
|
846
|
-
if (!url && !content)
|
|
823
|
+
if (!url && !content)
|
|
824
|
+
throw new Error("Provide an object with a `url`, `path` or `content` property");
|
|
847
825
|
const context = await this._mainContext();
|
|
848
826
|
return this._raceWithCSPError(async () => {
|
|
849
|
-
if (url !== null)
|
|
850
|
-
url,
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
content: content,
|
|
855
|
-
type
|
|
856
|
-
})).asElement();
|
|
857
|
-
// Another round trip to the browser to ensure that we receive CSP error messages
|
|
858
|
-
// (if any) logged asynchronously in a separate task on the content main thread.
|
|
859
|
-
if (this._page._delegate.cspErrorsAsynchronousForInlineScripts) await context.evaluate(() => true);
|
|
827
|
+
if (url !== null)
|
|
828
|
+
return (await context.evaluateHandle(addScriptUrl, { url, type })).asElement();
|
|
829
|
+
const result = (await context.evaluateHandle(addScriptContent, { content, type })).asElement();
|
|
830
|
+
if (this._page._delegate.cspErrorsAsynchronousForInlineScripts)
|
|
831
|
+
await context.evaluate(() => true);
|
|
860
832
|
return result;
|
|
861
833
|
});
|
|
862
|
-
async function addScriptUrl(
|
|
863
|
-
const script = document.createElement(
|
|
864
|
-
script.src =
|
|
865
|
-
if (
|
|
834
|
+
async function addScriptUrl(params2) {
|
|
835
|
+
const script = document.createElement("script");
|
|
836
|
+
script.src = params2.url;
|
|
837
|
+
if (params2.type)
|
|
838
|
+
script.type = params2.type;
|
|
866
839
|
const promise = new Promise((res, rej) => {
|
|
867
840
|
script.onload = res;
|
|
868
|
-
script.onerror = e => rej(typeof e ===
|
|
841
|
+
script.onerror = (e) => rej(typeof e === "string" ? new Error(e) : new Error(`Failed to load script at ${script.src}`));
|
|
869
842
|
});
|
|
870
843
|
document.head.appendChild(script);
|
|
871
844
|
await promise;
|
|
872
845
|
return script;
|
|
873
846
|
}
|
|
874
|
-
function addScriptContent(
|
|
875
|
-
const script = document.createElement(
|
|
876
|
-
script.type =
|
|
877
|
-
script.text =
|
|
847
|
+
function addScriptContent(params2) {
|
|
848
|
+
const script = document.createElement("script");
|
|
849
|
+
script.type = params2.type || "text/javascript";
|
|
850
|
+
script.text = params2.content;
|
|
878
851
|
let error = null;
|
|
879
|
-
script.onerror = e => error = e;
|
|
852
|
+
script.onerror = (e) => error = e;
|
|
880
853
|
document.head.appendChild(script);
|
|
881
|
-
if (error)
|
|
854
|
+
if (error)
|
|
855
|
+
throw error;
|
|
882
856
|
return script;
|
|
883
857
|
}
|
|
884
858
|
}
|
|
@@ -887,16 +861,18 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
887
861
|
url = null,
|
|
888
862
|
content = null
|
|
889
863
|
} = params;
|
|
890
|
-
if (!url && !content)
|
|
864
|
+
if (!url && !content)
|
|
865
|
+
throw new Error("Provide an object with a `url`, `path` or `content` property");
|
|
891
866
|
const context = await this._mainContext();
|
|
892
867
|
return this._raceWithCSPError(async () => {
|
|
893
|
-
if (url !== null)
|
|
868
|
+
if (url !== null)
|
|
869
|
+
return (await context.evaluateHandle(addStyleUrl, url)).asElement();
|
|
894
870
|
return (await context.evaluateHandle(addStyleContent, content)).asElement();
|
|
895
871
|
});
|
|
896
|
-
async function addStyleUrl(
|
|
897
|
-
const link = document.createElement(
|
|
898
|
-
link.rel =
|
|
899
|
-
link.href =
|
|
872
|
+
async function addStyleUrl(url2) {
|
|
873
|
+
const link = document.createElement("link");
|
|
874
|
+
link.rel = "stylesheet";
|
|
875
|
+
link.href = url2;
|
|
900
876
|
const promise = new Promise((res, rej) => {
|
|
901
877
|
link.onload = res;
|
|
902
878
|
link.onerror = rej;
|
|
@@ -905,10 +881,10 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
905
881
|
await promise;
|
|
906
882
|
return link;
|
|
907
883
|
}
|
|
908
|
-
async function addStyleContent(
|
|
909
|
-
const style = document.createElement(
|
|
910
|
-
style.type =
|
|
911
|
-
style.appendChild(document.createTextNode(
|
|
884
|
+
async function addStyleContent(content2) {
|
|
885
|
+
const style = document.createElement("style");
|
|
886
|
+
style.type = "text/css";
|
|
887
|
+
style.appendChild(document.createTextNode(content2));
|
|
912
888
|
const promise = new Promise((res, rej) => {
|
|
913
889
|
style.onload = res;
|
|
914
890
|
style.onerror = rej;
|
|
@@ -923,158 +899,146 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
923
899
|
let result;
|
|
924
900
|
let error;
|
|
925
901
|
let cspMessage;
|
|
926
|
-
const actionPromise = func().then(r => result = r).catch(e => error = e);
|
|
927
|
-
const errorPromise = new Promise(resolve => {
|
|
928
|
-
listeners.push(
|
|
929
|
-
if (message.page() !== this._page || message.type() !==
|
|
930
|
-
|
|
902
|
+
const actionPromise = func().then((r) => result = r).catch((e) => error = e);
|
|
903
|
+
const errorPromise = new Promise((resolve) => {
|
|
904
|
+
listeners.push(import_eventsHelper.eventsHelper.addEventListener(this._page._browserContext, import_browserContext.BrowserContext.Events.Console, (message) => {
|
|
905
|
+
if (message.page() !== this._page || message.type() !== "error")
|
|
906
|
+
return;
|
|
907
|
+
if (message.text().includes("Content-Security-Policy") || message.text().includes("Content Security Policy")) {
|
|
931
908
|
cspMessage = message;
|
|
932
909
|
resolve();
|
|
933
910
|
}
|
|
934
911
|
}));
|
|
935
912
|
});
|
|
936
913
|
await Promise.race([actionPromise, errorPromise]);
|
|
937
|
-
|
|
938
|
-
if (cspMessage)
|
|
939
|
-
|
|
914
|
+
import_eventsHelper.eventsHelper.removeEventListeners(listeners);
|
|
915
|
+
if (cspMessage)
|
|
916
|
+
throw new Error(cspMessage.text());
|
|
917
|
+
if (error)
|
|
918
|
+
throw error;
|
|
940
919
|
return result;
|
|
941
920
|
}
|
|
942
921
|
async retryWithProgressAndTimeouts(progress, timeouts, action) {
|
|
943
|
-
const continuePolling = Symbol(
|
|
922
|
+
const continuePolling = Symbol("continuePolling");
|
|
944
923
|
timeouts = [0, ...timeouts];
|
|
945
924
|
let timeoutIndex = 0;
|
|
946
925
|
while (progress.isRunning()) {
|
|
947
926
|
const timeout = timeouts[Math.min(timeoutIndex++, timeouts.length - 1)];
|
|
948
927
|
if (timeout) {
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
928
|
+
const actionPromise = new Promise((f) => setTimeout(f, timeout));
|
|
929
|
+
await import_utils.LongStandingScope.raceMultiple([
|
|
930
|
+
this._page.openScope,
|
|
931
|
+
this._detachedScope
|
|
932
|
+
], actionPromise);
|
|
953
933
|
}
|
|
954
934
|
progress.throwIfAborted();
|
|
955
935
|
try {
|
|
956
936
|
const result = await action(continuePolling);
|
|
957
|
-
if (result === continuePolling)
|
|
937
|
+
if (result === continuePolling)
|
|
938
|
+
continue;
|
|
958
939
|
return result;
|
|
959
940
|
} catch (e) {
|
|
960
|
-
if (this._isErrorThatCannotBeRetried(e))
|
|
941
|
+
if (this._isErrorThatCannotBeRetried(e))
|
|
942
|
+
throw e;
|
|
961
943
|
continue;
|
|
962
944
|
}
|
|
963
945
|
}
|
|
964
946
|
progress.throwIfAborted();
|
|
965
|
-
return
|
|
947
|
+
return void 0;
|
|
966
948
|
}
|
|
967
949
|
_isErrorThatCannotBeRetried(e) {
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
// Retry upon all other errors.
|
|
950
|
+
if (js.isJavaScriptErrorInEvaluate(e) || (0, import_protocolError.isSessionClosedError)(e))
|
|
951
|
+
return true;
|
|
952
|
+
if (dom.isNonRecoverableDOMError(e) || (0, import_selectorParser.isInvalidSelectorError)(e))
|
|
953
|
+
return true;
|
|
954
|
+
if (this.isDetached())
|
|
955
|
+
return true;
|
|
975
956
|
return false;
|
|
976
957
|
}
|
|
977
958
|
async _retryWithProgressIfNotConnected(progress, selector, strict, performActionPreChecks, action) {
|
|
978
959
|
progress.log(`waiting for ${this._asLocator(selector)}`);
|
|
979
|
-
return this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async continuePolling => {
|
|
980
|
-
if (performActionPreChecks)
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
});
|
|
960
|
+
return this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async (continuePolling) => {
|
|
961
|
+
if (performActionPreChecks)
|
|
962
|
+
await this._page.performActionPreChecks(progress);
|
|
963
|
+
const resolved = await this.selectors.resolveInjectedForSelector(selector, { strict });
|
|
984
964
|
progress.throwIfAborted();
|
|
985
|
-
if (!resolved)
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
callId
|
|
989
|
-
}) => {
|
|
965
|
+
if (!resolved)
|
|
966
|
+
return continuePolling;
|
|
967
|
+
const result = await resolved.injected.evaluateHandle((injected, { info, callId }) => {
|
|
990
968
|
const elements = injected.querySelectorAll(info.parsed, document);
|
|
991
|
-
if (callId)
|
|
992
|
-
|
|
993
|
-
|
|
969
|
+
if (callId)
|
|
970
|
+
injected.markTargetElements(new Set(elements), callId);
|
|
971
|
+
const element2 = elements[0];
|
|
972
|
+
let log2 = "";
|
|
994
973
|
if (elements.length > 1) {
|
|
995
|
-
if (info.strict)
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
974
|
+
if (info.strict)
|
|
975
|
+
throw injected.strictModeViolationError(info.parsed, elements);
|
|
976
|
+
log2 = ` locator resolved to ${elements.length} elements. Proceeding with the first one: ${injected.previewNode(elements[0])}`;
|
|
977
|
+
} else if (element2) {
|
|
978
|
+
log2 = ` locator resolved to ${injected.previewNode(element2)}`;
|
|
999
979
|
}
|
|
1000
|
-
return {
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
}, {
|
|
1006
|
-
info: resolved.info,
|
|
1007
|
-
callId: progress.metadata.id
|
|
1008
|
-
});
|
|
1009
|
-
const {
|
|
1010
|
-
log,
|
|
1011
|
-
success
|
|
1012
|
-
} = await result.evaluate(r => ({
|
|
1013
|
-
log: r.log,
|
|
1014
|
-
success: r.success
|
|
1015
|
-
}));
|
|
1016
|
-
if (log) progress.log(log);
|
|
980
|
+
return { log: log2, success: !!element2, element: element2 };
|
|
981
|
+
}, { info: resolved.info, callId: progress.metadata.id });
|
|
982
|
+
const { log, success } = await result.evaluate((r) => ({ log: r.log, success: r.success }));
|
|
983
|
+
if (log)
|
|
984
|
+
progress.log(log);
|
|
1017
985
|
if (!success) {
|
|
1018
986
|
result.dispose();
|
|
1019
987
|
return continuePolling;
|
|
1020
988
|
}
|
|
1021
|
-
const element = await result.evaluateHandle(r => r.element);
|
|
989
|
+
const element = await result.evaluateHandle((r) => r.element);
|
|
1022
990
|
result.dispose();
|
|
1023
991
|
try {
|
|
1024
|
-
const
|
|
1025
|
-
if (
|
|
1026
|
-
progress.log(
|
|
992
|
+
const result2 = await action(element);
|
|
993
|
+
if (result2 === "error:notconnected") {
|
|
994
|
+
progress.log("element was detached from the DOM, retrying");
|
|
1027
995
|
return continuePolling;
|
|
1028
996
|
}
|
|
1029
|
-
return
|
|
997
|
+
return result2;
|
|
1030
998
|
} finally {
|
|
1031
|
-
element
|
|
999
|
+
element?.dispose();
|
|
1032
1000
|
}
|
|
1033
1001
|
});
|
|
1034
1002
|
}
|
|
1035
1003
|
async rafrafTimeoutScreenshotElementWithProgress(progress, selector, timeout, options) {
|
|
1036
|
-
return await this._retryWithProgressIfNotConnected(progress, selector, true
|
|
1004
|
+
return await this._retryWithProgressIfNotConnected(progress, selector, true, true, async (handle) => {
|
|
1037
1005
|
await handle._frame.rafrafTimeout(timeout);
|
|
1038
1006
|
return await this._page._screenshotter.screenshotElement(progress, handle, options);
|
|
1039
1007
|
});
|
|
1040
1008
|
}
|
|
1041
1009
|
async click(metadata, selector, options) {
|
|
1042
|
-
const controller = new
|
|
1043
|
-
return controller.run(async progress => {
|
|
1044
|
-
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force
|
|
1045
|
-
...options,
|
|
1046
|
-
waitAfter: !options.noWaitAfter
|
|
1047
|
-
})));
|
|
1010
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1011
|
+
return controller.run(async (progress) => {
|
|
1012
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._click(progress, { ...options, waitAfter: !options.noWaitAfter })));
|
|
1048
1013
|
}, this._page._timeoutSettings.timeout(options));
|
|
1049
1014
|
}
|
|
1050
1015
|
async dblclick(metadata, selector, options = {}) {
|
|
1051
|
-
const controller = new
|
|
1052
|
-
return controller.run(async progress => {
|
|
1053
|
-
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force
|
|
1016
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1017
|
+
return controller.run(async (progress) => {
|
|
1018
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._dblclick(progress, options)));
|
|
1054
1019
|
}, this._page._timeoutSettings.timeout(options));
|
|
1055
1020
|
}
|
|
1056
1021
|
async dragAndDrop(metadata, source, target, options = {}) {
|
|
1057
|
-
const controller = new
|
|
1058
|
-
await controller.run(async progress => {
|
|
1059
|
-
dom.assertDone(await this._retryWithProgressIfNotConnected(progress, source, options.strict, !options.force
|
|
1060
|
-
return handle._retryPointerAction(progress,
|
|
1022
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1023
|
+
await controller.run(async (progress) => {
|
|
1024
|
+
dom.assertDone(await this._retryWithProgressIfNotConnected(progress, source, options.strict, !options.force, async (handle) => {
|
|
1025
|
+
return handle._retryPointerAction(progress, "move and down", false, async (point) => {
|
|
1061
1026
|
await this._page.mouse.move(point.x, point.y);
|
|
1062
1027
|
await this._page.mouse.down();
|
|
1063
1028
|
}, {
|
|
1064
1029
|
...options,
|
|
1065
|
-
waitAfter:
|
|
1030
|
+
waitAfter: "disabled",
|
|
1066
1031
|
position: options.sourcePosition,
|
|
1067
1032
|
timeout: progress.timeUntilDeadline()
|
|
1068
1033
|
});
|
|
1069
1034
|
}));
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
return handle._retryPointerAction(progress, 'move and up', false, async point => {
|
|
1035
|
+
dom.assertDone(await this._retryWithProgressIfNotConnected(progress, target, options.strict, false, async (handle) => {
|
|
1036
|
+
return handle._retryPointerAction(progress, "move and up", false, async (point) => {
|
|
1073
1037
|
await this._page.mouse.move(point.x, point.y);
|
|
1074
1038
|
await this._page.mouse.up();
|
|
1075
1039
|
}, {
|
|
1076
1040
|
...options,
|
|
1077
|
-
waitAfter:
|
|
1041
|
+
waitAfter: "disabled",
|
|
1078
1042
|
position: options.targetPosition,
|
|
1079
1043
|
timeout: progress.timeUntilDeadline()
|
|
1080
1044
|
});
|
|
@@ -1082,70 +1046,68 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1082
1046
|
}, this._page._timeoutSettings.timeout(options));
|
|
1083
1047
|
}
|
|
1084
1048
|
async tap(metadata, selector, options) {
|
|
1085
|
-
if (!this._page._browserContext._options.hasTouch)
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1049
|
+
if (!this._page._browserContext._options.hasTouch)
|
|
1050
|
+
throw new Error("The page does not support tap. Use hasTouch context option to enable touch support.");
|
|
1051
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1052
|
+
return controller.run(async (progress) => {
|
|
1053
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._tap(progress, options)));
|
|
1089
1054
|
}, this._page._timeoutSettings.timeout(options));
|
|
1090
1055
|
}
|
|
1091
1056
|
async fill(metadata, selector, value, options) {
|
|
1092
|
-
const controller = new
|
|
1093
|
-
return controller.run(async progress => {
|
|
1094
|
-
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force
|
|
1057
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1058
|
+
return controller.run(async (progress) => {
|
|
1059
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._fill(progress, value, options)));
|
|
1095
1060
|
}, this._page._timeoutSettings.timeout(options));
|
|
1096
1061
|
}
|
|
1097
1062
|
async focus(metadata, selector, options = {}) {
|
|
1098
|
-
const controller = new
|
|
1099
|
-
await controller.run(async progress => {
|
|
1100
|
-
dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true
|
|
1063
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1064
|
+
await controller.run(async (progress) => {
|
|
1065
|
+
dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, (handle) => handle._focus(progress)));
|
|
1101
1066
|
}, this._page._timeoutSettings.timeout(options));
|
|
1102
1067
|
}
|
|
1103
1068
|
async blur(metadata, selector, options = {}) {
|
|
1104
|
-
const controller = new
|
|
1105
|
-
await controller.run(async progress => {
|
|
1106
|
-
dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true
|
|
1069
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1070
|
+
await controller.run(async (progress) => {
|
|
1071
|
+
dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, (handle) => handle._blur(progress)));
|
|
1107
1072
|
}, this._page._timeoutSettings.timeout(options));
|
|
1108
1073
|
}
|
|
1109
1074
|
async textContent(metadata, selector, options = {}, scope) {
|
|
1110
|
-
return this._callOnElementOnceMatches(metadata, selector, (injected, element) => element.textContent,
|
|
1075
|
+
return this._callOnElementOnceMatches(metadata, selector, (injected, element) => element.textContent, void 0, options, scope);
|
|
1111
1076
|
}
|
|
1112
1077
|
async innerText(metadata, selector, options = {}, scope) {
|
|
1113
1078
|
return this._callOnElementOnceMatches(metadata, selector, (injectedScript, element) => {
|
|
1114
|
-
if (element.namespaceURI !==
|
|
1079
|
+
if (element.namespaceURI !== "http://www.w3.org/1999/xhtml")
|
|
1080
|
+
throw injectedScript.createStacklessError("Node is not an HTMLElement");
|
|
1115
1081
|
return element.innerText;
|
|
1116
|
-
},
|
|
1082
|
+
}, void 0, options, scope);
|
|
1117
1083
|
}
|
|
1118
1084
|
async innerHTML(metadata, selector, options = {}, scope) {
|
|
1119
|
-
return this._callOnElementOnceMatches(metadata, selector, (injected, element) => element.innerHTML,
|
|
1085
|
+
return this._callOnElementOnceMatches(metadata, selector, (injected, element) => element.innerHTML, void 0, options, scope);
|
|
1120
1086
|
}
|
|
1121
1087
|
async getAttribute(metadata, selector, name, options = {}, scope) {
|
|
1122
|
-
return this._callOnElementOnceMatches(metadata, selector, (injected, element, data) => element.getAttribute(data.name), {
|
|
1123
|
-
name
|
|
1124
|
-
}, options, scope);
|
|
1088
|
+
return this._callOnElementOnceMatches(metadata, selector, (injected, element, data) => element.getAttribute(data.name), { name }, options, scope);
|
|
1125
1089
|
}
|
|
1126
1090
|
async inputValue(metadata, selector, options = {}, scope) {
|
|
1127
1091
|
return this._callOnElementOnceMatches(metadata, selector, (injectedScript, node) => {
|
|
1128
|
-
const element = injectedScript.retarget(node,
|
|
1129
|
-
if (!element || element.nodeName !==
|
|
1092
|
+
const element = injectedScript.retarget(node, "follow-label");
|
|
1093
|
+
if (!element || element.nodeName !== "INPUT" && element.nodeName !== "TEXTAREA" && element.nodeName !== "SELECT")
|
|
1094
|
+
throw injectedScript.createStacklessError("Node is not an <input>, <textarea> or <select> element");
|
|
1130
1095
|
return element.value;
|
|
1131
|
-
},
|
|
1096
|
+
}, void 0, options, scope);
|
|
1132
1097
|
}
|
|
1133
1098
|
async highlight(selector) {
|
|
1134
1099
|
const resolved = await this.selectors.resolveInjectedForSelector(selector);
|
|
1135
|
-
if (!resolved)
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
}) => {
|
|
1100
|
+
if (!resolved)
|
|
1101
|
+
return;
|
|
1102
|
+
return await resolved.injected.evaluate((injected, { info }) => {
|
|
1139
1103
|
return injected.highlight(info.parsed);
|
|
1140
|
-
}, {
|
|
1141
|
-
info: resolved.info
|
|
1142
|
-
});
|
|
1104
|
+
}, { info: resolved.info });
|
|
1143
1105
|
}
|
|
1144
1106
|
async hideHighlight() {
|
|
1145
1107
|
return this.raceAgainstEvaluationStallingEvents(async () => {
|
|
1146
1108
|
const context = await this._utilityContext();
|
|
1147
1109
|
const injectedScript = await context.injectedScript();
|
|
1148
|
-
return await injectedScript.evaluate(injected => {
|
|
1110
|
+
return await injectedScript.evaluate((injected) => {
|
|
1149
1111
|
return injected.hideHighlight();
|
|
1150
1112
|
});
|
|
1151
1113
|
});
|
|
@@ -1153,14 +1115,14 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1153
1115
|
async _elementState(metadata, selector, state, options = {}, scope) {
|
|
1154
1116
|
const result = await this._callOnElementOnceMatches(metadata, selector, (injected, element, data) => {
|
|
1155
1117
|
return injected.elementState(element, data.state);
|
|
1156
|
-
}, {
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
return
|
|
1118
|
+
}, { state }, options, scope);
|
|
1119
|
+
if (result.received === "error:notconnected")
|
|
1120
|
+
dom.throwElementIsNotAttached();
|
|
1121
|
+
return result.matches;
|
|
1160
1122
|
}
|
|
1161
1123
|
async isVisible(metadata, selector, options = {}, scope) {
|
|
1162
|
-
const controller = new
|
|
1163
|
-
return controller.run(async progress => {
|
|
1124
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1125
|
+
return controller.run(async (progress) => {
|
|
1164
1126
|
progress.log(` checking visibility of ${this._asLocator(selector)}`);
|
|
1165
1127
|
return await this.isVisibleInternal(selector, options, scope);
|
|
1166
1128
|
}, this._page._timeoutSettings.timeout({}));
|
|
@@ -1168,256 +1130,195 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1168
1130
|
async isVisibleInternal(selector, options = {}, scope) {
|
|
1169
1131
|
try {
|
|
1170
1132
|
const resolved = await this.selectors.resolveInjectedForSelector(selector, options, scope);
|
|
1171
|
-
if (!resolved)
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
root
|
|
1175
|
-
}) => {
|
|
1133
|
+
if (!resolved)
|
|
1134
|
+
return false;
|
|
1135
|
+
return await resolved.injected.evaluate((injected, { info, root }) => {
|
|
1176
1136
|
const element = injected.querySelector(info.parsed, root || document, info.strict);
|
|
1177
|
-
const state = element ? injected.elementState(element,
|
|
1178
|
-
return state
|
|
1179
|
-
}, {
|
|
1180
|
-
info: resolved.info,
|
|
1181
|
-
root: resolved.frame === this ? scope : undefined
|
|
1182
|
-
});
|
|
1137
|
+
const state = element ? injected.elementState(element, "visible") : { matches: false, received: "error:notconnected" };
|
|
1138
|
+
return state.matches;
|
|
1139
|
+
}, { info: resolved.info, root: resolved.frame === this ? scope : void 0 });
|
|
1183
1140
|
} catch (e) {
|
|
1184
|
-
if (js.isJavaScriptErrorInEvaluate(e) || (0,
|
|
1141
|
+
if (js.isJavaScriptErrorInEvaluate(e) || (0, import_selectorParser.isInvalidSelectorError)(e) || (0, import_protocolError.isSessionClosedError)(e))
|
|
1142
|
+
throw e;
|
|
1185
1143
|
return false;
|
|
1186
1144
|
}
|
|
1187
1145
|
}
|
|
1188
1146
|
async isHidden(metadata, selector, options = {}, scope) {
|
|
1189
|
-
return !
|
|
1147
|
+
return !await this.isVisible(metadata, selector, options, scope);
|
|
1190
1148
|
}
|
|
1191
1149
|
async isDisabled(metadata, selector, options = {}, scope) {
|
|
1192
|
-
return this._elementState(metadata, selector,
|
|
1150
|
+
return this._elementState(metadata, selector, "disabled", options, scope);
|
|
1193
1151
|
}
|
|
1194
1152
|
async isEnabled(metadata, selector, options = {}, scope) {
|
|
1195
|
-
return this._elementState(metadata, selector,
|
|
1153
|
+
return this._elementState(metadata, selector, "enabled", options, scope);
|
|
1196
1154
|
}
|
|
1197
1155
|
async isEditable(metadata, selector, options = {}, scope) {
|
|
1198
|
-
return this._elementState(metadata, selector,
|
|
1156
|
+
return this._elementState(metadata, selector, "editable", options, scope);
|
|
1199
1157
|
}
|
|
1200
1158
|
async isChecked(metadata, selector, options = {}, scope) {
|
|
1201
|
-
return this._elementState(metadata, selector,
|
|
1159
|
+
return this._elementState(metadata, selector, "checked", options, scope);
|
|
1202
1160
|
}
|
|
1203
1161
|
async hover(metadata, selector, options = {}) {
|
|
1204
|
-
const controller = new
|
|
1205
|
-
return controller.run(async progress => {
|
|
1206
|
-
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force
|
|
1162
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1163
|
+
return controller.run(async (progress) => {
|
|
1164
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._hover(progress, options)));
|
|
1207
1165
|
}, this._page._timeoutSettings.timeout(options));
|
|
1208
1166
|
}
|
|
1209
1167
|
async selectOption(metadata, selector, elements, values, options = {}) {
|
|
1210
|
-
const controller = new
|
|
1211
|
-
return controller.run(async progress => {
|
|
1212
|
-
return await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force
|
|
1168
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1169
|
+
return controller.run(async (progress) => {
|
|
1170
|
+
return await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._selectOption(progress, elements, values, options));
|
|
1213
1171
|
}, this._page._timeoutSettings.timeout(options));
|
|
1214
1172
|
}
|
|
1215
1173
|
async setInputFiles(metadata, selector, params) {
|
|
1216
|
-
const inputFileItems = await (0,
|
|
1217
|
-
const controller = new
|
|
1218
|
-
return controller.run(async progress => {
|
|
1219
|
-
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, params.strict, true
|
|
1174
|
+
const inputFileItems = await (0, import_fileUploadUtils.prepareFilesForUpload)(this, params);
|
|
1175
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1176
|
+
return controller.run(async (progress) => {
|
|
1177
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, params.strict, true, (handle) => handle._setInputFiles(progress, inputFileItems)));
|
|
1220
1178
|
}, this._page._timeoutSettings.timeout(params));
|
|
1221
1179
|
}
|
|
1222
1180
|
async type(metadata, selector, text, options = {}) {
|
|
1223
|
-
const controller = new
|
|
1224
|
-
return controller.run(async progress => {
|
|
1225
|
-
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true
|
|
1181
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1182
|
+
return controller.run(async (progress) => {
|
|
1183
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, (handle) => handle._type(progress, text, options)));
|
|
1226
1184
|
}, this._page._timeoutSettings.timeout(options));
|
|
1227
1185
|
}
|
|
1228
1186
|
async press(metadata, selector, key, options = {}) {
|
|
1229
|
-
const controller = new
|
|
1230
|
-
return controller.run(async progress => {
|
|
1231
|
-
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true
|
|
1187
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1188
|
+
return controller.run(async (progress) => {
|
|
1189
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, (handle) => handle._press(progress, key, options)));
|
|
1232
1190
|
}, this._page._timeoutSettings.timeout(options));
|
|
1233
1191
|
}
|
|
1234
1192
|
async check(metadata, selector, options = {}) {
|
|
1235
|
-
const controller = new
|
|
1236
|
-
return controller.run(async progress => {
|
|
1237
|
-
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force
|
|
1193
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1194
|
+
return controller.run(async (progress) => {
|
|
1195
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._setChecked(progress, true, options)));
|
|
1238
1196
|
}, this._page._timeoutSettings.timeout(options));
|
|
1239
1197
|
}
|
|
1240
1198
|
async uncheck(metadata, selector, options = {}) {
|
|
1241
|
-
const controller = new
|
|
1242
|
-
return controller.run(async progress => {
|
|
1243
|
-
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force
|
|
1199
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1200
|
+
return controller.run(async (progress) => {
|
|
1201
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._setChecked(progress, false, options)));
|
|
1244
1202
|
}, this._page._timeoutSettings.timeout(options));
|
|
1245
1203
|
}
|
|
1246
1204
|
async waitForTimeout(metadata, timeout) {
|
|
1247
|
-
const controller = new
|
|
1205
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1248
1206
|
return controller.run(async () => {
|
|
1249
|
-
await new Promise(resolve => setTimeout(resolve, timeout));
|
|
1207
|
+
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
1250
1208
|
});
|
|
1251
1209
|
}
|
|
1252
1210
|
async ariaSnapshot(metadata, selector, options = {}) {
|
|
1253
|
-
const controller = new
|
|
1254
|
-
return controller.run(async progress => {
|
|
1255
|
-
return await this._retryWithProgressIfNotConnected(progress, selector, true
|
|
1211
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1212
|
+
return controller.run(async (progress) => {
|
|
1213
|
+
return await this._retryWithProgressIfNotConnected(progress, selector, true, true, (handle) => handle.ariaSnapshot(options));
|
|
1256
1214
|
}, this._page._timeoutSettings.timeout(options));
|
|
1257
1215
|
}
|
|
1258
1216
|
async expect(metadata, selector, options) {
|
|
1259
1217
|
const result = await this._expectImpl(metadata, selector, options);
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
error: {
|
|
1263
|
-
name: 'Expect',
|
|
1264
|
-
message: 'Expect failed'
|
|
1265
|
-
}
|
|
1266
|
-
};
|
|
1218
|
+
if (result.matches === options.isNot)
|
|
1219
|
+
metadata.error = { error: { name: "Expect", message: "Expect failed" } };
|
|
1267
1220
|
return result;
|
|
1268
1221
|
}
|
|
1269
1222
|
async _expectImpl(metadata, selector, options) {
|
|
1270
|
-
const lastIntermediateResult = {
|
|
1271
|
-
isSet: false
|
|
1272
|
-
};
|
|
1223
|
+
const lastIntermediateResult = { isSet: false };
|
|
1273
1224
|
try {
|
|
1274
1225
|
let timeout = this._page._timeoutSettings.timeout(options);
|
|
1275
|
-
const start = timeout > 0 ? (0,
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
await new _progress.ProgressController(metadata, this).run(async progress => {
|
|
1279
|
-
progress.log(`${metadata.apiName}${timeout ? ` with timeout ${timeout}ms` : ''}`);
|
|
1226
|
+
const start = timeout > 0 ? (0, import_utils.monotonicTime)() : 0;
|
|
1227
|
+
await new import_progress.ProgressController(metadata, this).run(async (progress) => {
|
|
1228
|
+
progress.log(`${metadata.apiName}${timeout ? ` with timeout ${timeout}ms` : ""}`);
|
|
1280
1229
|
progress.log(`waiting for ${this._asLocator(selector)}`);
|
|
1281
1230
|
await this._page.performActionPreChecks(progress);
|
|
1282
1231
|
}, timeout);
|
|
1283
|
-
|
|
1284
|
-
// Step 2: perform one-shot expect check without a timeout.
|
|
1285
|
-
// Supports the case of `expect(locator).toBeVisible({ timeout: 1 })`
|
|
1286
|
-
// that should succeed when the locator is already visible.
|
|
1287
1232
|
try {
|
|
1288
|
-
const resultOneShot = await new
|
|
1233
|
+
const resultOneShot = await new import_progress.ProgressController(metadata, this).run(async (progress) => {
|
|
1289
1234
|
return await this._expectInternal(progress, selector, options, lastIntermediateResult);
|
|
1290
1235
|
});
|
|
1291
|
-
if (resultOneShot.matches !== options.isNot)
|
|
1236
|
+
if (resultOneShot.matches !== options.isNot)
|
|
1237
|
+
return resultOneShot;
|
|
1292
1238
|
} catch (e) {
|
|
1293
|
-
if (js.isJavaScriptErrorInEvaluate(e) || (0,
|
|
1294
|
-
|
|
1239
|
+
if (js.isJavaScriptErrorInEvaluate(e) || (0, import_selectorParser.isInvalidSelectorError)(e))
|
|
1240
|
+
throw e;
|
|
1295
1241
|
}
|
|
1296
1242
|
if (timeout > 0) {
|
|
1297
|
-
const elapsed = (0,
|
|
1243
|
+
const elapsed = (0, import_utils.monotonicTime)() - start;
|
|
1298
1244
|
timeout -= elapsed;
|
|
1299
1245
|
}
|
|
1300
|
-
if (timeout < 0)
|
|
1301
|
-
matches: options.isNot,
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
received: lastIntermediateResult.received
|
|
1305
|
-
};
|
|
1306
|
-
|
|
1307
|
-
// Step 3: auto-retry expect with increasing timeouts. Bounded by the total remaining time.
|
|
1308
|
-
return await new _progress.ProgressController(metadata, this).run(async progress => {
|
|
1309
|
-
return await this.retryWithProgressAndTimeouts(progress, [100, 250, 500, 1000], async continuePolling => {
|
|
1246
|
+
if (timeout < 0)
|
|
1247
|
+
return { matches: options.isNot, log: (0, import_callLog.compressCallLog)(metadata.log), timedOut: true, received: lastIntermediateResult.received };
|
|
1248
|
+
return await new import_progress.ProgressController(metadata, this).run(async (progress) => {
|
|
1249
|
+
return await this.retryWithProgressAndTimeouts(progress, [100, 250, 500, 1e3], async (continuePolling) => {
|
|
1310
1250
|
await this._page.performActionPreChecks(progress);
|
|
1311
|
-
const {
|
|
1312
|
-
matches,
|
|
1313
|
-
received
|
|
1314
|
-
} = await this._expectInternal(progress, selector, options, lastIntermediateResult);
|
|
1251
|
+
const { matches, received } = await this._expectInternal(progress, selector, options, lastIntermediateResult);
|
|
1315
1252
|
if (matches === options.isNot) {
|
|
1316
|
-
// Keep waiting in these cases:
|
|
1317
|
-
// expect(locator).conditionThatDoesNotMatch
|
|
1318
|
-
// expect(locator).not.conditionThatDoesMatch
|
|
1319
1253
|
return continuePolling;
|
|
1320
1254
|
}
|
|
1321
|
-
return {
|
|
1322
|
-
matches,
|
|
1323
|
-
received
|
|
1324
|
-
};
|
|
1255
|
+
return { matches, received };
|
|
1325
1256
|
});
|
|
1326
1257
|
}, timeout);
|
|
1327
1258
|
} catch (e) {
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
if (lastIntermediateResult.isSet) result.received = lastIntermediateResult.received;
|
|
1336
|
-
if (e instanceof _errors.TimeoutError) result.timedOut = true;
|
|
1259
|
+
if (js.isJavaScriptErrorInEvaluate(e) || (0, import_selectorParser.isInvalidSelectorError)(e))
|
|
1260
|
+
throw e;
|
|
1261
|
+
const result = { matches: options.isNot, log: (0, import_callLog.compressCallLog)(metadata.log) };
|
|
1262
|
+
if (lastIntermediateResult.isSet)
|
|
1263
|
+
result.received = lastIntermediateResult.received;
|
|
1264
|
+
if (e instanceof import_errors.TimeoutError)
|
|
1265
|
+
result.timedOut = true;
|
|
1337
1266
|
return result;
|
|
1338
1267
|
}
|
|
1339
1268
|
}
|
|
1340
1269
|
async _expectInternal(progress, selector, options, lastIntermediateResult) {
|
|
1341
|
-
|
|
1342
|
-
const selectorInFrame = await this.selectors.resolveFrameForSelector(selector, {
|
|
1343
|
-
strict: true
|
|
1344
|
-
});
|
|
1270
|
+
const selectorInFrame = await this.selectors.resolveFrameForSelector(selector, { strict: true });
|
|
1345
1271
|
progress.throwIfAborted();
|
|
1346
|
-
const {
|
|
1347
|
-
|
|
1348
|
-
info
|
|
1349
|
-
} = selectorInFrame || {
|
|
1350
|
-
frame: this,
|
|
1351
|
-
info: undefined
|
|
1352
|
-
};
|
|
1353
|
-
const world = options.expression === 'to.have.property' ? 'main' : (_info$world = info === null || info === void 0 ? void 0 : info.world) !== null && _info$world !== void 0 ? _info$world : 'utility';
|
|
1272
|
+
const { frame, info } = selectorInFrame || { frame: this, info: void 0 };
|
|
1273
|
+
const world = options.expression === "to.have.property" ? "main" : info?.world ?? "utility";
|
|
1354
1274
|
const context = await frame._context(world);
|
|
1355
1275
|
const injected = await context.injectedScript();
|
|
1356
1276
|
progress.throwIfAborted();
|
|
1357
|
-
const {
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
log,
|
|
1374
|
-
...(await injected.expect(elements[0], options, elements))
|
|
1375
|
-
};
|
|
1376
|
-
}, {
|
|
1377
|
-
info,
|
|
1378
|
-
options,
|
|
1379
|
-
callId: progress.metadata.id
|
|
1380
|
-
});
|
|
1381
|
-
if (log) progress.log(log);
|
|
1382
|
-
// Note: missingReceived avoids `unexpected value "undefined"` when element was not found.
|
|
1277
|
+
const { log, matches, received, missingReceived } = await injected.evaluate(async (injected2, { info: info2, options: options2, callId }) => {
|
|
1278
|
+
const elements = info2 ? injected2.querySelectorAll(info2.parsed, document) : [];
|
|
1279
|
+
if (callId)
|
|
1280
|
+
injected2.markTargetElements(new Set(elements), callId);
|
|
1281
|
+
const isArray = options2.expression === "to.have.count" || options2.expression.endsWith(".array");
|
|
1282
|
+
let log2 = "";
|
|
1283
|
+
if (isArray)
|
|
1284
|
+
log2 = ` locator resolved to ${elements.length} element${elements.length === 1 ? "" : "s"}`;
|
|
1285
|
+
else if (elements.length > 1)
|
|
1286
|
+
throw injected2.strictModeViolationError(info2.parsed, elements);
|
|
1287
|
+
else if (elements.length)
|
|
1288
|
+
log2 = ` locator resolved to ${injected2.previewNode(elements[0])}`;
|
|
1289
|
+
return { log: log2, ...await injected2.expect(elements[0], options2, elements) };
|
|
1290
|
+
}, { info, options, callId: progress.metadata.id });
|
|
1291
|
+
if (log)
|
|
1292
|
+
progress.log(log);
|
|
1383
1293
|
if (matches === options.isNot) {
|
|
1384
|
-
lastIntermediateResult.received = missingReceived ?
|
|
1294
|
+
lastIntermediateResult.received = missingReceived ? "<element(s) not found>" : received;
|
|
1385
1295
|
lastIntermediateResult.isSet = true;
|
|
1386
|
-
if (!missingReceived && !Array.isArray(received))
|
|
1296
|
+
if (!missingReceived && !Array.isArray(received))
|
|
1297
|
+
progress.log(` unexpected value "${renderUnexpectedValue(options.expression, received)}"`);
|
|
1387
1298
|
}
|
|
1388
|
-
return {
|
|
1389
|
-
matches,
|
|
1390
|
-
received
|
|
1391
|
-
};
|
|
1299
|
+
return { matches, received };
|
|
1392
1300
|
}
|
|
1393
|
-
async _waitForFunctionExpression(metadata, expression, isFunction, arg, options, world =
|
|
1394
|
-
const controller = new
|
|
1395
|
-
if (typeof options.pollingInterval ===
|
|
1301
|
+
async _waitForFunctionExpression(metadata, expression, isFunction, arg, options, world = "main") {
|
|
1302
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1303
|
+
if (typeof options.pollingInterval === "number")
|
|
1304
|
+
(0, import_utils.assert)(options.pollingInterval > 0, "Cannot poll with non-positive interval: " + options.pollingInterval);
|
|
1396
1305
|
expression = js.normalizeEvaluationExpression(expression, isFunction);
|
|
1397
|
-
return controller.run(async progress => {
|
|
1306
|
+
return controller.run(async (progress) => {
|
|
1398
1307
|
return this.retryWithProgressAndTimeouts(progress, [100], async () => {
|
|
1399
|
-
const context = world ===
|
|
1308
|
+
const context = world === "main" ? await this._mainContext() : await this._utilityContext();
|
|
1400
1309
|
const injectedScript = await context.injectedScript();
|
|
1401
|
-
const handle = await injectedScript.evaluateHandle((injected, {
|
|
1402
|
-
expression,
|
|
1403
|
-
isFunction,
|
|
1404
|
-
polling,
|
|
1405
|
-
arg
|
|
1406
|
-
}) => {
|
|
1310
|
+
const handle = await injectedScript.evaluateHandle((injected, { expression: expression2, isFunction: isFunction2, polling, arg: arg2 }) => {
|
|
1407
1311
|
const predicate = () => {
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
result = result(arg);
|
|
1414
|
-
} else if (isFunction === false) {
|
|
1415
|
-
result = result;
|
|
1312
|
+
let result2 = globalThis.eval(expression2);
|
|
1313
|
+
if (isFunction2 === true) {
|
|
1314
|
+
result2 = result2(arg2);
|
|
1315
|
+
} else if (isFunction2 === false) {
|
|
1316
|
+
result2 = result2;
|
|
1416
1317
|
} else {
|
|
1417
|
-
|
|
1418
|
-
|
|
1318
|
+
if (typeof result2 === "function")
|
|
1319
|
+
result2 = result2(arg2);
|
|
1419
1320
|
}
|
|
1420
|
-
return
|
|
1321
|
+
return result2;
|
|
1421
1322
|
};
|
|
1422
1323
|
let fulfill;
|
|
1423
1324
|
let reject;
|
|
@@ -1427,31 +1328,28 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1427
1328
|
reject = r;
|
|
1428
1329
|
});
|
|
1429
1330
|
const next = () => {
|
|
1430
|
-
if (aborted)
|
|
1331
|
+
if (aborted)
|
|
1332
|
+
return;
|
|
1431
1333
|
try {
|
|
1432
1334
|
const success = predicate();
|
|
1433
1335
|
if (success) {
|
|
1434
1336
|
fulfill(success);
|
|
1435
1337
|
return;
|
|
1436
1338
|
}
|
|
1437
|
-
if (typeof polling !==
|
|
1339
|
+
if (typeof polling !== "number")
|
|
1340
|
+
injected.utils.builtins.requestAnimationFrame(next);
|
|
1341
|
+
else
|
|
1342
|
+
injected.utils.builtins.setTimeout(next, polling);
|
|
1438
1343
|
} catch (e) {
|
|
1439
1344
|
reject(e);
|
|
1440
1345
|
}
|
|
1441
1346
|
};
|
|
1442
1347
|
next();
|
|
1443
|
-
return {
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
expression,
|
|
1449
|
-
isFunction,
|
|
1450
|
-
polling: options.pollingInterval,
|
|
1451
|
-
arg
|
|
1452
|
-
});
|
|
1453
|
-
progress.cleanupWhenAborted(() => handle.evaluate(h => h.abort()).catch(() => {}));
|
|
1454
|
-
return handle.evaluateHandle(h => h.result);
|
|
1348
|
+
return { result, abort: () => aborted = true };
|
|
1349
|
+
}, { expression, isFunction, polling: options.pollingInterval, arg });
|
|
1350
|
+
progress.cleanupWhenAborted(() => handle.evaluate((h) => h.abort()).catch(() => {
|
|
1351
|
+
}));
|
|
1352
|
+
return handle.evaluateHandle((h) => h.result);
|
|
1455
1353
|
});
|
|
1456
1354
|
}, this._page._timeoutSettings.timeout(options));
|
|
1457
1355
|
}
|
|
@@ -1462,9 +1360,7 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1462
1360
|
return result;
|
|
1463
1361
|
return JSON.stringify(result);
|
|
1464
1362
|
}`;
|
|
1465
|
-
const handle = await this._waitForFunctionExpression((0,
|
|
1466
|
-
timeout: progress.timeUntilDeadline()
|
|
1467
|
-
}, 'utility');
|
|
1363
|
+
const handle = await this._waitForFunctionExpression((0, import_instrumentation.serverSideCallMetadata)(), expression, true, void 0, { timeout: progress.timeUntilDeadline() }, "utility");
|
|
1468
1364
|
return JSON.parse(handle.rawValue());
|
|
1469
1365
|
}
|
|
1470
1366
|
async title() {
|
|
@@ -1472,69 +1368,55 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1472
1368
|
return context.evaluate(() => document.title);
|
|
1473
1369
|
}
|
|
1474
1370
|
async rafrafTimeout(timeout) {
|
|
1475
|
-
if (timeout === 0)
|
|
1371
|
+
if (timeout === 0)
|
|
1372
|
+
return;
|
|
1476
1373
|
const context = await this._utilityContext();
|
|
1477
1374
|
await Promise.all([
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1375
|
+
// wait for double raf
|
|
1376
|
+
context.evaluate(() => new Promise((x) => {
|
|
1377
|
+
requestAnimationFrame(() => {
|
|
1378
|
+
requestAnimationFrame(x);
|
|
1379
|
+
});
|
|
1380
|
+
})),
|
|
1381
|
+
new Promise((fulfill) => setTimeout(fulfill, timeout))
|
|
1382
|
+
]);
|
|
1484
1383
|
}
|
|
1485
1384
|
_onDetached() {
|
|
1486
1385
|
this._stopNetworkIdleTimer();
|
|
1487
|
-
this._detachedScope.close(new Error(
|
|
1386
|
+
this._detachedScope.close(new Error("Frame was detached"));
|
|
1488
1387
|
for (const data of this._contextData.values()) {
|
|
1489
|
-
if (data.context)
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
});
|
|
1388
|
+
if (data.context)
|
|
1389
|
+
data.context.contextDestroyed("Frame was detached");
|
|
1390
|
+
data.contextPromise.resolve({ destroyedReason: "Frame was detached" });
|
|
1493
1391
|
}
|
|
1494
|
-
if (this._parentFrame)
|
|
1392
|
+
if (this._parentFrame)
|
|
1393
|
+
this._parentFrame._childFrames.delete(this);
|
|
1495
1394
|
this._parentFrame = null;
|
|
1496
1395
|
}
|
|
1497
1396
|
async _callOnElementOnceMatches(metadata, selector, body, taskData, options = {}, scope) {
|
|
1498
1397
|
const callbackText = body.toString();
|
|
1499
|
-
const controller = new
|
|
1500
|
-
return controller.run(async progress => {
|
|
1398
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1399
|
+
return controller.run(async (progress) => {
|
|
1501
1400
|
progress.log(`waiting for ${this._asLocator(selector)}`);
|
|
1502
|
-
const promise = this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async continuePolling => {
|
|
1401
|
+
const promise = this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async (continuePolling) => {
|
|
1503
1402
|
const resolved = await this.selectors.resolveInjectedForSelector(selector, options, scope);
|
|
1504
1403
|
progress.throwIfAborted();
|
|
1505
|
-
if (!resolved)
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
value
|
|
1510
|
-
} = await resolved.injected.evaluate((injected, {
|
|
1511
|
-
info,
|
|
1512
|
-
callbackText,
|
|
1513
|
-
taskData,
|
|
1514
|
-
callId,
|
|
1515
|
-
root
|
|
1516
|
-
}) => {
|
|
1517
|
-
const callback = injected.eval(callbackText);
|
|
1404
|
+
if (!resolved)
|
|
1405
|
+
return continuePolling;
|
|
1406
|
+
const { log, success, value } = await resolved.injected.evaluate((injected, { info, callbackText: callbackText2, taskData: taskData2, callId, root }) => {
|
|
1407
|
+
const callback = injected.eval(callbackText2);
|
|
1518
1408
|
const element = injected.querySelector(info.parsed, root || document, info.strict);
|
|
1519
|
-
if (!element)
|
|
1520
|
-
success: false
|
|
1521
|
-
}
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
return {
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
info: resolved.info,
|
|
1531
|
-
callbackText,
|
|
1532
|
-
taskData,
|
|
1533
|
-
callId: progress.metadata.id,
|
|
1534
|
-
root: resolved.frame === this ? scope : undefined
|
|
1535
|
-
});
|
|
1536
|
-
if (log) progress.log(log);
|
|
1537
|
-
if (!success) return continuePolling;
|
|
1409
|
+
if (!element)
|
|
1410
|
+
return { success: false };
|
|
1411
|
+
const log2 = ` locator resolved to ${injected.previewNode(element)}`;
|
|
1412
|
+
if (callId)
|
|
1413
|
+
injected.markTargetElements(/* @__PURE__ */ new Set([element]), callId);
|
|
1414
|
+
return { log: log2, success: true, value: callback(injected, element, taskData2) };
|
|
1415
|
+
}, { info: resolved.info, callbackText, taskData, callId: progress.metadata.id, root: resolved.frame === this ? scope : void 0 });
|
|
1416
|
+
if (log)
|
|
1417
|
+
progress.log(log);
|
|
1418
|
+
if (!success)
|
|
1419
|
+
return continuePolling;
|
|
1538
1420
|
return value;
|
|
1539
1421
|
});
|
|
1540
1422
|
return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;
|
|
@@ -1543,105 +1425,81 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1543
1425
|
_setContext(world, context) {
|
|
1544
1426
|
const data = this._contextData.get(world);
|
|
1545
1427
|
data.context = context;
|
|
1546
|
-
if (context)
|
|
1428
|
+
if (context)
|
|
1429
|
+
data.contextPromise.resolve(context);
|
|
1430
|
+
else
|
|
1431
|
+
data.contextPromise = new import_manualPromise.ManualPromise();
|
|
1547
1432
|
}
|
|
1548
1433
|
_contextCreated(world, context) {
|
|
1549
1434
|
const data = this._contextData.get(world);
|
|
1550
|
-
// In case of multiple sessions to the same target, there's a race between
|
|
1551
|
-
// connections so we might end up creating multiple isolated worlds.
|
|
1552
|
-
// We can use either.
|
|
1553
1435
|
if (data.context) {
|
|
1554
|
-
data.context.contextDestroyed(
|
|
1436
|
+
data.context.contextDestroyed("Execution context was destroyed, most likely because of a navigation");
|
|
1555
1437
|
this._setContext(world, null);
|
|
1556
1438
|
}
|
|
1557
1439
|
this._setContext(world, context);
|
|
1558
1440
|
}
|
|
1559
1441
|
_contextDestroyed(context) {
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
context.contextDestroyed('Execution context was destroyed, most likely because of a navigation');
|
|
1442
|
+
if (this._detachedScope.isClosed())
|
|
1443
|
+
return;
|
|
1444
|
+
context.contextDestroyed("Execution context was destroyed, most likely because of a navigation");
|
|
1564
1445
|
for (const [world, data] of this._contextData) {
|
|
1565
|
-
if (data.context === context)
|
|
1446
|
+
if (data.context === context)
|
|
1447
|
+
this._setContext(world, null);
|
|
1566
1448
|
}
|
|
1567
1449
|
}
|
|
1568
1450
|
_startNetworkIdleTimer() {
|
|
1569
|
-
(0,
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
// after the frame was detached - probably a race in the Firefox itself.
|
|
1573
|
-
if (this._firedLifecycleEvents.has('networkidle') || this._detachedScope.isClosed()) return;
|
|
1451
|
+
(0, import_utils.assert)(!this._networkIdleTimer);
|
|
1452
|
+
if (this._firedLifecycleEvents.has("networkidle") || this._detachedScope.isClosed())
|
|
1453
|
+
return;
|
|
1574
1454
|
this._networkIdleTimer = setTimeout(() => {
|
|
1575
1455
|
this._firedNetworkIdleSelf = true;
|
|
1576
1456
|
this._page.mainFrame()._recalculateNetworkIdle();
|
|
1577
1457
|
}, 500);
|
|
1578
1458
|
}
|
|
1579
1459
|
_stopNetworkIdleTimer() {
|
|
1580
|
-
if (this._networkIdleTimer)
|
|
1581
|
-
|
|
1460
|
+
if (this._networkIdleTimer)
|
|
1461
|
+
clearTimeout(this._networkIdleTimer);
|
|
1462
|
+
this._networkIdleTimer = void 0;
|
|
1582
1463
|
this._firedNetworkIdleSelf = false;
|
|
1583
1464
|
}
|
|
1584
1465
|
async extendInjectedScript(source, arg) {
|
|
1585
|
-
const context = await this._context(
|
|
1466
|
+
const context = await this._context("main");
|
|
1586
1467
|
const injectedScriptHandle = await context.injectedScript();
|
|
1587
|
-
return injectedScriptHandle.evaluateHandle((injectedScript, {
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
}) => {
|
|
1591
|
-
return injectedScript.extend(source, arg);
|
|
1592
|
-
}, {
|
|
1593
|
-
source,
|
|
1594
|
-
arg
|
|
1595
|
-
});
|
|
1468
|
+
return injectedScriptHandle.evaluateHandle((injectedScript, { source: source2, arg: arg2 }) => {
|
|
1469
|
+
return injectedScript.extend(source2, arg2);
|
|
1470
|
+
}, { source, arg });
|
|
1596
1471
|
}
|
|
1597
1472
|
async resetStorageForCurrentOriginBestEffort(newStorage) {
|
|
1598
1473
|
const context = await this._utilityContext();
|
|
1599
|
-
await context.evaluate(async ({
|
|
1600
|
-
ls
|
|
1601
|
-
}) => {
|
|
1602
|
-
// Clean DOMStorage.
|
|
1474
|
+
await context.evaluate(async ({ ls }) => {
|
|
1603
1475
|
sessionStorage.clear();
|
|
1604
1476
|
localStorage.clear();
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
for (const entry of ls || []) localStorage[entry.name] = entry.value;
|
|
1608
|
-
|
|
1609
|
-
// Clean Service Workers
|
|
1477
|
+
for (const entry of ls || [])
|
|
1478
|
+
localStorage[entry.name] = entry.value;
|
|
1610
1479
|
const registrations = navigator.serviceWorker ? await navigator.serviceWorker.getRegistrations() : [];
|
|
1611
|
-
await Promise.all(registrations.map(async r => {
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1480
|
+
await Promise.all(registrations.map(async (r) => {
|
|
1481
|
+
if (!r.installing && !r.waiting && !r.active)
|
|
1482
|
+
r.unregister().catch(() => {
|
|
1483
|
+
});
|
|
1484
|
+
else
|
|
1485
|
+
await r.unregister().catch(() => {
|
|
1486
|
+
});
|
|
1618
1487
|
}));
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
var _indexedDB$databases, _indexedDB;
|
|
1623
|
-
// Do not wait for the callback - it is called on timer in Chromium (slow).
|
|
1624
|
-
if (db.name) indexedDB.deleteDatabase(db.name);
|
|
1488
|
+
for (const db of await indexedDB.databases?.() || []) {
|
|
1489
|
+
if (db.name)
|
|
1490
|
+
indexedDB.deleteDatabase(db.name);
|
|
1625
1491
|
}
|
|
1626
|
-
}, {
|
|
1627
|
-
|
|
1628
|
-
}).catch(() => {});
|
|
1492
|
+
}, { ls: newStorage?.localStorage }).catch(() => {
|
|
1493
|
+
});
|
|
1629
1494
|
}
|
|
1630
1495
|
_asLocator(selector) {
|
|
1631
|
-
return (0,
|
|
1496
|
+
return (0, import_utils.asLocator)(this._page.attribution.playwright.options.sdkLanguage, selector);
|
|
1632
1497
|
}
|
|
1633
1498
|
}
|
|
1634
|
-
exports.Frame = Frame;
|
|
1635
|
-
Frame.Events = {
|
|
1636
|
-
InternalNavigation: 'internalnavigation',
|
|
1637
|
-
AddLifecycle: 'addlifecycle',
|
|
1638
|
-
RemoveLifecycle: 'removelifecycle'
|
|
1639
|
-
};
|
|
1640
1499
|
class SignalBarrier {
|
|
1641
1500
|
constructor(progress) {
|
|
1642
|
-
this._progress = void 0;
|
|
1643
1501
|
this._protectCount = 0;
|
|
1644
|
-
this._promise = new
|
|
1502
|
+
this._promise = new import_manualPromise.ManualPromise();
|
|
1645
1503
|
this._progress = progress;
|
|
1646
1504
|
this.retain();
|
|
1647
1505
|
}
|
|
@@ -1650,15 +1508,21 @@ class SignalBarrier {
|
|
|
1650
1508
|
return this._promise;
|
|
1651
1509
|
}
|
|
1652
1510
|
async addFrameNavigation(frame) {
|
|
1653
|
-
|
|
1654
|
-
|
|
1511
|
+
if (frame.parentFrame())
|
|
1512
|
+
return;
|
|
1655
1513
|
this.retain();
|
|
1656
|
-
const waiter =
|
|
1657
|
-
if (!e.isPublic)
|
|
1658
|
-
|
|
1514
|
+
const waiter = import_helper.helper.waitForEvent(null, frame, Frame.Events.InternalNavigation, (e) => {
|
|
1515
|
+
if (!e.isPublic)
|
|
1516
|
+
return false;
|
|
1517
|
+
if (!e.error && this._progress)
|
|
1518
|
+
this._progress.log(` navigated to "${frame._url}"`);
|
|
1659
1519
|
return true;
|
|
1660
1520
|
});
|
|
1661
|
-
await
|
|
1521
|
+
await import_utils.LongStandingScope.raceMultiple([
|
|
1522
|
+
frame._page.openScope,
|
|
1523
|
+
frame._detachedScope
|
|
1524
|
+
], waiter.promise).catch(() => {
|
|
1525
|
+
});
|
|
1662
1526
|
waiter.dispose();
|
|
1663
1527
|
this.release();
|
|
1664
1528
|
}
|
|
@@ -1667,25 +1531,25 @@ class SignalBarrier {
|
|
|
1667
1531
|
}
|
|
1668
1532
|
release() {
|
|
1669
1533
|
--this._protectCount;
|
|
1670
|
-
if (!this._protectCount)
|
|
1534
|
+
if (!this._protectCount)
|
|
1535
|
+
this._promise.resolve();
|
|
1671
1536
|
}
|
|
1672
1537
|
}
|
|
1673
1538
|
function verifyLifecycle(name, waitUntil) {
|
|
1674
|
-
if (waitUntil ===
|
|
1675
|
-
|
|
1539
|
+
if (waitUntil === "networkidle0")
|
|
1540
|
+
waitUntil = "networkidle";
|
|
1541
|
+
if (!types.kLifecycleEvents.has(waitUntil))
|
|
1542
|
+
throw new Error(`${name}: expected one of (load|domcontentloaded|networkidle|commit)`);
|
|
1676
1543
|
return waitUntil;
|
|
1677
1544
|
}
|
|
1678
1545
|
function renderUnexpectedValue(expression, received) {
|
|
1679
|
-
if (expression ===
|
|
1680
|
-
|
|
1681
|
-
if (expression === 'to.be.visible') return received ? 'visible' : 'hidden';
|
|
1682
|
-
if (expression === 'to.be.hidden') return received ? 'hidden' : 'visible';
|
|
1683
|
-
if (expression === 'to.be.enabled') return received ? 'enabled' : 'disabled';
|
|
1684
|
-
if (expression === 'to.be.disabled') return received ? 'disabled' : 'enabled';
|
|
1685
|
-
if (expression === 'to.be.editable') return received ? 'editable' : 'readonly';
|
|
1686
|
-
if (expression === 'to.be.readonly') return received ? 'readonly' : 'editable';
|
|
1687
|
-
if (expression === 'to.be.empty') return received ? 'empty' : 'not empty';
|
|
1688
|
-
if (expression === 'to.be.focused') return received ? 'focused' : 'not focused';
|
|
1689
|
-
if (expression === 'to.match.aria') return received ? received.raw : received;
|
|
1546
|
+
if (expression === "to.match.aria")
|
|
1547
|
+
return received ? received.raw : received;
|
|
1690
1548
|
return received;
|
|
1691
|
-
}
|
|
1549
|
+
}
|
|
1550
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1551
|
+
0 && (module.exports = {
|
|
1552
|
+
Frame,
|
|
1553
|
+
FrameManager,
|
|
1554
|
+
NavigationAbortedError
|
|
1555
|
+
});
|