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/page.js
CHANGED
|
@@ -1,88 +1,85 @@
|
|
|
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 page_exports = {};
|
|
30
|
+
__export(page_exports, {
|
|
31
|
+
InitScript: () => InitScript,
|
|
32
|
+
Page: () => Page,
|
|
33
|
+
PageBinding: () => PageBinding,
|
|
34
|
+
Worker: () => Worker,
|
|
35
|
+
kBuiltinsScript: () => kBuiltinsScript
|
|
5
36
|
});
|
|
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
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
*
|
|
32
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
33
|
-
* you may not use this file except in compliance with the License.
|
|
34
|
-
* You may obtain a copy of the License at
|
|
35
|
-
*
|
|
36
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
37
|
-
*
|
|
38
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
39
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
40
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
41
|
-
* See the License for the specific language governing permissions and
|
|
42
|
-
* limitations under the License.
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
class Page extends _instrumentation.SdkObject {
|
|
37
|
+
module.exports = __toCommonJS(page_exports);
|
|
38
|
+
var accessibility = __toESM(require("./accessibility"));
|
|
39
|
+
var import_browserContext = require("./browserContext");
|
|
40
|
+
var import_console = require("./console");
|
|
41
|
+
var import_errors = require("./errors");
|
|
42
|
+
var import_fileChooser = require("./fileChooser");
|
|
43
|
+
var frames = __toESM(require("./frames"));
|
|
44
|
+
var import_helper = require("./helper");
|
|
45
|
+
var input = __toESM(require("./input"));
|
|
46
|
+
var import_instrumentation = require("./instrumentation");
|
|
47
|
+
var import_builtins = require("../utils/isomorphic/builtins");
|
|
48
|
+
var import_pageBinding = require("./pageBinding");
|
|
49
|
+
var js = __toESM(require("./javascript"));
|
|
50
|
+
var import_progress = require("./progress");
|
|
51
|
+
var import_screenshotter = require("./screenshotter");
|
|
52
|
+
var import_timeoutSettings = require("./timeoutSettings");
|
|
53
|
+
var import_utils = require("../utils");
|
|
54
|
+
var import_crypto = require("./utils/crypto");
|
|
55
|
+
var import_utils2 = require("../utils");
|
|
56
|
+
var import_comparators = require("./utils/comparators");
|
|
57
|
+
var import_debugLogger = require("./utils/debugLogger");
|
|
58
|
+
var import_selectorParser = require("../utils/isomorphic/selectorParser");
|
|
59
|
+
var import_manualPromise = require("../utils/isomorphic/manualPromise");
|
|
60
|
+
var import_callLog = require("./callLog");
|
|
61
|
+
class Page extends import_instrumentation.SdkObject {
|
|
46
62
|
constructor(delegate, browserContext) {
|
|
47
|
-
super(browserContext,
|
|
48
|
-
this._closedState =
|
|
49
|
-
this._closedPromise = new
|
|
50
|
-
this.
|
|
63
|
+
super(browserContext, "page");
|
|
64
|
+
this._closedState = "open";
|
|
65
|
+
this._closedPromise = new import_manualPromise.ManualPromise();
|
|
66
|
+
this._initializedPromise = new import_manualPromise.ManualPromise();
|
|
51
67
|
this._eventsToEmitAfterInitialized = [];
|
|
52
68
|
this._crashed = false;
|
|
53
|
-
this.openScope = new
|
|
54
|
-
this._browserContext = void 0;
|
|
55
|
-
this.keyboard = void 0;
|
|
56
|
-
this.mouse = void 0;
|
|
57
|
-
this.touchscreen = void 0;
|
|
58
|
-
this._timeoutSettings = void 0;
|
|
59
|
-
this._delegate = void 0;
|
|
60
|
-
this._emulatedSize = void 0;
|
|
61
|
-
this._extraHTTPHeaders = void 0;
|
|
69
|
+
this.openScope = new import_utils.LongStandingScope();
|
|
62
70
|
this._emulatedMedia = {};
|
|
63
71
|
this._interceptFileChooser = false;
|
|
64
|
-
this._pageBindings = new Map();
|
|
72
|
+
this._pageBindings = /* @__PURE__ */ new Map();
|
|
65
73
|
this.initScripts = [];
|
|
66
|
-
this.
|
|
67
|
-
this._frameManager = void 0;
|
|
68
|
-
this.accessibility = void 0;
|
|
69
|
-
this._workers = new Map();
|
|
70
|
-
this.pdf = void 0;
|
|
71
|
-
this.coverage = void 0;
|
|
72
|
-
this._clientRequestInterceptor = void 0;
|
|
73
|
-
this._serverRequestInterceptor = void 0;
|
|
74
|
-
this._ownedContext = void 0;
|
|
75
|
-
this._pageIsError = void 0;
|
|
74
|
+
this._workers = /* @__PURE__ */ new Map();
|
|
76
75
|
this._video = null;
|
|
77
|
-
this._opener = void 0;
|
|
78
76
|
this._isServerSideOnly = false;
|
|
79
|
-
this._locatorHandlers = new Map();
|
|
77
|
+
this._locatorHandlers = /* @__PURE__ */ new Map();
|
|
80
78
|
this._lastLocatorHandlerUid = 0;
|
|
81
79
|
this._locatorHandlerRunningCounter = 0;
|
|
82
80
|
// Aiming at 25 fps by default - each frame is 40ms, but we give some slack with 35ms.
|
|
83
81
|
// When throttling for tracing, 200ms between frames, except for 10 frames around the action.
|
|
84
82
|
this._frameThrottler = new FrameThrottler(10, 35, 200);
|
|
85
|
-
this._closeReason = void 0;
|
|
86
83
|
this.attribution.page = this;
|
|
87
84
|
this._delegate = delegate;
|
|
88
85
|
this._browserContext = browserContext;
|
|
@@ -90,82 +87,103 @@ class Page extends _instrumentation.SdkObject {
|
|
|
90
87
|
this.keyboard = new input.Keyboard(delegate.rawKeyboard);
|
|
91
88
|
this.mouse = new input.Mouse(delegate.rawMouse, this);
|
|
92
89
|
this.touchscreen = new input.Touchscreen(delegate.rawTouchscreen, this);
|
|
93
|
-
this._timeoutSettings = new
|
|
94
|
-
this._screenshotter = new
|
|
90
|
+
this._timeoutSettings = new import_timeoutSettings.TimeoutSettings(browserContext._timeoutSettings);
|
|
91
|
+
this._screenshotter = new import_screenshotter.Screenshotter(this);
|
|
95
92
|
this._frameManager = new frames.FrameManager(this);
|
|
96
|
-
if (delegate.pdf)
|
|
93
|
+
if (delegate.pdf)
|
|
94
|
+
this.pdf = delegate.pdf.bind(delegate);
|
|
97
95
|
this.coverage = delegate.coverage ? delegate.coverage() : null;
|
|
98
96
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
static {
|
|
98
|
+
this.Events = {
|
|
99
|
+
Close: "close",
|
|
100
|
+
Crash: "crash",
|
|
101
|
+
Download: "download",
|
|
102
|
+
FileChooser: "filechooser",
|
|
103
|
+
FrameAttached: "frameattached",
|
|
104
|
+
FrameDetached: "framedetached",
|
|
105
|
+
InternalFrameNavigatedToNewDocument: "internalframenavigatedtonewdocument",
|
|
106
|
+
LocatorHandlerTriggered: "locatorhandlertriggered",
|
|
107
|
+
ScreencastFrame: "screencastframe",
|
|
108
|
+
Video: "video",
|
|
109
|
+
WebSocket: "websocket",
|
|
110
|
+
Worker: "worker"
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
async reportAsNew(opener, error = void 0, contextEvent = import_browserContext.BrowserContext.Events.Page) {
|
|
114
|
+
if (opener) {
|
|
115
|
+
const openerPageOrError = await opener.waitForInitializedOrError();
|
|
116
|
+
if (openerPageOrError instanceof Page && !openerPageOrError.isClosed())
|
|
117
|
+
this._opener = openerPageOrError;
|
|
118
|
+
}
|
|
119
|
+
this._markInitialized(error, contextEvent);
|
|
103
120
|
}
|
|
104
|
-
|
|
121
|
+
_markInitialized(error = void 0, contextEvent = import_browserContext.BrowserContext.Events.Page) {
|
|
105
122
|
if (error) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
this._setIsError(error);
|
|
123
|
+
if (this._browserContext.isClosingOrClosed())
|
|
124
|
+
return;
|
|
125
|
+
this._frameManager.createDummyMainFrameIfNeeded();
|
|
110
126
|
}
|
|
111
|
-
this._initialized =
|
|
127
|
+
this._initialized = error || this;
|
|
112
128
|
this.emitOnContext(contextEvent, this);
|
|
113
|
-
for (const {
|
|
114
|
-
event,
|
|
115
|
-
args
|
|
116
|
-
} of this._eventsToEmitAfterInitialized) this._browserContext.emit(event, ...args);
|
|
129
|
+
for (const { event, args } of this._eventsToEmitAfterInitialized)
|
|
130
|
+
this._browserContext.emit(event, ...args);
|
|
117
131
|
this._eventsToEmitAfterInitialized = [];
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
132
|
+
if (this.isClosed())
|
|
133
|
+
this.emit(Page.Events.Close);
|
|
134
|
+
else
|
|
135
|
+
this.instrumentation.onPageOpen(this);
|
|
136
|
+
this._initializedPromise.resolve(this._initialized);
|
|
123
137
|
}
|
|
124
138
|
initializedOrUndefined() {
|
|
125
|
-
return this._initialized ? this :
|
|
139
|
+
return this._initialized ? this : void 0;
|
|
140
|
+
}
|
|
141
|
+
waitForInitializedOrError() {
|
|
142
|
+
return this._initializedPromise;
|
|
126
143
|
}
|
|
127
144
|
emitOnContext(event, ...args) {
|
|
128
|
-
if (this._isServerSideOnly)
|
|
145
|
+
if (this._isServerSideOnly)
|
|
146
|
+
return;
|
|
129
147
|
this._browserContext.emit(event, ...args);
|
|
130
148
|
}
|
|
131
149
|
emitOnContextOnceInitialized(event, ...args) {
|
|
132
|
-
if (this._isServerSideOnly)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
event,
|
|
139
|
-
args
|
|
140
|
-
});
|
|
150
|
+
if (this._isServerSideOnly)
|
|
151
|
+
return;
|
|
152
|
+
if (this._initialized)
|
|
153
|
+
this._browserContext.emit(event, ...args);
|
|
154
|
+
else
|
|
155
|
+
this._eventsToEmitAfterInitialized.push({ event, args });
|
|
141
156
|
}
|
|
142
157
|
async resetForReuse(metadata) {
|
|
143
|
-
this.setDefaultNavigationTimeout(
|
|
144
|
-
this.setDefaultTimeout(
|
|
158
|
+
this.setDefaultNavigationTimeout(void 0);
|
|
159
|
+
this.setDefaultTimeout(void 0);
|
|
145
160
|
this._locatorHandlers.clear();
|
|
146
161
|
await this._removeExposedBindings();
|
|
147
162
|
await this._removeInitScripts();
|
|
148
|
-
await this.setClientRequestInterceptor(
|
|
149
|
-
await this._setServerRequestInterceptor(
|
|
163
|
+
await this.setClientRequestInterceptor(void 0);
|
|
164
|
+
await this._setServerRequestInterceptor(void 0);
|
|
150
165
|
await this.setFileChooserIntercepted(false);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
this._emulatedSize = undefined;
|
|
166
|
+
await this.mainFrame().goto(metadata, "about:blank");
|
|
167
|
+
this._emulatedSize = void 0;
|
|
154
168
|
this._emulatedMedia = {};
|
|
155
|
-
this._extraHTTPHeaders =
|
|
169
|
+
this._extraHTTPHeaders = void 0;
|
|
156
170
|
this._interceptFileChooser = false;
|
|
157
|
-
await Promise.all([
|
|
171
|
+
await Promise.all([
|
|
172
|
+
this._delegate.updateEmulatedViewportSize(),
|
|
173
|
+
this._delegate.updateEmulateMedia(),
|
|
174
|
+
this._delegate.updateFileChooserInterception()
|
|
175
|
+
]);
|
|
158
176
|
await this._delegate.resetForReuse();
|
|
159
177
|
}
|
|
160
178
|
_didClose() {
|
|
161
179
|
this._frameManager.dispose();
|
|
162
180
|
this._frameThrottler.dispose();
|
|
163
|
-
(0,
|
|
164
|
-
this._closedState =
|
|
181
|
+
(0, import_utils.assert)(this._closedState !== "closed", "Page closed twice");
|
|
182
|
+
this._closedState = "closed";
|
|
165
183
|
this.emit(Page.Events.Close);
|
|
166
184
|
this._closedPromise.resolve();
|
|
167
185
|
this.instrumentation.onPageClose(this);
|
|
168
|
-
this.openScope.close(new
|
|
186
|
+
this.openScope.close(new import_errors.TargetClosedError());
|
|
169
187
|
}
|
|
170
188
|
_didCrash() {
|
|
171
189
|
this._frameManager.dispose();
|
|
@@ -173,21 +191,20 @@ class Page extends _instrumentation.SdkObject {
|
|
|
173
191
|
this.emit(Page.Events.Crash);
|
|
174
192
|
this._crashed = true;
|
|
175
193
|
this.instrumentation.onPageClose(this);
|
|
176
|
-
this.openScope.close(new Error(
|
|
194
|
+
this.openScope.close(new Error("Page crashed"));
|
|
177
195
|
}
|
|
178
196
|
async _onFileChooserOpened(handle) {
|
|
179
197
|
let multiple;
|
|
180
198
|
try {
|
|
181
|
-
multiple = await handle.evaluate(element => !!element.multiple);
|
|
199
|
+
multiple = await handle.evaluate((element) => !!element.multiple);
|
|
182
200
|
} catch (e) {
|
|
183
|
-
// Frame/context may be gone during async processing. Do not throw.
|
|
184
201
|
return;
|
|
185
202
|
}
|
|
186
203
|
if (!this.listenerCount(Page.Events.FileChooser)) {
|
|
187
204
|
handle.dispose();
|
|
188
205
|
return;
|
|
189
206
|
}
|
|
190
|
-
const fileChooser = new
|
|
207
|
+
const fileChooser = new import_fileChooser.FileChooser(this, handle, multiple);
|
|
191
208
|
this.emit(Page.Events.FileChooser, fileChooser);
|
|
192
209
|
}
|
|
193
210
|
context() {
|
|
@@ -209,16 +226,20 @@ class Page extends _instrumentation.SdkObject {
|
|
|
209
226
|
this._timeoutSettings.setDefaultTimeout(timeout);
|
|
210
227
|
}
|
|
211
228
|
async exposeBinding(name, needsHandle, playwrightBinding) {
|
|
212
|
-
if (this._pageBindings.has(name))
|
|
213
|
-
|
|
229
|
+
if (this._pageBindings.has(name))
|
|
230
|
+
throw new Error(`Function "${name}" has been already registered`);
|
|
231
|
+
if (this._browserContext._pageBindings.has(name))
|
|
232
|
+
throw new Error(`Function "${name}" has been already registered in the browser context`);
|
|
214
233
|
const binding = new PageBinding(name, playwrightBinding, needsHandle);
|
|
215
234
|
this._pageBindings.set(name, binding);
|
|
216
235
|
await this._delegate.addInitScript(binding.initScript);
|
|
217
|
-
await Promise.all(this.frames().map(frame => frame.evaluateExpression(binding.initScript.source).catch(e => {
|
|
236
|
+
await Promise.all(this.frames().map((frame) => frame.evaluateExpression(binding.initScript.source).catch((e) => {
|
|
237
|
+
})));
|
|
218
238
|
}
|
|
219
239
|
async _removeExposedBindings() {
|
|
220
240
|
for (const [key, binding] of this._pageBindings) {
|
|
221
|
-
if (!binding.internal)
|
|
241
|
+
if (!binding.internal)
|
|
242
|
+
this._pageBindings.delete(key);
|
|
222
243
|
}
|
|
223
244
|
}
|
|
224
245
|
setExtraHTTPHeaders(headers) {
|
|
@@ -229,60 +250,61 @@ class Page extends _instrumentation.SdkObject {
|
|
|
229
250
|
return this._extraHTTPHeaders;
|
|
230
251
|
}
|
|
231
252
|
async _onBindingCalled(payload, context) {
|
|
232
|
-
if (this._closedState ===
|
|
253
|
+
if (this._closedState === "closed")
|
|
254
|
+
return;
|
|
233
255
|
await PageBinding.dispatch(this, payload, context);
|
|
234
256
|
}
|
|
235
257
|
_addConsoleMessage(type, args, location, text) {
|
|
236
|
-
const message = new
|
|
258
|
+
const message = new import_console.ConsoleMessage(this, type, text, args, location);
|
|
237
259
|
const intercepted = this._frameManager.interceptConsoleMessage(message);
|
|
238
260
|
if (intercepted) {
|
|
239
|
-
args.forEach(arg => arg.dispose());
|
|
261
|
+
args.forEach((arg) => arg.dispose());
|
|
240
262
|
return;
|
|
241
263
|
}
|
|
242
|
-
this.emitOnContextOnceInitialized(
|
|
264
|
+
this.emitOnContextOnceInitialized(import_browserContext.BrowserContext.Events.Console, message);
|
|
243
265
|
}
|
|
244
266
|
async reload(metadata, options) {
|
|
245
|
-
const controller = new
|
|
246
|
-
return controller.run(progress => this.mainFrame().raceNavigationAction(progress, options, async () => {
|
|
247
|
-
// Note: waitForNavigation may fail before we get response to reload(),
|
|
248
|
-
// so we should await it immediately.
|
|
267
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
268
|
+
return controller.run((progress) => this.mainFrame().raceNavigationAction(progress, options, async () => {
|
|
249
269
|
const [response] = await Promise.all([
|
|
250
|
-
|
|
251
|
-
|
|
270
|
+
// Reload must be a new document, and should not be confused with a stray pushState.
|
|
271
|
+
this.mainFrame()._waitForNavigation(progress, true, options),
|
|
272
|
+
this._delegate.reload()
|
|
273
|
+
]);
|
|
252
274
|
return response;
|
|
253
275
|
}), this._timeoutSettings.navigationTimeout(options));
|
|
254
276
|
}
|
|
255
277
|
async goBack(metadata, options) {
|
|
256
|
-
const controller = new
|
|
257
|
-
return controller.run(progress => this.mainFrame().raceNavigationAction(progress, options, async () => {
|
|
258
|
-
// Note: waitForNavigation may fail before we get response to goBack,
|
|
259
|
-
// so we should catch it immediately.
|
|
278
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
279
|
+
return controller.run((progress) => this.mainFrame().raceNavigationAction(progress, options, async () => {
|
|
260
280
|
let error;
|
|
261
|
-
const waitPromise = this.mainFrame()._waitForNavigation(progress, false
|
|
281
|
+
const waitPromise = this.mainFrame()._waitForNavigation(progress, false, options).catch((e) => {
|
|
262
282
|
error = e;
|
|
263
283
|
return null;
|
|
264
284
|
});
|
|
265
285
|
const result = await this._delegate.goBack();
|
|
266
|
-
if (!result)
|
|
286
|
+
if (!result)
|
|
287
|
+
return null;
|
|
267
288
|
const response = await waitPromise;
|
|
268
|
-
if (error)
|
|
289
|
+
if (error)
|
|
290
|
+
throw error;
|
|
269
291
|
return response;
|
|
270
292
|
}), this._timeoutSettings.navigationTimeout(options));
|
|
271
293
|
}
|
|
272
294
|
async goForward(metadata, options) {
|
|
273
|
-
const controller = new
|
|
274
|
-
return controller.run(progress => this.mainFrame().raceNavigationAction(progress, options, async () => {
|
|
275
|
-
// Note: waitForNavigation may fail before we get response to goForward,
|
|
276
|
-
// so we should catch it immediately.
|
|
295
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
296
|
+
return controller.run((progress) => this.mainFrame().raceNavigationAction(progress, options, async () => {
|
|
277
297
|
let error;
|
|
278
|
-
const waitPromise = this.mainFrame()._waitForNavigation(progress, false
|
|
298
|
+
const waitPromise = this.mainFrame()._waitForNavigation(progress, false, options).catch((e) => {
|
|
279
299
|
error = e;
|
|
280
300
|
return null;
|
|
281
301
|
});
|
|
282
302
|
const result = await this._delegate.goForward();
|
|
283
|
-
if (!result)
|
|
303
|
+
if (!result)
|
|
304
|
+
return null;
|
|
284
305
|
const response = await waitPromise;
|
|
285
|
-
if (error)
|
|
306
|
+
if (error)
|
|
307
|
+
throw error;
|
|
286
308
|
return response;
|
|
287
309
|
}), this._timeoutSettings.navigationTimeout(options));
|
|
288
310
|
}
|
|
@@ -291,19 +313,16 @@ class Page extends _instrumentation.SdkObject {
|
|
|
291
313
|
}
|
|
292
314
|
registerLocatorHandler(selector, noWaitAfter) {
|
|
293
315
|
const uid = ++this._lastLocatorHandlerUid;
|
|
294
|
-
this._locatorHandlers.set(uid, {
|
|
295
|
-
selector,
|
|
296
|
-
noWaitAfter
|
|
297
|
-
});
|
|
316
|
+
this._locatorHandlers.set(uid, { selector, noWaitAfter });
|
|
298
317
|
return uid;
|
|
299
318
|
}
|
|
300
319
|
resolveLocatorHandler(uid, remove) {
|
|
301
320
|
const handler = this._locatorHandlers.get(uid);
|
|
302
|
-
if (remove)
|
|
321
|
+
if (remove)
|
|
322
|
+
this._locatorHandlers.delete(uid);
|
|
303
323
|
if (handler) {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
handler.resolved = undefined;
|
|
324
|
+
handler.resolved?.resolve();
|
|
325
|
+
handler.resolved = void 0;
|
|
307
326
|
}
|
|
308
327
|
}
|
|
309
328
|
unregisterLocatorHandler(uid) {
|
|
@@ -314,106 +333,99 @@ class Page extends _instrumentation.SdkObject {
|
|
|
314
333
|
progress.throwIfAborted();
|
|
315
334
|
await this._performLocatorHandlersCheckpoint(progress);
|
|
316
335
|
progress.throwIfAborted();
|
|
317
|
-
// Wait once again, just in case a locator handler caused a navigation.
|
|
318
336
|
await this._performWaitForNavigationCheck(progress);
|
|
319
337
|
}
|
|
320
338
|
async _performWaitForNavigationCheck(progress) {
|
|
321
|
-
|
|
322
|
-
|
|
339
|
+
if (process.env.PLAYWRIGHT_SKIP_NAVIGATION_CHECK)
|
|
340
|
+
return;
|
|
323
341
|
const mainFrame = this._frameManager.mainFrame();
|
|
324
|
-
if (!mainFrame || !mainFrame.pendingDocument())
|
|
325
|
-
|
|
326
|
-
const
|
|
342
|
+
if (!mainFrame || !mainFrame.pendingDocument())
|
|
343
|
+
return;
|
|
344
|
+
const url = mainFrame.pendingDocument()?.request?.url();
|
|
345
|
+
const toUrl = url ? `" ${(0, import_utils.trimStringWithEllipsis)(url, 200)}"` : "";
|
|
327
346
|
progress.log(` waiting for${toUrl} navigation to finish...`);
|
|
328
|
-
await
|
|
329
|
-
if (!e.isPublic)
|
|
330
|
-
|
|
347
|
+
await import_helper.helper.waitForEvent(progress, mainFrame, frames.Frame.Events.InternalNavigation, (e) => {
|
|
348
|
+
if (!e.isPublic)
|
|
349
|
+
return false;
|
|
350
|
+
if (!e.error)
|
|
351
|
+
progress.log(` navigated to "${(0, import_utils.trimStringWithEllipsis)(mainFrame.url(), 200)}"`);
|
|
331
352
|
return true;
|
|
332
353
|
}).promise;
|
|
333
354
|
}
|
|
334
355
|
async _performLocatorHandlersCheckpoint(progress) {
|
|
335
|
-
|
|
336
|
-
|
|
356
|
+
if (this._locatorHandlerRunningCounter)
|
|
357
|
+
return;
|
|
337
358
|
for (const [uid, handler] of this._locatorHandlers) {
|
|
338
359
|
if (!handler.resolved) {
|
|
339
|
-
if (await this.mainFrame().isVisibleInternal(handler.selector, {
|
|
340
|
-
|
|
341
|
-
})) {
|
|
342
|
-
handler.resolved = new _manualPromise.ManualPromise();
|
|
360
|
+
if (await this.mainFrame().isVisibleInternal(handler.selector, { strict: true })) {
|
|
361
|
+
handler.resolved = new import_manualPromise.ManualPromise();
|
|
343
362
|
this.emit(Page.Events.LocatorHandlerTriggered, uid);
|
|
344
363
|
}
|
|
345
364
|
}
|
|
346
365
|
if (handler.resolved) {
|
|
347
366
|
++this._locatorHandlerRunningCounter;
|
|
348
|
-
progress.log(` found ${(0,
|
|
367
|
+
progress.log(` found ${(0, import_utils2.asLocator)(this.attribution.playwright.options.sdkLanguage, handler.selector)}, intercepting action to run the handler`);
|
|
349
368
|
const promise = handler.resolved.then(async () => {
|
|
350
369
|
progress.throwIfAborted();
|
|
351
370
|
if (!handler.noWaitAfter) {
|
|
352
|
-
progress.log(` locator handler has finished, waiting for ${(0,
|
|
353
|
-
await this.mainFrame().waitForSelectorInternal(progress, handler.selector, false, {
|
|
354
|
-
state: 'hidden'
|
|
355
|
-
});
|
|
371
|
+
progress.log(` locator handler has finished, waiting for ${(0, import_utils2.asLocator)(this.attribution.playwright.options.sdkLanguage, handler.selector)} to be hidden`);
|
|
372
|
+
await this.mainFrame().waitForSelectorInternal(progress, handler.selector, false, { state: "hidden" });
|
|
356
373
|
} else {
|
|
357
374
|
progress.log(` locator handler has finished`);
|
|
358
375
|
}
|
|
359
376
|
});
|
|
360
377
|
await this.openScope.race(promise).finally(() => --this._locatorHandlerRunningCounter);
|
|
361
|
-
// Avoid side-effects after long-running operation.
|
|
362
378
|
progress.throwIfAborted();
|
|
363
379
|
progress.log(` interception handler has finished, continuing`);
|
|
364
380
|
}
|
|
365
381
|
}
|
|
366
382
|
}
|
|
367
383
|
async emulateMedia(options) {
|
|
368
|
-
if (options.media !==
|
|
369
|
-
|
|
370
|
-
if (options.
|
|
371
|
-
|
|
384
|
+
if (options.media !== void 0)
|
|
385
|
+
this._emulatedMedia.media = options.media;
|
|
386
|
+
if (options.colorScheme !== void 0)
|
|
387
|
+
this._emulatedMedia.colorScheme = options.colorScheme;
|
|
388
|
+
if (options.reducedMotion !== void 0)
|
|
389
|
+
this._emulatedMedia.reducedMotion = options.reducedMotion;
|
|
390
|
+
if (options.forcedColors !== void 0)
|
|
391
|
+
this._emulatedMedia.forcedColors = options.forcedColors;
|
|
392
|
+
if (options.contrast !== void 0)
|
|
393
|
+
this._emulatedMedia.contrast = options.contrast;
|
|
372
394
|
await this._delegate.updateEmulateMedia();
|
|
373
395
|
}
|
|
374
396
|
emulatedMedia() {
|
|
375
|
-
var _contextOptions$color, _contextOptions$reduc, _contextOptions$force;
|
|
376
397
|
const contextOptions = this._browserContext._options;
|
|
377
398
|
return {
|
|
378
|
-
media: this._emulatedMedia.media ||
|
|
379
|
-
colorScheme: this._emulatedMedia.colorScheme !==
|
|
380
|
-
reducedMotion: this._emulatedMedia.reducedMotion !==
|
|
381
|
-
forcedColors: this._emulatedMedia.forcedColors !==
|
|
399
|
+
media: this._emulatedMedia.media || "no-override",
|
|
400
|
+
colorScheme: this._emulatedMedia.colorScheme !== void 0 ? this._emulatedMedia.colorScheme : contextOptions.colorScheme ?? "light",
|
|
401
|
+
reducedMotion: this._emulatedMedia.reducedMotion !== void 0 ? this._emulatedMedia.reducedMotion : contextOptions.reducedMotion ?? "no-preference",
|
|
402
|
+
forcedColors: this._emulatedMedia.forcedColors !== void 0 ? this._emulatedMedia.forcedColors : contextOptions.forcedColors ?? "none",
|
|
403
|
+
contrast: this._emulatedMedia.contrast !== void 0 ? this._emulatedMedia.contrast : contextOptions.contrast ?? "no-preference"
|
|
382
404
|
};
|
|
383
405
|
}
|
|
384
406
|
async setViewportSize(viewportSize) {
|
|
385
|
-
this._emulatedSize = {
|
|
386
|
-
viewport: {
|
|
387
|
-
...viewportSize
|
|
388
|
-
},
|
|
389
|
-
screen: {
|
|
390
|
-
...viewportSize
|
|
391
|
-
}
|
|
392
|
-
};
|
|
407
|
+
this._emulatedSize = { viewport: { ...viewportSize }, screen: { ...viewportSize } };
|
|
393
408
|
await this._delegate.updateEmulatedViewportSize();
|
|
394
409
|
}
|
|
395
410
|
viewportSize() {
|
|
396
|
-
|
|
397
|
-
return ((_this$emulatedSize = this.emulatedSize()) === null || _this$emulatedSize === void 0 ? void 0 : _this$emulatedSize.viewport) || null;
|
|
411
|
+
return this.emulatedSize()?.viewport || null;
|
|
398
412
|
}
|
|
399
413
|
emulatedSize() {
|
|
400
|
-
if (this._emulatedSize)
|
|
414
|
+
if (this._emulatedSize)
|
|
415
|
+
return this._emulatedSize;
|
|
401
416
|
const contextOptions = this._browserContext._options;
|
|
402
|
-
return contextOptions.viewport ? {
|
|
403
|
-
viewport: contextOptions.viewport,
|
|
404
|
-
screen: contextOptions.screen || contextOptions.viewport
|
|
405
|
-
} : null;
|
|
417
|
+
return contextOptions.viewport ? { viewport: contextOptions.viewport, screen: contextOptions.screen || contextOptions.viewport } : null;
|
|
406
418
|
}
|
|
407
419
|
async bringToFront() {
|
|
408
420
|
await this._delegate.bringToFront();
|
|
409
421
|
}
|
|
410
|
-
async addInitScript(source) {
|
|
411
|
-
const initScript = new InitScript(source);
|
|
422
|
+
async addInitScript(source, name) {
|
|
423
|
+
const initScript = new InitScript(source, false, name);
|
|
412
424
|
this.initScripts.push(initScript);
|
|
413
425
|
await this._delegate.addInitScript(initScript);
|
|
414
426
|
}
|
|
415
427
|
async _removeInitScripts() {
|
|
416
|
-
this.initScripts = this.initScripts.filter(script => script.internal);
|
|
428
|
+
this.initScripts = this.initScripts.filter((script) => script.internal);
|
|
417
429
|
await this._delegate.removeNonInternalInitScripts();
|
|
418
430
|
}
|
|
419
431
|
needsRequestInterception() {
|
|
@@ -436,114 +448,115 @@ class Page extends _instrumentation.SdkObject {
|
|
|
436
448
|
await this.mainFrame().rafrafTimeout(timeout);
|
|
437
449
|
return await this._screenshotter.screenshotPage(progress, options || {});
|
|
438
450
|
};
|
|
439
|
-
const comparator = (0,
|
|
440
|
-
const controller = new
|
|
441
|
-
if (!options.expected && options.isNot)
|
|
442
|
-
errorMessage: '"not" matcher requires expected result'
|
|
443
|
-
};
|
|
451
|
+
const comparator = (0, import_comparators.getComparator)("image/png");
|
|
452
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
453
|
+
if (!options.expected && options.isNot)
|
|
454
|
+
return { errorMessage: '"not" matcher requires expected result' };
|
|
444
455
|
try {
|
|
445
|
-
const format = (0,
|
|
446
|
-
if (format !==
|
|
456
|
+
const format = (0, import_screenshotter.validateScreenshotOptions)(options || {});
|
|
457
|
+
if (format !== "png")
|
|
458
|
+
throw new Error("Only PNG screenshots are supported");
|
|
447
459
|
} catch (error) {
|
|
448
|
-
return {
|
|
449
|
-
errorMessage: error.message
|
|
450
|
-
};
|
|
460
|
+
return { errorMessage: error.message };
|
|
451
461
|
}
|
|
452
|
-
let intermediateResult =
|
|
462
|
+
let intermediateResult = void 0;
|
|
453
463
|
const areEqualScreenshots = (actual, expected, previous) => {
|
|
454
|
-
const comparatorResult = actual && expected ? comparator(actual, expected, options) :
|
|
455
|
-
if (comparatorResult !==
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
diff: comparatorResult.diff,
|
|
459
|
-
actual,
|
|
460
|
-
previous
|
|
461
|
-
};
|
|
464
|
+
const comparatorResult = actual && expected ? comparator(actual, expected, options) : void 0;
|
|
465
|
+
if (comparatorResult !== void 0 && !!comparatorResult === !!options.isNot)
|
|
466
|
+
return true;
|
|
467
|
+
if (comparatorResult)
|
|
468
|
+
intermediateResult = { errorMessage: comparatorResult.errorMessage, diff: comparatorResult.diff, actual, previous };
|
|
462
469
|
return false;
|
|
463
470
|
};
|
|
464
471
|
const callTimeout = this._timeoutSettings.timeout(options);
|
|
465
|
-
return controller.run(async progress => {
|
|
472
|
+
return controller.run(async (progress) => {
|
|
466
473
|
let actual;
|
|
467
474
|
let previous;
|
|
468
475
|
const pollIntervals = [0, 100, 250, 500];
|
|
469
|
-
progress.log(`${metadata.apiName}${callTimeout ? ` with timeout ${callTimeout}ms` :
|
|
470
|
-
if (options.expected)
|
|
476
|
+
progress.log(`${metadata.apiName}${callTimeout ? ` with timeout ${callTimeout}ms` : ""}`);
|
|
477
|
+
if (options.expected)
|
|
478
|
+
progress.log(` verifying given screenshot expectation`);
|
|
479
|
+
else
|
|
480
|
+
progress.log(` generating new stable screenshot expectation`);
|
|
471
481
|
let isFirstIteration = true;
|
|
472
482
|
while (true) {
|
|
473
|
-
var _pollIntervals$shift;
|
|
474
483
|
progress.throwIfAborted();
|
|
475
|
-
if (this.isClosed())
|
|
476
|
-
|
|
477
|
-
|
|
484
|
+
if (this.isClosed())
|
|
485
|
+
throw new Error("The page has closed");
|
|
486
|
+
const screenshotTimeout = pollIntervals.shift() ?? 1e3;
|
|
487
|
+
if (screenshotTimeout)
|
|
488
|
+
progress.log(`waiting ${screenshotTimeout}ms before taking screenshot`);
|
|
478
489
|
previous = actual;
|
|
479
|
-
actual = await rafrafScreenshot(progress, screenshotTimeout).catch(e => {
|
|
490
|
+
actual = await rafrafScreenshot(progress, screenshotTimeout).catch((e) => {
|
|
480
491
|
progress.log(`failed to take screenshot - ` + e.message);
|
|
481
|
-
return
|
|
492
|
+
return void 0;
|
|
482
493
|
});
|
|
483
|
-
if (!actual)
|
|
484
|
-
|
|
494
|
+
if (!actual)
|
|
495
|
+
continue;
|
|
485
496
|
const expectation = options.expected && isFirstIteration ? options.expected : previous;
|
|
486
|
-
if (areEqualScreenshots(actual, expectation, previous))
|
|
487
|
-
|
|
497
|
+
if (areEqualScreenshots(actual, expectation, previous))
|
|
498
|
+
break;
|
|
499
|
+
if (intermediateResult)
|
|
500
|
+
progress.log(intermediateResult.errorMessage);
|
|
488
501
|
isFirstIteration = false;
|
|
489
502
|
}
|
|
490
|
-
if (!isFirstIteration)
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
503
|
+
if (!isFirstIteration)
|
|
504
|
+
progress.log(`captured a stable screenshot`);
|
|
505
|
+
if (!options.expected)
|
|
506
|
+
return { actual };
|
|
494
507
|
if (isFirstIteration) {
|
|
495
508
|
progress.log(`screenshot matched expectation`);
|
|
496
509
|
return {};
|
|
497
510
|
}
|
|
498
|
-
if (areEqualScreenshots(actual, options.expected,
|
|
511
|
+
if (areEqualScreenshots(actual, options.expected, void 0)) {
|
|
499
512
|
progress.log(`screenshot matched expectation`);
|
|
500
513
|
return {};
|
|
501
514
|
}
|
|
502
515
|
throw new Error(intermediateResult.errorMessage);
|
|
503
|
-
}, callTimeout).catch(e => {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
// A: We want user to receive a friendly diff between actual and expected/previous.
|
|
507
|
-
if (js.isJavaScriptErrorInEvaluate(e) || (0, _selectorParser.isInvalidSelectorError)(e)) throw e;
|
|
516
|
+
}, callTimeout).catch((e) => {
|
|
517
|
+
if (js.isJavaScriptErrorInEvaluate(e) || (0, import_selectorParser.isInvalidSelectorError)(e))
|
|
518
|
+
throw e;
|
|
508
519
|
let errorMessage = e.message;
|
|
509
|
-
if (e instanceof
|
|
520
|
+
if (e instanceof import_errors.TimeoutError && intermediateResult?.previous)
|
|
521
|
+
errorMessage = `Failed to take two consecutive stable screenshots.`;
|
|
510
522
|
return {
|
|
511
|
-
log: (0,
|
|
523
|
+
log: (0, import_callLog.compressCallLog)(e.message ? [...metadata.log, e.message] : metadata.log),
|
|
512
524
|
...intermediateResult,
|
|
513
525
|
errorMessage,
|
|
514
|
-
timedOut: e instanceof
|
|
526
|
+
timedOut: e instanceof import_errors.TimeoutError
|
|
515
527
|
};
|
|
516
528
|
});
|
|
517
529
|
}
|
|
518
530
|
async screenshot(metadata, options = {}) {
|
|
519
|
-
const controller = new
|
|
520
|
-
return controller.run(
|
|
531
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
532
|
+
return controller.run(
|
|
533
|
+
(progress) => this._screenshotter.screenshotPage(progress, options),
|
|
534
|
+
this._timeoutSettings.timeout(options)
|
|
535
|
+
);
|
|
521
536
|
}
|
|
522
537
|
async close(metadata, options = {}) {
|
|
523
|
-
if (this._closedState ===
|
|
524
|
-
|
|
538
|
+
if (this._closedState === "closed")
|
|
539
|
+
return;
|
|
540
|
+
if (options.reason)
|
|
541
|
+
this._closeReason = options.reason;
|
|
525
542
|
const runBeforeUnload = !!options.runBeforeUnload;
|
|
526
|
-
if (this._closedState !==
|
|
527
|
-
this._closedState =
|
|
528
|
-
|
|
529
|
-
// while we are trying to close the page.
|
|
530
|
-
await this._delegate.closePage(runBeforeUnload).catch(e => _debugLogger.debugLogger.log('error', e));
|
|
543
|
+
if (this._closedState !== "closing") {
|
|
544
|
+
this._closedState = "closing";
|
|
545
|
+
await this._delegate.closePage(runBeforeUnload).catch((e) => import_debugLogger.debugLogger.log("error", e));
|
|
531
546
|
}
|
|
532
|
-
if (!runBeforeUnload)
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
this._pageIsError = error;
|
|
537
|
-
this._frameManager.createDummyMainFrameIfNeeded();
|
|
547
|
+
if (!runBeforeUnload)
|
|
548
|
+
await this._closedPromise;
|
|
549
|
+
if (this._ownedContext)
|
|
550
|
+
await this._ownedContext.close(options);
|
|
538
551
|
}
|
|
539
552
|
isClosed() {
|
|
540
|
-
return this._closedState ===
|
|
553
|
+
return this._closedState === "closed";
|
|
541
554
|
}
|
|
542
555
|
hasCrashed() {
|
|
543
556
|
return this._crashed;
|
|
544
557
|
}
|
|
545
558
|
isClosedOrClosingOrCrashed() {
|
|
546
|
-
return this._closedState !==
|
|
559
|
+
return this._closedState !== "open" || this._crashed;
|
|
547
560
|
}
|
|
548
561
|
_addWorker(workerId, worker) {
|
|
549
562
|
this._workers.set(workerId, worker);
|
|
@@ -551,7 +564,8 @@ class Page extends _instrumentation.SdkObject {
|
|
|
551
564
|
}
|
|
552
565
|
_removeWorker(workerId) {
|
|
553
566
|
const worker = this._workers.get(workerId);
|
|
554
|
-
if (!worker)
|
|
567
|
+
if (!worker)
|
|
568
|
+
return;
|
|
555
569
|
worker.didClose();
|
|
556
570
|
this._workers.delete(workerId);
|
|
557
571
|
}
|
|
@@ -571,237 +585,135 @@ class Page extends _instrumentation.SdkObject {
|
|
|
571
585
|
frameNavigatedToNewDocument(frame) {
|
|
572
586
|
this.emit(Page.Events.InternalFrameNavigatedToNewDocument, frame);
|
|
573
587
|
const origin = frame.origin();
|
|
574
|
-
if (origin)
|
|
588
|
+
if (origin)
|
|
589
|
+
this._browserContext.addVisitedOrigin(origin);
|
|
575
590
|
}
|
|
576
591
|
allInitScripts() {
|
|
577
592
|
const bindings = [...this._browserContext._pageBindings.values(), ...this._pageBindings.values()];
|
|
578
|
-
return [...bindings.map(binding => binding.initScript), ...this._browserContext.initScripts, ...this.initScripts];
|
|
593
|
+
return [kBuiltinsScript, ...bindings.map((binding) => binding.initScript), ...this._browserContext.initScripts, ...this.initScripts];
|
|
579
594
|
}
|
|
580
595
|
getBinding(name) {
|
|
581
596
|
return this._pageBindings.get(name) || this._browserContext._pageBindings.get(name);
|
|
582
597
|
}
|
|
583
598
|
setScreencastOptions(options) {
|
|
584
|
-
this._delegate.setScreencastOptions(options).catch(e =>
|
|
599
|
+
this._delegate.setScreencastOptions(options).catch((e) => import_debugLogger.debugLogger.log("error", e));
|
|
585
600
|
this._frameThrottler.setThrottlingEnabled(!!options);
|
|
586
601
|
}
|
|
587
602
|
throttleScreencastFrameAck(ack) {
|
|
588
|
-
// Don't ack immediately, tracing has smart throttling logic that is implemented here.
|
|
589
603
|
this._frameThrottler.ack(ack);
|
|
590
604
|
}
|
|
591
605
|
temporarilyDisableTracingScreencastThrottling() {
|
|
592
606
|
this._frameThrottler.recharge();
|
|
593
607
|
}
|
|
594
608
|
async safeNonStallingEvaluateInAllFrames(expression, world, options = {}) {
|
|
595
|
-
await Promise.all(this.frames().map(async frame => {
|
|
609
|
+
await Promise.all(this.frames().map(async (frame) => {
|
|
596
610
|
try {
|
|
597
611
|
await frame.nonStallingEvaluateInExistingContext(expression, world);
|
|
598
612
|
} catch (e) {
|
|
599
|
-
if (options.throwOnJSErrors && js.isJavaScriptErrorInEvaluate(e))
|
|
613
|
+
if (options.throwOnJSErrors && js.isJavaScriptErrorInEvaluate(e))
|
|
614
|
+
throw e;
|
|
600
615
|
}
|
|
601
616
|
}));
|
|
602
617
|
}
|
|
603
618
|
async hideHighlight() {
|
|
604
|
-
await Promise.all(this.frames().map(frame => frame.hideHighlight().catch(() => {
|
|
619
|
+
await Promise.all(this.frames().map((frame) => frame.hideHighlight().catch(() => {
|
|
620
|
+
})));
|
|
605
621
|
}
|
|
606
622
|
markAsServerSideOnly() {
|
|
607
623
|
this._isServerSideOnly = true;
|
|
608
624
|
}
|
|
609
625
|
}
|
|
610
|
-
|
|
611
|
-
Page.Events = {
|
|
612
|
-
Close: 'close',
|
|
613
|
-
Crash: 'crash',
|
|
614
|
-
Download: 'download',
|
|
615
|
-
FileChooser: 'filechooser',
|
|
616
|
-
FrameAttached: 'frameattached',
|
|
617
|
-
FrameDetached: 'framedetached',
|
|
618
|
-
InternalFrameNavigatedToNewDocument: 'internalframenavigatedtonewdocument',
|
|
619
|
-
LocatorHandlerTriggered: 'locatorhandlertriggered',
|
|
620
|
-
ScreencastFrame: 'screencastframe',
|
|
621
|
-
Video: 'video',
|
|
622
|
-
WebSocket: 'websocket',
|
|
623
|
-
Worker: 'worker'
|
|
624
|
-
};
|
|
625
|
-
class Worker extends _instrumentation.SdkObject {
|
|
626
|
+
class Worker extends import_instrumentation.SdkObject {
|
|
626
627
|
constructor(parent, url, targetId, session) {
|
|
627
|
-
super(parent,
|
|
628
|
-
this._url = void 0;
|
|
629
|
-
this._executionContextPromise = void 0;
|
|
630
|
-
this._executionContextCallback = void 0;
|
|
628
|
+
super(parent, "worker");
|
|
631
629
|
this._existingExecutionContext = null;
|
|
632
|
-
this.openScope = new
|
|
633
|
-
this._targetId = void 0;
|
|
634
|
-
this._session = void 0;
|
|
630
|
+
this.openScope = new import_utils.LongStandingScope();
|
|
635
631
|
this._url = url;
|
|
636
|
-
this._executionContextCallback = () => {
|
|
637
|
-
|
|
632
|
+
this._executionContextCallback = () => {
|
|
633
|
+
};
|
|
634
|
+
this._executionContextPromise = new Promise((x) => this._executionContextCallback = x);
|
|
638
635
|
this._targetId = targetId;
|
|
639
636
|
this._session = session;
|
|
640
637
|
}
|
|
638
|
+
static {
|
|
639
|
+
this.Events = {
|
|
640
|
+
Close: "close"
|
|
641
|
+
};
|
|
642
|
+
}
|
|
641
643
|
_createExecutionContext(delegate) {
|
|
642
|
-
this._existingExecutionContext = new js.ExecutionContext(this, delegate,
|
|
644
|
+
this._existingExecutionContext = new js.ExecutionContext(this, delegate, "worker");
|
|
643
645
|
this._executionContextCallback(this._existingExecutionContext);
|
|
646
|
+
return this._existingExecutionContext;
|
|
644
647
|
}
|
|
645
648
|
url() {
|
|
646
649
|
return this._url;
|
|
647
650
|
}
|
|
648
651
|
didClose() {
|
|
649
|
-
if (this._existingExecutionContext)
|
|
652
|
+
if (this._existingExecutionContext)
|
|
653
|
+
this._existingExecutionContext.contextDestroyed("Worker was closed");
|
|
650
654
|
this.emit(Worker.Events.Close, this);
|
|
651
|
-
this.openScope.close(new Error(
|
|
655
|
+
this.openScope.close(new Error("Worker closed"));
|
|
652
656
|
}
|
|
653
657
|
async getExecutionContext() {
|
|
654
|
-
if (process.env[
|
|
658
|
+
if (process.env["REBROWSER_PATCHES_RUNTIME_FIX_MODE"] !== "0" && !this._existingExecutionContext) {
|
|
655
659
|
await this._session.__re__emitExecutionContext({
|
|
656
|
-
world:
|
|
660
|
+
world: "main",
|
|
657
661
|
targetId: this._targetId
|
|
658
662
|
});
|
|
659
663
|
}
|
|
660
664
|
return this._executionContextPromise;
|
|
661
665
|
}
|
|
662
666
|
async evaluateExpression(expression, isFunction, arg) {
|
|
663
|
-
return js.evaluateExpression(await this.getExecutionContext(), expression, {
|
|
664
|
-
returnByValue: true,
|
|
665
|
-
isFunction
|
|
666
|
-
}, arg);
|
|
667
|
+
return js.evaluateExpression(await this.getExecutionContext(), expression, { returnByValue: true, isFunction }, arg);
|
|
667
668
|
}
|
|
668
669
|
async evaluateExpressionHandle(expression, isFunction, arg) {
|
|
669
|
-
return js.evaluateExpression(await this.getExecutionContext(), expression, {
|
|
670
|
-
returnByValue: false,
|
|
671
|
-
isFunction
|
|
672
|
-
}, arg);
|
|
670
|
+
return js.evaluateExpression(await this.getExecutionContext(), expression, { returnByValue: false, isFunction }, arg);
|
|
673
671
|
}
|
|
674
672
|
}
|
|
675
|
-
exports.Worker = Worker;
|
|
676
|
-
Worker.Events = {
|
|
677
|
-
Close: 'close'
|
|
678
|
-
};
|
|
679
673
|
class PageBinding {
|
|
674
|
+
static {
|
|
675
|
+
this.kPlaywrightBinding = "__playwright__binding__";
|
|
676
|
+
}
|
|
680
677
|
constructor(name, playwrightFunction, needsHandle) {
|
|
681
|
-
this.name = void 0;
|
|
682
|
-
this.playwrightFunction = void 0;
|
|
683
|
-
this.initScript = void 0;
|
|
684
|
-
this.needsHandle = void 0;
|
|
685
|
-
this.internal = void 0;
|
|
686
678
|
this.name = name;
|
|
687
679
|
this.playwrightFunction = playwrightFunction;
|
|
688
|
-
this.initScript = new InitScript(
|
|
680
|
+
this.initScript = new InitScript(
|
|
681
|
+
(0, import_pageBinding.createPageBindingScript)(PageBinding.kPlaywrightBinding, name, needsHandle),
|
|
682
|
+
true
|
|
683
|
+
/* internal */
|
|
684
|
+
);
|
|
689
685
|
this.needsHandle = needsHandle;
|
|
690
|
-
this.internal = name.startsWith(
|
|
686
|
+
this.internal = name.startsWith("__pw");
|
|
691
687
|
}
|
|
692
688
|
static async dispatch(page, payload, context) {
|
|
693
|
-
if (process.env[
|
|
694
|
-
// ignore as it's not a JSON but a string from addBinding method
|
|
689
|
+
if (process.env["REBROWSER_PATCHES_RUNTIME_FIX_MODE"] !== "0" && !payload.includes("{")) {
|
|
695
690
|
return;
|
|
696
691
|
}
|
|
697
|
-
const {
|
|
698
|
-
name,
|
|
699
|
-
seq,
|
|
700
|
-
serializedArgs
|
|
701
|
-
} = JSON.parse(payload);
|
|
692
|
+
const { name, seq, serializedArgs } = JSON.parse(payload);
|
|
702
693
|
try {
|
|
703
|
-
(0,
|
|
694
|
+
(0, import_utils.assert)(context.world);
|
|
704
695
|
const binding = page.getBinding(name);
|
|
705
|
-
if (!binding)
|
|
696
|
+
if (!binding)
|
|
697
|
+
throw new Error(`Function "${name}" is not exposed`);
|
|
706
698
|
let result;
|
|
707
699
|
if (binding.needsHandle) {
|
|
708
|
-
const handle = await context.evaluateHandle(
|
|
709
|
-
|
|
710
|
-
seq
|
|
711
|
-
}).catch(e => null);
|
|
712
|
-
result = await binding.playwrightFunction({
|
|
713
|
-
frame: context.frame,
|
|
714
|
-
page,
|
|
715
|
-
context: page._browserContext
|
|
716
|
-
}, handle);
|
|
700
|
+
const handle = await context.evaluateHandle(import_pageBinding.takeBindingHandle, { name, seq }).catch((e) => null);
|
|
701
|
+
result = await binding.playwrightFunction({ frame: context.frame, page, context: page._browserContext }, handle);
|
|
717
702
|
} else {
|
|
718
|
-
if (!Array.isArray(serializedArgs))
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
page,
|
|
723
|
-
context: page._browserContext
|
|
724
|
-
}, ...args);
|
|
703
|
+
if (!Array.isArray(serializedArgs))
|
|
704
|
+
throw new Error(`serializedArgs is not an array. This can happen when Array.prototype.toJSON is defined incorrectly`);
|
|
705
|
+
const args = serializedArgs.map((a) => js.parseEvaluationResultValue(a));
|
|
706
|
+
result = await binding.playwrightFunction({ frame: context.frame, page, context: page._browserContext }, ...args);
|
|
725
707
|
}
|
|
726
|
-
context.evaluate(
|
|
727
|
-
name,
|
|
728
|
-
seq,
|
|
729
|
-
result
|
|
730
|
-
}).catch(e => _debugLogger.debugLogger.log('error', e));
|
|
708
|
+
context.evaluate(import_pageBinding.deliverBindingResult, { name, seq, result }).catch((e) => import_debugLogger.debugLogger.log("error", e));
|
|
731
709
|
} catch (error) {
|
|
732
|
-
context.evaluate(
|
|
733
|
-
name,
|
|
734
|
-
seq,
|
|
735
|
-
error
|
|
736
|
-
}).catch(e => _debugLogger.debugLogger.log('error', e));
|
|
737
|
-
}
|
|
738
|
-
function takeHandle(arg) {
|
|
739
|
-
const handle = globalThis[arg.name]['handles'].get(arg.seq);
|
|
740
|
-
globalThis[arg.name]['handles'].delete(arg.seq);
|
|
741
|
-
return handle;
|
|
742
|
-
}
|
|
743
|
-
function deliverResult(arg) {
|
|
744
|
-
const callbacks = globalThis[arg.name]['callbacks'];
|
|
745
|
-
if ('error' in arg) callbacks.get(arg.seq).reject(arg.error);else callbacks.get(arg.seq).resolve(arg.result);
|
|
746
|
-
callbacks.delete(arg.seq);
|
|
710
|
+
context.evaluate(import_pageBinding.deliverBindingResult, { name, seq, error }).catch((e) => import_debugLogger.debugLogger.log("error", e));
|
|
747
711
|
}
|
|
748
712
|
}
|
|
749
713
|
}
|
|
750
|
-
exports.PageBinding = PageBinding;
|
|
751
|
-
PageBinding.kPlaywrightBinding = '__playwright__binding__';
|
|
752
|
-
function addPageBinding(playwrightBinding, bindingName, needsHandle, utilityScriptSerializers) {
|
|
753
|
-
const binding = globalThis[playwrightBinding];
|
|
754
|
-
globalThis[bindingName] = (...args) => {
|
|
755
|
-
const me = globalThis[bindingName];
|
|
756
|
-
if (needsHandle && args.slice(1).some(arg => arg !== undefined)) throw new Error(`exposeBindingHandle supports a single argument, ${args.length} received`);
|
|
757
|
-
let callbacks = me['callbacks'];
|
|
758
|
-
if (!callbacks) {
|
|
759
|
-
callbacks = new Map();
|
|
760
|
-
me['callbacks'] = callbacks;
|
|
761
|
-
}
|
|
762
|
-
const seq = (me['lastSeq'] || 0) + 1;
|
|
763
|
-
me['lastSeq'] = seq;
|
|
764
|
-
let handles = me['handles'];
|
|
765
|
-
if (!handles) {
|
|
766
|
-
handles = new Map();
|
|
767
|
-
me['handles'] = handles;
|
|
768
|
-
}
|
|
769
|
-
const promise = new Promise((resolve, reject) => callbacks.set(seq, {
|
|
770
|
-
resolve,
|
|
771
|
-
reject
|
|
772
|
-
}));
|
|
773
|
-
let payload;
|
|
774
|
-
if (needsHandle) {
|
|
775
|
-
handles.set(seq, args[0]);
|
|
776
|
-
payload = {
|
|
777
|
-
name: bindingName,
|
|
778
|
-
seq
|
|
779
|
-
};
|
|
780
|
-
} else {
|
|
781
|
-
const serializedArgs = [];
|
|
782
|
-
for (let i = 0; i < args.length; i++) {
|
|
783
|
-
serializedArgs[i] = utilityScriptSerializers.serializeAsCallArgument(args[i], v => {
|
|
784
|
-
return {
|
|
785
|
-
fallThrough: v
|
|
786
|
-
};
|
|
787
|
-
});
|
|
788
|
-
}
|
|
789
|
-
payload = {
|
|
790
|
-
name: bindingName,
|
|
791
|
-
seq,
|
|
792
|
-
serializedArgs
|
|
793
|
-
};
|
|
794
|
-
}
|
|
795
|
-
binding(JSON.stringify(payload));
|
|
796
|
-
return promise;
|
|
797
|
-
};
|
|
798
|
-
globalThis[bindingName].__installed = true;
|
|
799
|
-
}
|
|
800
714
|
class InitScript {
|
|
801
|
-
constructor(source, internal) {
|
|
802
|
-
|
|
803
|
-
this.internal = void 0;
|
|
804
|
-
const guid = (0, _utils.createGuid)();
|
|
715
|
+
constructor(source, internal, name) {
|
|
716
|
+
const guid = (0, import_crypto.createGuid)();
|
|
805
717
|
this.source = `(() => {
|
|
806
718
|
globalThis.__pwInitScripts = globalThis.__pwInitScripts || {};
|
|
807
719
|
const hasInitScript = globalThis.__pwInitScripts[${JSON.stringify(guid)}];
|
|
@@ -811,18 +723,18 @@ class InitScript {
|
|
|
811
723
|
${source}
|
|
812
724
|
})();`;
|
|
813
725
|
this.internal = !!internal;
|
|
726
|
+
this.name = name;
|
|
814
727
|
}
|
|
815
728
|
}
|
|
816
|
-
|
|
729
|
+
const kBuiltinsScript = new InitScript(
|
|
730
|
+
`(${import_builtins.builtins})()`,
|
|
731
|
+
true
|
|
732
|
+
/* internal */
|
|
733
|
+
);
|
|
817
734
|
class FrameThrottler {
|
|
818
735
|
constructor(nonThrottledFrames, defaultInterval, throttlingInterval) {
|
|
819
736
|
this._acks = [];
|
|
820
|
-
this._defaultInterval = void 0;
|
|
821
|
-
this._throttlingInterval = void 0;
|
|
822
|
-
this._nonThrottledFrames = void 0;
|
|
823
|
-
this._budget = void 0;
|
|
824
737
|
this._throttlingEnabled = false;
|
|
825
|
-
this._timeoutId = void 0;
|
|
826
738
|
this._nonThrottledFrames = nonThrottledFrames;
|
|
827
739
|
this._budget = nonThrottledFrames;
|
|
828
740
|
this._defaultInterval = defaultInterval;
|
|
@@ -832,15 +744,15 @@ class FrameThrottler {
|
|
|
832
744
|
dispose() {
|
|
833
745
|
if (this._timeoutId) {
|
|
834
746
|
clearTimeout(this._timeoutId);
|
|
835
|
-
this._timeoutId =
|
|
747
|
+
this._timeoutId = void 0;
|
|
836
748
|
}
|
|
837
749
|
}
|
|
838
750
|
setThrottlingEnabled(enabled) {
|
|
839
751
|
this._throttlingEnabled = enabled;
|
|
840
752
|
}
|
|
841
753
|
recharge() {
|
|
842
|
-
|
|
843
|
-
|
|
754
|
+
for (const ack of this._acks)
|
|
755
|
+
ack();
|
|
844
756
|
this._acks = [];
|
|
845
757
|
this._budget = this._nonThrottledFrames;
|
|
846
758
|
if (this._timeoutId) {
|
|
@@ -850,7 +762,6 @@ class FrameThrottler {
|
|
|
850
762
|
}
|
|
851
763
|
ack(ack) {
|
|
852
764
|
if (!this._timeoutId) {
|
|
853
|
-
// Already disposed.
|
|
854
765
|
ack();
|
|
855
766
|
return;
|
|
856
767
|
}
|
|
@@ -863,11 +774,17 @@ class FrameThrottler {
|
|
|
863
774
|
ack();
|
|
864
775
|
}
|
|
865
776
|
if (this._throttlingEnabled && this._budget <= 0) {
|
|
866
|
-
// Non-throttled frame budget is exceeded. Next ack will be throttled.
|
|
867
777
|
this._timeoutId = setTimeout(() => this._tick(), this._throttlingInterval);
|
|
868
778
|
} else {
|
|
869
|
-
// Either not throttling, or still under budget. Next ack will be after the default timeout.
|
|
870
779
|
this._timeoutId = setTimeout(() => this._tick(), this._defaultInterval);
|
|
871
780
|
}
|
|
872
781
|
}
|
|
873
|
-
}
|
|
782
|
+
}
|
|
783
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
784
|
+
0 && (module.exports = {
|
|
785
|
+
InitScript,
|
|
786
|
+
Page,
|
|
787
|
+
PageBinding,
|
|
788
|
+
Worker,
|
|
789
|
+
kBuiltinsScript
|
|
790
|
+
});
|