patchright-core 1.57.0 → 1.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ThirdPartyNotices.txt +2688 -297
- package/browsers.json +23 -22
- package/lib/bootstrap.js +77 -0
- package/lib/cli/browserActions.js +308 -0
- package/lib/cli/driver.js +3 -2
- package/lib/cli/installActions.js +171 -0
- package/lib/cli/program.js +48 -413
- package/lib/client/android.js +4 -4
- package/lib/client/api.js +3 -0
- package/lib/client/browser.js +11 -5
- package/lib/client/browserContext.js +20 -23
- package/lib/client/browserType.js +23 -54
- package/lib/client/cdpSession.js +6 -2
- package/lib/client/channelOwner.js +1 -1
- package/lib/client/clientHelper.js +2 -1
- package/lib/client/clock.js +0 -1
- package/lib/client/{webSocket.js → connect.js} +57 -7
- package/lib/client/connection.js +8 -0
- package/lib/client/consoleMessage.js +3 -0
- package/lib/client/debugger.js +57 -0
- package/lib/client/dialog.js +8 -1
- package/lib/client/disposable.js +76 -0
- package/lib/client/electron.js +1 -0
- package/lib/client/elementHandle.js +1 -1
- package/lib/client/events.js +3 -0
- package/lib/client/fetch.js +2 -4
- package/lib/client/frame.js +9 -13
- package/lib/client/harRouter.js +13 -1
- package/lib/client/jsHandle.js +4 -8
- package/lib/client/locator.js +13 -36
- package/lib/client/network.js +14 -11
- package/lib/client/page.js +44 -50
- package/lib/client/screencast.js +88 -0
- package/lib/client/selectors.js +3 -1
- package/lib/client/tracing.js +11 -5
- package/lib/client/video.js +13 -20
- package/lib/client/worker.js +6 -6
- package/lib/generated/bindingsControllerSource.js +1 -1
- package/lib/generated/clockSource.js +1 -1
- package/lib/generated/injectedScriptSource.js +1 -1
- package/lib/generated/pollingRecorderSource.js +1 -1
- package/lib/generated/storageScriptSource.js +1 -1
- package/lib/generated/utilityScriptSource.js +1 -1
- package/lib/mcpBundle.js +78 -0
- package/lib/mcpBundleImpl.js +91 -0
- package/lib/protocol/serializers.js +5 -0
- package/lib/protocol/validator.js +228 -58
- package/lib/protocol/validatorPrimitives.js +1 -1
- package/lib/remote/playwrightConnection.js +10 -8
- package/lib/remote/playwrightPipeServer.js +100 -0
- package/lib/remote/playwrightServer.js +14 -10
- package/lib/remote/playwrightWebSocketServer.js +73 -0
- package/lib/remote/serverTransport.js +96 -0
- package/lib/server/android/android.js +2 -2
- package/lib/server/artifact.js +1 -1
- package/lib/server/bidi/bidiBrowser.js +80 -14
- package/lib/server/bidi/bidiChromium.js +23 -14
- package/lib/server/bidi/bidiConnection.js +1 -0
- package/lib/server/bidi/bidiDeserializer.js +116 -0
- package/lib/server/bidi/bidiExecutionContext.js +75 -29
- package/lib/server/bidi/bidiFirefox.js +6 -8
- package/lib/server/bidi/bidiNetworkManager.js +40 -12
- package/lib/server/bidi/bidiPage.js +67 -40
- package/lib/server/bidi/third_party/bidiProtocolCore.js +1 -0
- package/lib/server/bidi/third_party/firefoxPrefs.js +3 -1
- package/lib/server/browser.js +84 -21
- package/lib/server/browserContext.js +137 -77
- package/lib/server/browserType.js +26 -16
- package/lib/server/chromium/chromium.js +28 -31
- package/lib/server/chromium/chromiumSwitches.js +16 -4
- package/lib/server/chromium/crBrowser.js +40 -27
- package/lib/server/chromium/crConnection.js +0 -5
- package/lib/server/chromium/crDevTools.js +1 -2
- package/lib/server/chromium/crNetworkManager.js +54 -229
- package/lib/server/chromium/crPage.js +74 -260
- package/lib/server/chromium/crServiceWorker.js +7 -14
- package/lib/server/clock.js +33 -41
- package/lib/server/codegen/javascript.js +6 -29
- package/lib/server/console.js +5 -1
- package/lib/server/debugController.js +12 -6
- package/lib/server/debugger.js +40 -47
- package/lib/server/deviceDescriptorsSource.json +137 -137
- package/lib/server/dispatchers/browserContextDispatcher.js +30 -30
- package/lib/server/dispatchers/browserDispatcher.js +11 -5
- package/lib/server/dispatchers/browserTypeDispatcher.js +7 -0
- package/lib/server/dispatchers/cdpSessionDispatcher.js +4 -1
- package/lib/server/dispatchers/debuggerDispatcher.js +84 -0
- package/lib/server/dispatchers/dispatcher.js +7 -14
- package/lib/server/dispatchers/disposableDispatcher.js +39 -0
- package/lib/server/dispatchers/electronDispatcher.js +2 -1
- package/lib/server/dispatchers/frameDispatcher.js +7 -7
- package/lib/server/dispatchers/localUtilsDispatcher.js +37 -1
- package/lib/server/dispatchers/networkDispatchers.js +6 -5
- package/lib/server/dispatchers/pageDispatcher.js +101 -34
- package/lib/server/dispatchers/webSocketRouteDispatcher.js +4 -5
- package/lib/server/disposable.js +41 -0
- package/lib/server/dom.js +56 -29
- package/lib/server/download.js +3 -2
- package/lib/server/electron/electron.js +17 -9
- package/lib/server/firefox/ffBrowser.js +9 -29
- package/lib/server/firefox/ffConnection.js +0 -5
- package/lib/server/firefox/ffInput.js +21 -5
- package/lib/server/firefox/ffNetworkManager.js +4 -4
- package/lib/server/firefox/ffPage.js +27 -33
- package/lib/server/firefox/firefox.js +6 -8
- package/lib/server/frameSelectors.js +14 -169
- package/lib/server/frames.js +263 -551
- package/lib/server/har/harRecorder.js +2 -2
- package/lib/server/har/harTracer.js +5 -4
- package/lib/server/input.js +49 -4
- package/lib/server/instrumentation.js +8 -0
- package/lib/server/javascript.js +6 -22
- package/lib/server/launchApp.js +0 -1
- package/lib/server/localUtils.js +6 -6
- package/lib/server/network.js +59 -20
- package/lib/server/overlay.js +138 -0
- package/lib/server/page.js +179 -157
- package/lib/server/progress.js +32 -6
- package/lib/server/recorder/recorderApp.js +84 -104
- package/lib/server/recorder.js +76 -40
- package/lib/server/registry/browserFetcher.js +6 -4
- package/lib/server/registry/index.js +222 -226
- package/lib/server/registry/nativeDeps.js +1 -0
- package/lib/server/registry/oopDownloadBrowserMain.js +3 -0
- package/lib/server/screencast.js +137 -0
- package/lib/server/trace/recorder/snapshotter.js +2 -2
- package/lib/server/trace/recorder/snapshotterInjected.js +21 -1
- package/lib/server/trace/recorder/tracing.js +98 -47
- package/lib/server/trace/viewer/traceViewer.js +24 -21
- package/lib/server/usKeyboardLayout.js +7 -0
- package/lib/server/utils/comparators.js +1 -1
- package/lib/server/utils/disposable.js +32 -0
- package/lib/server/utils/eventsHelper.js +3 -1
- package/lib/server/utils/expectUtils.js +87 -2
- package/lib/server/utils/fileUtils.js +16 -2
- package/lib/server/utils/happyEyeballs.js +15 -12
- package/lib/server/utils/httpServer.js +10 -23
- package/lib/server/utils/network.js +39 -29
- package/lib/server/utils/processLauncher.js +8 -6
- package/lib/server/utils/zipFile.js +2 -2
- package/lib/server/videoRecorder.js +194 -0
- package/lib/server/webkit/webkit.js +4 -6
- package/lib/server/webkit/wkBrowser.js +1 -10
- package/lib/server/webkit/wkConnection.js +1 -6
- package/lib/server/webkit/wkInterceptableRequest.js +29 -1
- package/lib/server/webkit/wkPage.js +88 -57
- package/lib/server/webkit/wkWorkers.js +2 -1
- package/lib/serverRegistry.js +156 -0
- package/lib/tools/backend/browserBackend.js +79 -0
- package/lib/tools/backend/common.js +63 -0
- package/lib/tools/backend/config.js +41 -0
- package/lib/tools/backend/console.js +66 -0
- package/lib/tools/backend/context.js +296 -0
- package/lib/tools/backend/cookies.js +152 -0
- package/lib/tools/backend/devtools.js +69 -0
- package/lib/tools/backend/dialogs.js +59 -0
- package/lib/tools/backend/evaluate.js +64 -0
- package/lib/tools/backend/files.js +60 -0
- package/lib/tools/backend/form.js +64 -0
- package/lib/tools/backend/keyboard.js +155 -0
- package/lib/tools/backend/logFile.js +95 -0
- package/lib/tools/backend/mouse.js +168 -0
- package/lib/tools/backend/navigate.js +106 -0
- package/lib/tools/backend/network.js +135 -0
- package/lib/tools/backend/pdf.js +48 -0
- package/lib/tools/backend/response.js +305 -0
- package/lib/tools/backend/route.js +140 -0
- package/lib/tools/backend/runCode.js +77 -0
- package/lib/tools/backend/screenshot.js +88 -0
- package/lib/tools/backend/sessionLog.js +74 -0
- package/lib/tools/backend/snapshot.js +208 -0
- package/lib/tools/backend/storage.js +68 -0
- package/lib/tools/backend/tab.js +445 -0
- package/lib/tools/backend/tabs.js +67 -0
- package/lib/tools/backend/tool.js +47 -0
- package/lib/tools/backend/tools.js +102 -0
- package/lib/tools/backend/tracing.js +78 -0
- package/lib/tools/backend/utils.js +83 -0
- package/lib/tools/backend/verify.js +151 -0
- package/lib/tools/backend/video.js +98 -0
- package/lib/tools/backend/wait.js +63 -0
- package/lib/tools/backend/webstorage.js +223 -0
- package/lib/tools/cli-client/cli.js +6 -0
- package/lib/tools/cli-client/help.json +399 -0
- package/lib/tools/cli-client/minimist.js +128 -0
- package/lib/tools/cli-client/program.js +350 -0
- package/lib/tools/cli-client/registry.js +176 -0
- package/lib/tools/cli-client/session.js +289 -0
- package/lib/tools/cli-client/skill/SKILL.md +328 -0
- package/lib/tools/cli-client/skill/references/element-attributes.md +23 -0
- package/lib/tools/cli-client/skill/references/playwright-tests.md +39 -0
- package/lib/tools/cli-client/skill/references/request-mocking.md +87 -0
- package/lib/tools/cli-client/skill/references/running-code.md +231 -0
- package/lib/tools/cli-client/skill/references/session-management.md +169 -0
- package/lib/tools/cli-client/skill/references/storage-state.md +275 -0
- package/lib/tools/cli-client/skill/references/test-generation.md +88 -0
- package/lib/tools/cli-client/skill/references/tracing.md +139 -0
- package/lib/tools/cli-client/skill/references/video-recording.md +143 -0
- package/lib/tools/cli-daemon/command.js +73 -0
- package/lib/tools/cli-daemon/commands.js +956 -0
- package/lib/tools/cli-daemon/daemon.js +157 -0
- package/lib/tools/cli-daemon/helpGenerator.js +177 -0
- package/lib/tools/cli-daemon/program.js +129 -0
- package/lib/tools/dashboard/appIcon.png +0 -0
- package/lib/tools/dashboard/dashboardApp.js +284 -0
- package/lib/tools/dashboard/dashboardController.js +296 -0
- package/lib/tools/exports.js +60 -0
- package/lib/tools/mcp/browserFactory.js +233 -0
- package/lib/tools/mcp/cdpRelay.js +352 -0
- package/lib/tools/mcp/cli-stub.js +7 -0
- package/lib/tools/mcp/config.d.js +16 -0
- package/lib/tools/mcp/config.js +446 -0
- package/lib/tools/mcp/configIni.js +189 -0
- package/lib/tools/mcp/extensionContextFactory.js +55 -0
- package/lib/tools/mcp/index.js +62 -0
- package/lib/tools/mcp/log.js +35 -0
- package/lib/tools/mcp/program.js +107 -0
- package/lib/tools/mcp/protocol.js +28 -0
- package/lib/tools/mcp/watchdog.js +44 -0
- package/lib/tools/trace/SKILL.md +171 -0
- package/lib/tools/trace/installSkill.js +48 -0
- package/lib/tools/trace/traceActions.js +142 -0
- package/lib/tools/trace/traceAttachments.js +69 -0
- package/lib/tools/trace/traceCli.js +87 -0
- package/lib/tools/trace/traceConsole.js +97 -0
- package/lib/tools/trace/traceErrors.js +55 -0
- package/lib/tools/trace/traceOpen.js +69 -0
- package/lib/tools/trace/traceParser.js +96 -0
- package/lib/tools/trace/traceRequests.js +182 -0
- package/lib/tools/trace/traceScreenshot.js +68 -0
- package/lib/tools/trace/traceSnapshot.js +149 -0
- package/lib/tools/trace/traceUtils.js +153 -0
- package/lib/tools/utils/connect.js +32 -0
- package/lib/tools/utils/mcp/http.js +152 -0
- package/lib/tools/utils/mcp/server.js +230 -0
- package/lib/tools/utils/mcp/tool.js +47 -0
- package/lib/tools/utils/socketConnection.js +108 -0
- package/lib/utils/isomorphic/ariaSnapshot.js +60 -2
- package/lib/utils/isomorphic/formatUtils.js +64 -0
- package/lib/utils/isomorphic/jsonSchema.js +89 -0
- package/lib/utils/isomorphic/lruCache.js +51 -0
- package/lib/utils/isomorphic/mimeType.js +7 -2
- package/lib/utils/isomorphic/protocolFormatter.js +2 -2
- package/lib/utils/isomorphic/protocolMetainfo.js +127 -98
- package/lib/utils/isomorphic/stringUtils.js +49 -0
- package/lib/utils/isomorphic/timeoutRunner.js +3 -3
- package/lib/utils/isomorphic/trace/entries.js +16 -0
- package/lib/utils/isomorphic/trace/snapshotRenderer.js +492 -0
- package/lib/utils/isomorphic/trace/snapshotServer.js +120 -0
- package/lib/utils/isomorphic/trace/snapshotStorage.js +89 -0
- package/lib/utils/isomorphic/trace/traceLoader.js +132 -0
- package/lib/utils/isomorphic/trace/traceModel.js +366 -0
- package/lib/utils/isomorphic/trace/traceModernizer.js +401 -0
- package/lib/utils/isomorphic/trace/versions/traceV3.js +16 -0
- package/lib/utils/isomorphic/trace/versions/traceV4.js +16 -0
- package/lib/utils/isomorphic/trace/versions/traceV5.js +16 -0
- package/lib/utils/isomorphic/trace/versions/traceV6.js +16 -0
- package/lib/utils/isomorphic/trace/versions/traceV7.js +16 -0
- package/lib/utils/isomorphic/trace/versions/traceV8.js +16 -0
- package/lib/utils/isomorphic/urlMatch.js +54 -1
- package/lib/utils/isomorphic/utilityScriptSerializers.js +11 -0
- package/lib/utils/isomorphic/yaml.js +84 -0
- package/lib/utils.js +8 -2
- package/lib/utilsBundle.js +5 -26
- package/lib/utilsBundleImpl/index.js +172 -173
- package/lib/vite/dashboard/assets/index-BAOybkp8.js +50 -0
- package/lib/vite/dashboard/assets/index-CZAYOG76.css +1 -0
- package/lib/vite/dashboard/index.html +28 -0
- package/lib/vite/htmlReport/index.html +2 -70
- package/lib/vite/htmlReport/report.css +1 -0
- package/lib/vite/htmlReport/report.js +72 -0
- package/lib/vite/recorder/assets/codeMirrorModule-C8KMvO9L.js +32 -0
- package/lib/vite/recorder/assets/{codeMirrorModule-C3UTv-Ge.css → codeMirrorModule-DYBRYzYX.css} +1 -1
- package/lib/vite/recorder/assets/{index-Ri0uHF7I.css → index-BSjZa4pk.css} +1 -1
- package/lib/vite/recorder/assets/index-CqAYX1I3.js +193 -0
- package/lib/vite/recorder/index.html +2 -2
- package/lib/vite/traceViewer/assets/codeMirrorModule-DS0FLvoc.js +32 -0
- package/lib/vite/traceViewer/assets/defaultSettingsView-GTWI-W_B.js +262 -0
- package/lib/vite/traceViewer/{codeMirrorModule.C3UTv-Ge.css → codeMirrorModule.DYBRYzYX.css} +1 -1
- package/lib/vite/traceViewer/defaultSettingsView.B4dS75f0.css +1 -0
- package/lib/vite/traceViewer/index.CzXZzn5A.css +1 -0
- package/lib/vite/traceViewer/index.Dtstcb7U.js +2 -0
- package/lib/vite/traceViewer/index.html +4 -4
- package/lib/vite/traceViewer/sw.bundle.js +5 -3
- package/lib/vite/traceViewer/uiMode.Vipi55dB.js +6 -0
- package/lib/vite/traceViewer/uiMode.html +3 -3
- package/lib/zipBundleImpl.js +2 -2
- package/lib/zodBundle.js +39 -0
- package/lib/zodBundleImpl.js +40 -0
- package/package.json +7 -1
- package/types/protocol.d.ts +1696 -221
- package/types/types.d.ts +879 -112
- package/lib/server/bidi/third_party/bidiDeserializer.js +0 -98
- package/lib/server/chromium/videoRecorder.js +0 -115
- package/lib/server/pageBinding.js +0 -87
- package/lib/server/trace/test/inMemorySnapshotter.js +0 -87
- package/lib/utils/isomorphic/oldUtilityScriptSerializers.js +0 -248
- package/lib/vite/recorder/assets/codeMirrorModule-CBbSe-ZI.js +0 -25
- package/lib/vite/recorder/assets/index-CpZVd2nA.js +0 -193
- package/lib/vite/traceViewer/assets/codeMirrorModule-DHz0wP2C.js +0 -25
- package/lib/vite/traceViewer/assets/defaultSettingsView-WsZP88O6.js +0 -266
- package/lib/vite/traceViewer/defaultSettingsView.ConWv5KN.css +0 -1
- package/lib/vite/traceViewer/index.C4Y3Aw8n.css +0 -1
- package/lib/vite/traceViewer/index.C8xAeo93.js +0 -2
- package/lib/vite/traceViewer/uiMode.BltraIJB.js +0 -5
- /package/lib/{server/utils → utils/isomorphic}/imageUtils.js +0 -0
- /package/lib/utils/isomorphic/{traceUtils.js → trace/traceUtils.js} +0 -0
|
@@ -31,10 +31,7 @@ __export(crPage_exports, {
|
|
|
31
31
|
CRPage: () => CRPage
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(crPage_exports);
|
|
34
|
-
var import_crypto = __toESM(require("crypto"));
|
|
35
|
-
var import_path = __toESM(require("path"));
|
|
36
34
|
var import_assert = require("../../utils/isomorphic/assert");
|
|
37
|
-
var import_crypto2 = require("../utils/crypto");
|
|
38
35
|
var import_eventsHelper = require("../utils/eventsHelper");
|
|
39
36
|
var import_stackTrace = require("../../utils/isomorphic/stackTrace");
|
|
40
37
|
var dialog = __toESM(require("../dialog"));
|
|
@@ -43,7 +40,7 @@ var frames = __toESM(require("../frames"));
|
|
|
43
40
|
var import_helper = require("../helper");
|
|
44
41
|
var network = __toESM(require("../network"));
|
|
45
42
|
var import_page = require("../page");
|
|
46
|
-
var
|
|
43
|
+
var import_browserContext = require("../browserContext");
|
|
47
44
|
var import_crCoverage = require("./crCoverage");
|
|
48
45
|
var import_crDragDrop = require("./crDragDrop");
|
|
49
46
|
var import_crExecutionContext = require("./crExecutionContext");
|
|
@@ -52,9 +49,9 @@ var import_crNetworkManager = require("./crNetworkManager");
|
|
|
52
49
|
var import_crPdf = require("./crPdf");
|
|
53
50
|
var import_crProtocolHelper = require("./crProtocolHelper");
|
|
54
51
|
var import_defaultFontFamilies = require("./defaultFontFamilies");
|
|
55
|
-
var import_videoRecorder = require("./videoRecorder");
|
|
56
52
|
var import_errors = require("../errors");
|
|
57
53
|
var import_protocolError = require("../protocolError");
|
|
54
|
+
var import_videoRecorder = require("../videoRecorder");
|
|
58
55
|
class CRPage {
|
|
59
56
|
constructor(client, targetId, browserContext, opener, bits) {
|
|
60
57
|
this._sessions = /* @__PURE__ */ new Map();
|
|
@@ -79,8 +76,7 @@ class CRPage {
|
|
|
79
76
|
this.updateOffline();
|
|
80
77
|
this.updateExtraHTTPHeaders();
|
|
81
78
|
this.updateHttpCredentials();
|
|
82
|
-
this.
|
|
83
|
-
this.initScriptTag = import_crypto.default.randomBytes(20).toString("hex");
|
|
79
|
+
this.updateRequestInterception();
|
|
84
80
|
this._mainFrameSession = new FrameSession(this, client, targetId, null);
|
|
85
81
|
this._sessions.set(targetId, this._mainFrameSession);
|
|
86
82
|
if (opener && !browserContext._options.noDefaultViewport) {
|
|
@@ -189,7 +185,6 @@ class CRPage {
|
|
|
189
185
|
await this._mainFrameSession._client.send("HeapProfiler.collectGarbage");
|
|
190
186
|
}
|
|
191
187
|
async addInitScript(initScript, world = "main") {
|
|
192
|
-
this._page.initScripts.push(initScript);
|
|
193
188
|
await this._forAllFrameSessions((frame) => frame._evaluateOnNewDocument(initScript, world));
|
|
194
189
|
}
|
|
195
190
|
async exposePlaywrightBinding() {
|
|
@@ -208,7 +203,7 @@ class CRPage {
|
|
|
208
203
|
await this._mainFrameSession._client.send("Emulation.setDefaultBackgroundColorOverride", { color });
|
|
209
204
|
}
|
|
210
205
|
async takeScreenshot(progress, format, documentRect, viewportRect, quality, fitsViewport, scale) {
|
|
211
|
-
const { visualViewport } = await progress.race(this._mainFrameSession._client.send("Page.getLayoutMetrics"));
|
|
206
|
+
const { visualViewport, contentSize, cssContentSize } = await progress.race(this._mainFrameSession._client.send("Page.getLayoutMetrics"));
|
|
212
207
|
if (!documentRect) {
|
|
213
208
|
documentRect = {
|
|
214
209
|
x: visualViewport.pageX + viewportRect.x,
|
|
@@ -221,7 +216,7 @@ class CRPage {
|
|
|
221
216
|
}
|
|
222
217
|
const clip = { ...documentRect, scale: viewportRect ? visualViewport.scale : 1 };
|
|
223
218
|
if (scale === "css") {
|
|
224
|
-
const deviceScaleFactor = this.
|
|
219
|
+
const deviceScaleFactor = this._mainFrameSession._metricsOverride?.deviceScaleFactor || contentSize.width / cssContentSize.width || 1;
|
|
225
220
|
clip.scale /= deviceScaleFactor;
|
|
226
221
|
}
|
|
227
222
|
const result = await progress.race(this._mainFrameSession._client.send("Page.captureScreenshot", { format, quality, clip, captureBeyondViewport: !fitsViewport }));
|
|
@@ -239,17 +234,18 @@ class CRPage {
|
|
|
239
234
|
async scrollRectIntoViewIfNeeded(handle, rect) {
|
|
240
235
|
return this._sessionForHandle(handle)._scrollRectIntoViewIfNeeded(handle, rect);
|
|
241
236
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
237
|
+
startScreencast(options) {
|
|
238
|
+
this._mainFrameSession._client.send("Page.startScreencast", {
|
|
239
|
+
format: "jpeg",
|
|
240
|
+
quality: options.quality,
|
|
241
|
+
maxWidth: options.width,
|
|
242
|
+
maxHeight: options.height
|
|
243
|
+
}).catch(() => {
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
stopScreencast() {
|
|
247
|
+
this._mainFrameSession._client._sendMayFail("Page.stopScreencast").catch(() => {
|
|
248
|
+
});
|
|
253
249
|
}
|
|
254
250
|
rafCountForStablePosition() {
|
|
255
251
|
return 1;
|
|
@@ -301,13 +297,8 @@ class CRPage {
|
|
|
301
297
|
shouldToggleStyleSheetToSyncAnimations() {
|
|
302
298
|
return false;
|
|
303
299
|
}
|
|
304
|
-
async
|
|
305
|
-
await this.
|
|
306
|
-
await Promise.all(this._page.frames().map((frame) => frame.evaluateExpression(binding.source).catch((e) => {
|
|
307
|
-
})));
|
|
308
|
-
}
|
|
309
|
-
async removeExposedBindings() {
|
|
310
|
-
await this._forAllFrameSessions((frame) => frame._removeExposedBindings());
|
|
300
|
+
async setDockTile(image) {
|
|
301
|
+
await this._mainFrameSession._client.send("Browser.setDockTile", { image: image.toString("base64") });
|
|
311
302
|
}
|
|
312
303
|
}
|
|
313
304
|
class FrameSession {
|
|
@@ -322,15 +313,8 @@ class FrameSession {
|
|
|
322
313
|
// Marks the oopif session that remote -> local transition has happened in the parent.
|
|
323
314
|
// See Target.detachedFromTarget handler for details.
|
|
324
315
|
this._swappedIn = false;
|
|
325
|
-
this._videoRecorder = null;
|
|
326
|
-
this._screencastId = null;
|
|
327
|
-
this._screencastClients = /* @__PURE__ */ new Set();
|
|
328
316
|
this._workerSessions = /* @__PURE__ */ new Map();
|
|
329
317
|
this._initScriptIds = /* @__PURE__ */ new Map();
|
|
330
|
-
this._exposedBindingNames = [];
|
|
331
|
-
this._evaluateOnNewDocumentScripts = [];
|
|
332
|
-
this._parsedExecutionContextIds = [];
|
|
333
|
-
this._exposedBindingScripts = [];
|
|
334
318
|
this._client = client;
|
|
335
319
|
this._crPage = crPage;
|
|
336
320
|
this._page = crPage._page;
|
|
@@ -380,23 +364,8 @@ class FrameSession {
|
|
|
380
364
|
const { windowId } = await this._client.send("Browser.getWindowForTarget");
|
|
381
365
|
this._windowId = windowId;
|
|
382
366
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
const screencastId = (0, import_crypto2.createGuid)();
|
|
386
|
-
const outputFile = import_path.default.join(this._crPage._browserContext._options.recordVideo.dir, screencastId + ".webm");
|
|
387
|
-
screencastOptions = {
|
|
388
|
-
// validateBrowserContextOptions ensures correct video size.
|
|
389
|
-
...this._crPage._browserContext._options.recordVideo.size,
|
|
390
|
-
outputFile
|
|
391
|
-
};
|
|
392
|
-
await this._crPage._browserContext._ensureVideosPath();
|
|
393
|
-
await this._createVideoRecorder(screencastId, screencastOptions);
|
|
394
|
-
this._crPage._page.waitForInitializedOrError().then((p) => {
|
|
395
|
-
if (p instanceof Error)
|
|
396
|
-
this._stopVideoRecording().catch(() => {
|
|
397
|
-
});
|
|
398
|
-
});
|
|
399
|
-
}
|
|
367
|
+
if (this._isMainFrame() && hasUIWindow && !this._page.isStorageStatePage)
|
|
368
|
+
(0, import_videoRecorder.startAutomaticVideoRecording)(this._crPage._page);
|
|
400
369
|
let lifecycleEventsEnabled;
|
|
401
370
|
if (!this._isMainFrame())
|
|
402
371
|
this._addRendererListeners();
|
|
@@ -413,6 +382,14 @@ class FrameSession {
|
|
|
413
382
|
this._bufferedAttachedToTargetEvents = void 0;
|
|
414
383
|
for (const event of attachedToTargetEvents)
|
|
415
384
|
this._onAttachedToTarget(event);
|
|
385
|
+
const localFrames = this._isMainFrame() ? this._page.frames() : [this._page.frameManager.frame(this._targetId)];
|
|
386
|
+
for (const frame of localFrames) {
|
|
387
|
+
this._client._sendMayFail("Page.createIsolatedWorld", {
|
|
388
|
+
frameId: frame._id,
|
|
389
|
+
grantUniveralAccess: true,
|
|
390
|
+
worldName: this._crPage.utilityWorldName
|
|
391
|
+
});
|
|
392
|
+
}
|
|
416
393
|
const isInitialEmptyPage = this._isMainFrame() && this._page.mainFrame().url() === ":";
|
|
417
394
|
if (isInitialEmptyPage) {
|
|
418
395
|
lifecycleEventsEnabled.catch((e) => {
|
|
@@ -420,22 +397,13 @@ class FrameSession {
|
|
|
420
397
|
this._eventListeners.push(import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.lifecycleEvent", (event) => this._onLifecycleEvent(event)));
|
|
421
398
|
});
|
|
422
399
|
} else {
|
|
423
|
-
const localFrames = this._isMainFrame() ? this._page.frames() : [this._page.frameManager.frame(this._targetId)];
|
|
424
|
-
for (const frame of localFrames) {
|
|
425
|
-
this._page.frameManager.frame(frame._id)._context("utility");
|
|
426
|
-
for (const binding of this._crPage._browserContext._pageBindings.values())
|
|
427
|
-
frame.evaluateExpression(binding.source).catch((e) => {
|
|
428
|
-
});
|
|
429
|
-
for (const source of this._crPage._browserContext.initScripts)
|
|
430
|
-
frame.evaluateExpression(source).catch((e) => {
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
400
|
this._firstNonInitialNavigationCommittedFulfill();
|
|
434
401
|
this._eventListeners.push(import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.lifecycleEvent", (event) => this._onLifecycleEvent(event)));
|
|
435
402
|
}
|
|
436
403
|
}),
|
|
437
404
|
this._client.send("Log.enable", {}),
|
|
438
405
|
lifecycleEventsEnabled = this._client.send("Page.setLifecycleEventsEnabled", { enabled: true }),
|
|
406
|
+
this._client.send("Runtime.enable", {}),
|
|
439
407
|
this._client.send("Page.addScriptToEvaluateOnNewDocument", {
|
|
440
408
|
source: "",
|
|
441
409
|
worldName: this._crPage.utilityWorldName
|
|
@@ -446,6 +414,8 @@ class FrameSession {
|
|
|
446
414
|
if (!this._page.isStorageStatePage) {
|
|
447
415
|
if (this._crPage._browserContext.needsPlaywrightBinding())
|
|
448
416
|
promises.push(this.exposePlaywrightBinding());
|
|
417
|
+
if (this._isMainFrame())
|
|
418
|
+
promises.push(this._client.send("Emulation.setFocusEmulationEnabled", { enabled: true }));
|
|
449
419
|
const options = this._crPage._browserContext._options;
|
|
450
420
|
if (options.bypassCSP)
|
|
451
421
|
promises.push(this._client.send("Page.setBypassCSP", { enabled: true }));
|
|
@@ -468,21 +438,20 @@ class FrameSession {
|
|
|
468
438
|
promises.push(this._updateGeolocation(true));
|
|
469
439
|
promises.push(this._updateEmulateMedia());
|
|
470
440
|
promises.push(this._updateFileChooserInterception(true));
|
|
471
|
-
for (const
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
441
|
+
for (const initScript of this._crPage._page.allInitScripts())
|
|
442
|
+
promises.push(this._evaluateOnNewDocument(
|
|
443
|
+
initScript,
|
|
444
|
+
"main",
|
|
445
|
+
true
|
|
446
|
+
/* runImmediately */
|
|
447
|
+
));
|
|
476
448
|
}
|
|
477
|
-
|
|
478
|
-
promises.push(this._client.send("Runtime.runIfWaitingForDebugger"));
|
|
449
|
+
promises.push(this._client.send("Runtime.runIfWaitingForDebugger"));
|
|
479
450
|
promises.push(this._firstNonInitialNavigationCommittedPromise);
|
|
480
451
|
await Promise.all(promises);
|
|
481
|
-
if (this._crPage._page._pageBindings.size || this._crPage._browserContext._pageBindings.size)
|
|
482
|
-
await this._client.send("Runtime.runIfWaitingForDebugger");
|
|
483
452
|
}
|
|
484
453
|
dispose() {
|
|
485
|
-
this._firstNonInitialNavigationCommittedReject(new import_errors.TargetClosedError());
|
|
454
|
+
this._firstNonInitialNavigationCommittedReject(new import_errors.TargetClosedError(this._page.closeReason()));
|
|
486
455
|
for (const childSession of this._childSessions)
|
|
487
456
|
childSession.dispose();
|
|
488
457
|
if (this._parentSession)
|
|
@@ -500,28 +469,13 @@ class FrameSession {
|
|
|
500
469
|
throw new frames.NavigationAbortedError(response.loaderId, `${response.errorText} at ${url}`);
|
|
501
470
|
return { newDocumentId: response.loaderId };
|
|
502
471
|
}
|
|
503
|
-
|
|
472
|
+
_onLifecycleEvent(event) {
|
|
504
473
|
if (this._eventBelongsToStaleFrame(event.frameId))
|
|
505
474
|
return;
|
|
506
475
|
if (event.name === "load")
|
|
507
476
|
this._page.frameManager.frameLifecycleEvent(event.frameId, "load");
|
|
508
477
|
else if (event.name === "DOMContentLoaded")
|
|
509
478
|
this._page.frameManager.frameLifecycleEvent(event.frameId, "domcontentloaded");
|
|
510
|
-
await this._client._sendMayFail("Runtime.runIfWaitingForDebugger");
|
|
511
|
-
var document = await this._client._sendMayFail("DOM.getDocument");
|
|
512
|
-
if (!document) return;
|
|
513
|
-
var query = await this._client._sendMayFail("DOM.querySelectorAll", {
|
|
514
|
-
nodeId: document.root.nodeId,
|
|
515
|
-
selector: "[class=" + this._crPage.initScriptTag + "]"
|
|
516
|
-
});
|
|
517
|
-
if (!query) return;
|
|
518
|
-
for (const nodeId of query.nodeIds) await this._client._sendMayFail("DOM.removeNode", { nodeId });
|
|
519
|
-
await this._client._sendMayFail("Runtime.runIfWaitingForDebugger");
|
|
520
|
-
try {
|
|
521
|
-
await this._page.frameManager.frame(this._targetId)._context("utility");
|
|
522
|
-
} catch {
|
|
523
|
-
}
|
|
524
|
-
;
|
|
525
479
|
}
|
|
526
480
|
_handleFrameTree(frameTree) {
|
|
527
481
|
this._onFrameAttached(frameTree.frame.id, frameTree.frame.parentId || null);
|
|
@@ -552,27 +506,12 @@ class FrameSession {
|
|
|
552
506
|
}
|
|
553
507
|
this._page.frameManager.frameAttached(frameId, parentFrameId);
|
|
554
508
|
}
|
|
555
|
-
|
|
509
|
+
_onFrameNavigated(framePayload, initial) {
|
|
556
510
|
if (this._eventBelongsToStaleFrame(framePayload.id))
|
|
557
511
|
return;
|
|
558
512
|
this._page.frameManager.frameCommittedNewDocumentNavigation(framePayload.id, framePayload.url + (framePayload.urlFragment || ""), framePayload.name || "", framePayload.loaderId, initial);
|
|
559
513
|
if (!initial)
|
|
560
514
|
this._firstNonInitialNavigationCommittedFulfill();
|
|
561
|
-
await this._client._sendMayFail("Runtime.runIfWaitingForDebugger");
|
|
562
|
-
var document = await this._client._sendMayFail("DOM.getDocument");
|
|
563
|
-
if (!document) return;
|
|
564
|
-
var query = await this._client._sendMayFail("DOM.querySelectorAll", {
|
|
565
|
-
nodeId: document.root.nodeId,
|
|
566
|
-
selector: "[class=" + this._crPage.initScriptTag + "]"
|
|
567
|
-
});
|
|
568
|
-
if (!query) return;
|
|
569
|
-
for (const nodeId of query.nodeIds) await this._client._sendMayFail("DOM.removeNode", { nodeId });
|
|
570
|
-
await this._client._sendMayFail("Runtime.runIfWaitingForDebugger");
|
|
571
|
-
try {
|
|
572
|
-
await this._page.frameManager.frame(this._targetId)._context("utility");
|
|
573
|
-
} catch {
|
|
574
|
-
}
|
|
575
|
-
;
|
|
576
515
|
}
|
|
577
516
|
_onFrameRequestedNavigation(payload) {
|
|
578
517
|
if (this._eventBelongsToStaleFrame(payload.frameId))
|
|
@@ -598,25 +537,19 @@ class FrameSession {
|
|
|
598
537
|
this._page.frameManager.frameDetached(frameId);
|
|
599
538
|
}
|
|
600
539
|
_onExecutionContextCreated(contextPayload) {
|
|
601
|
-
for (const name of this._exposedBindingNames)
|
|
602
|
-
this._client._sendMayFail("Runtime.addBinding", { name, executionContextId: contextPayload.id });
|
|
603
540
|
const frame = contextPayload.auxData ? this._page.frameManager.frame(contextPayload.auxData.frameId) : null;
|
|
604
|
-
if (contextPayload.auxData.type == "worker") throw new Error("ExecutionContext is worker");
|
|
605
541
|
if (!frame || this._eventBelongsToStaleFrame(frame._id))
|
|
606
542
|
return;
|
|
607
543
|
const delegate = new import_crExecutionContext.CRExecutionContext(this._client, contextPayload);
|
|
608
|
-
let worldName =
|
|
544
|
+
let worldName = null;
|
|
545
|
+
if (contextPayload.auxData && !!contextPayload.auxData.isDefault)
|
|
546
|
+
worldName = "main";
|
|
547
|
+
else if (contextPayload.name === this._crPage.utilityWorldName)
|
|
548
|
+
worldName = "utility";
|
|
609
549
|
const context = new dom.FrameExecutionContext(delegate, frame, worldName);
|
|
610
550
|
if (worldName)
|
|
611
551
|
frame._contextCreated(worldName, context);
|
|
612
552
|
this._contextIdToContext.set(contextPayload.id, context);
|
|
613
|
-
for (const source of this._exposedBindingScripts) {
|
|
614
|
-
this._client._sendMayFail("Runtime.evaluate", {
|
|
615
|
-
expression: source,
|
|
616
|
-
contextId: contextPayload.id,
|
|
617
|
-
awaitPromise: true
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
553
|
}
|
|
621
554
|
_onExecutionContextDestroyed(executionContextId) {
|
|
622
555
|
const context = this._contextIdToContext.get(executionContextId);
|
|
@@ -629,7 +562,7 @@ class FrameSession {
|
|
|
629
562
|
for (const contextId of Array.from(this._contextIdToContext.keys()))
|
|
630
563
|
this._onExecutionContextDestroyed(contextId);
|
|
631
564
|
}
|
|
632
|
-
|
|
565
|
+
_onAttachedToTarget(event) {
|
|
633
566
|
if (this._bufferedAttachedToTargetEvents) {
|
|
634
567
|
this._bufferedAttachedToTargetEvents.push(event);
|
|
635
568
|
return;
|
|
@@ -665,19 +598,11 @@ class FrameSession {
|
|
|
665
598
|
session.once("Runtime.executionContextCreated", async (event2) => {
|
|
666
599
|
worker.createExecutionContext(new import_crExecutionContext.CRExecutionContext(session, event2.context));
|
|
667
600
|
});
|
|
668
|
-
var globalThis = await session._sendMayFail("Runtime.evaluate", {
|
|
669
|
-
expression: "globalThis",
|
|
670
|
-
serializationOptions: { serialization: "idOnly" }
|
|
671
|
-
});
|
|
672
|
-
if (globalThis && globalThis.result) {
|
|
673
|
-
var globalThisObjId = globalThis.result.objectId;
|
|
674
|
-
var executionContextId = parseInt(globalThisObjId.split(".")[1], 10);
|
|
675
|
-
worker.createExecutionContext(new import_crExecutionContext.CRExecutionContext(session, { id: executionContextId }));
|
|
676
|
-
}
|
|
677
601
|
if (this._crPage._browserContext._browser.majorVersion() >= 143)
|
|
678
602
|
session.on("Inspector.workerScriptLoaded", () => worker.workerScriptLoaded());
|
|
679
603
|
else
|
|
680
604
|
worker.workerScriptLoaded();
|
|
605
|
+
session._sendMayFail("Runtime.enable");
|
|
681
606
|
this._crPage._networkManager.addSession(session, this._page.frameManager.frame(this._targetId) ?? void 0).catch(() => {
|
|
682
607
|
});
|
|
683
608
|
session._sendMayFail("Runtime.runIfWaitingForDebugger");
|
|
@@ -686,7 +611,7 @@ class FrameSession {
|
|
|
686
611
|
session.on("Target.detachedFromTarget", (event2) => this._onDetachedFromTarget(event2));
|
|
687
612
|
session.on("Runtime.consoleAPICalled", (event2) => {
|
|
688
613
|
const args = event2.args.map((o) => (0, import_crExecutionContext.createHandle)(worker.existingExecutionContext, o));
|
|
689
|
-
this._page.addConsoleMessage(worker, event2.type, args, (0, import_crProtocolHelper.toConsoleMessageLocation)(event2.stackTrace));
|
|
614
|
+
this._page.addConsoleMessage(worker, event2.type, args, (0, import_crProtocolHelper.toConsoleMessageLocation)(event2.stackTrace), void 0, event2.timestamp);
|
|
690
615
|
});
|
|
691
616
|
session.on("Runtime.exceptionThrown", (exception) => this._page.addPageError((0, import_crProtocolHelper.exceptionToError)(exception.exceptionDetails)));
|
|
692
617
|
}
|
|
@@ -721,7 +646,7 @@ class FrameSession {
|
|
|
721
646
|
if (!context)
|
|
722
647
|
return;
|
|
723
648
|
const values = event.args.map((arg) => (0, import_crExecutionContext.createHandle)(context, arg));
|
|
724
|
-
this._page.addConsoleMessage(null, event.type, values, (0, import_crProtocolHelper.toConsoleMessageLocation)(event.stackTrace));
|
|
649
|
+
this._page.addConsoleMessage(null, event.type, values, (0, import_crProtocolHelper.toConsoleMessageLocation)(event.stackTrace), void 0, event.timestamp);
|
|
725
650
|
}
|
|
726
651
|
async _onBindingCalled(event) {
|
|
727
652
|
const pageOrError = await this._crPage._page.waitForInitializedOrError();
|
|
@@ -763,7 +688,7 @@ class FrameSession {
|
|
|
763
688
|
lineNumber: lineNumber || 0,
|
|
764
689
|
columnNumber: 0
|
|
765
690
|
};
|
|
766
|
-
this._page.addConsoleMessage(null, level, [], location, text);
|
|
691
|
+
this._page.addConsoleMessage(null, level, [], location, text, event.entry.timestamp);
|
|
767
692
|
}
|
|
768
693
|
}
|
|
769
694
|
async _onFileChooserOpened(event) {
|
|
@@ -787,63 +712,16 @@ class FrameSession {
|
|
|
787
712
|
}
|
|
788
713
|
}
|
|
789
714
|
_onScreencastFrame(payload) {
|
|
790
|
-
this._page.throttleScreencastFrameAck(() => {
|
|
791
|
-
this._client.send("Page.screencastFrameAck", { sessionId: payload.sessionId }).catch(() => {
|
|
792
|
-
});
|
|
793
|
-
});
|
|
794
715
|
const buffer = Buffer.from(payload.data, "base64");
|
|
795
|
-
this._page.
|
|
716
|
+
this._page.screencast.onScreencastFrame({
|
|
796
717
|
buffer,
|
|
797
|
-
frameSwapWallTime: payload.metadata.timestamp ? payload.metadata.timestamp * 1e3 :
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
})
|
|
801
|
-
|
|
802
|
-
async _createVideoRecorder(screencastId, options) {
|
|
803
|
-
(0, import_assert.assert)(!this._screencastId);
|
|
804
|
-
const ffmpegPath = import_registry.registry.findExecutable("ffmpeg").executablePathOrDie(this._page.browserContext._browser.sdkLanguage());
|
|
805
|
-
this._videoRecorder = await import_videoRecorder.VideoRecorder.launch(this._crPage._page, ffmpegPath, options);
|
|
806
|
-
this._screencastId = screencastId;
|
|
807
|
-
}
|
|
808
|
-
async _startVideoRecording(options) {
|
|
809
|
-
const screencastId = this._screencastId;
|
|
810
|
-
(0, import_assert.assert)(screencastId);
|
|
811
|
-
this._page.once(import_page.Page.Events.Close, () => this._stopVideoRecording().catch(() => {
|
|
812
|
-
}));
|
|
813
|
-
const gotFirstFrame = new Promise((f) => this._client.once("Page.screencastFrame", f));
|
|
814
|
-
await this._startScreencast(this._videoRecorder, {
|
|
815
|
-
format: "jpeg",
|
|
816
|
-
quality: 90,
|
|
817
|
-
maxWidth: options.width,
|
|
818
|
-
maxHeight: options.height
|
|
819
|
-
});
|
|
820
|
-
gotFirstFrame.then(() => {
|
|
821
|
-
this._crPage._browserContext._browser._videoStarted(this._crPage._browserContext, screencastId, options.outputFile, this._crPage._page.waitForInitializedOrError());
|
|
718
|
+
frameSwapWallTime: payload.metadata.timestamp ? payload.metadata.timestamp * 1e3 : Date.now(),
|
|
719
|
+
viewportWidth: payload.metadata.deviceWidth,
|
|
720
|
+
viewportHeight: payload.metadata.deviceHeight
|
|
721
|
+
}, () => {
|
|
722
|
+
this._client._sendMayFail("Page.screencastFrameAck", { sessionId: payload.sessionId });
|
|
822
723
|
});
|
|
823
724
|
}
|
|
824
|
-
async _stopVideoRecording() {
|
|
825
|
-
if (!this._screencastId)
|
|
826
|
-
return;
|
|
827
|
-
const screencastId = this._screencastId;
|
|
828
|
-
this._screencastId = null;
|
|
829
|
-
const recorder = this._videoRecorder;
|
|
830
|
-
this._videoRecorder = null;
|
|
831
|
-
await this._stopScreencast(recorder);
|
|
832
|
-
await recorder.stop().catch(() => {
|
|
833
|
-
});
|
|
834
|
-
const video = this._crPage._browserContext._browser._takeVideo(screencastId);
|
|
835
|
-
video?.reportFinished();
|
|
836
|
-
}
|
|
837
|
-
async _startScreencast(client, options = {}) {
|
|
838
|
-
this._screencastClients.add(client);
|
|
839
|
-
if (this._screencastClients.size === 1)
|
|
840
|
-
await this._client.send("Page.startScreencast", options);
|
|
841
|
-
}
|
|
842
|
-
async _stopScreencast(client) {
|
|
843
|
-
this._screencastClients.delete(client);
|
|
844
|
-
if (!this._screencastClients.size)
|
|
845
|
-
await this._client._sendMayFail("Page.stopScreencast");
|
|
846
|
-
}
|
|
847
725
|
async _updateGeolocation(initial) {
|
|
848
726
|
const geolocation = this._crPage._browserContext._options.geolocation;
|
|
849
727
|
if (!initial || geolocation)
|
|
@@ -925,10 +803,12 @@ class FrameSession {
|
|
|
925
803
|
}
|
|
926
804
|
async _updateUserAgent() {
|
|
927
805
|
const options = this._crPage._browserContext._options;
|
|
806
|
+
const { navigatorPlatform, userAgentMetadata } = (0, import_browserContext.calculateUserAgentEmulation)(options);
|
|
928
807
|
await this._client.send("Emulation.setUserAgentOverride", {
|
|
929
808
|
userAgent: options.userAgent || "",
|
|
930
809
|
acceptLanguage: options.locale,
|
|
931
|
-
|
|
810
|
+
platform: navigatorPlatform,
|
|
811
|
+
userAgentMetadata
|
|
932
812
|
});
|
|
933
813
|
}
|
|
934
814
|
async _setDefaultFontFamilies(session) {
|
|
@@ -943,10 +823,20 @@ class FrameSession {
|
|
|
943
823
|
});
|
|
944
824
|
}
|
|
945
825
|
async _evaluateOnNewDocument(initScript, world, runImmediately) {
|
|
946
|
-
this.
|
|
826
|
+
const worldName = world === "utility" ? this._crPage.utilityWorldName : void 0;
|
|
827
|
+
const { identifier } = await this._client.send("Page.addScriptToEvaluateOnNewDocument", { source: initScript.source, worldName, runImmediately });
|
|
828
|
+
this._initScriptIds.set(initScript, identifier);
|
|
947
829
|
}
|
|
948
830
|
async _removeEvaluatesOnNewDocument(initScripts) {
|
|
949
|
-
|
|
831
|
+
const ids = [];
|
|
832
|
+
for (const script of initScripts) {
|
|
833
|
+
const id = this._initScriptIds.get(script);
|
|
834
|
+
if (id)
|
|
835
|
+
ids.push(id);
|
|
836
|
+
this._initScriptIds.delete(script);
|
|
837
|
+
}
|
|
838
|
+
await Promise.all(ids.map((identifier) => this._client.send("Page.removeScriptToEvaluateOnNewDocument", { identifier }).catch(() => {
|
|
839
|
+
})));
|
|
950
840
|
}
|
|
951
841
|
async exposePlaywrightBinding() {
|
|
952
842
|
await this._client.send("Runtime.addBinding", { name: import_page.PageBinding.kBindingName });
|
|
@@ -1046,39 +936,6 @@ class FrameSession {
|
|
|
1046
936
|
throw new Error(dom.kUnableToAdoptErrorMessage);
|
|
1047
937
|
return (0, import_crExecutionContext.createHandle)(to, result.object).asElement();
|
|
1048
938
|
}
|
|
1049
|
-
async _initBinding(binding = import_page.PageBinding) {
|
|
1050
|
-
var result = await this._client._sendMayFail("Page.createIsolatedWorld", {
|
|
1051
|
-
frameId: this._targetId,
|
|
1052
|
-
grantUniveralAccess: true,
|
|
1053
|
-
worldName: "utility"
|
|
1054
|
-
});
|
|
1055
|
-
if (!result) return;
|
|
1056
|
-
var isolatedContextId = result.executionContextId;
|
|
1057
|
-
var globalThis = await this._client._sendMayFail("Runtime.evaluate", {
|
|
1058
|
-
expression: "globalThis",
|
|
1059
|
-
serializationOptions: { serialization: "idOnly" }
|
|
1060
|
-
});
|
|
1061
|
-
if (!globalThis) return;
|
|
1062
|
-
var globalThisObjId = globalThis["result"]["objectId"];
|
|
1063
|
-
var mainContextId = parseInt(globalThisObjId.split(".")[1], 10);
|
|
1064
|
-
await Promise.all([
|
|
1065
|
-
this._client._sendMayFail("Runtime.addBinding", { name: binding.name }),
|
|
1066
|
-
this._client._sendMayFail("Runtime.addBinding", { name: binding.name, executionContextId: mainContextId }),
|
|
1067
|
-
this._client._sendMayFail("Runtime.addBinding", { name: binding.name, executionContextId: isolatedContextId })
|
|
1068
|
-
// this._client._sendMayFail("Runtime.evaluate", { expression: binding.source, contextId: mainContextId, awaitPromise: true })
|
|
1069
|
-
]);
|
|
1070
|
-
this._exposedBindingNames.push(binding.name);
|
|
1071
|
-
this._exposedBindingScripts.push(binding.source);
|
|
1072
|
-
await this._crPage.addInitScript(binding.source);
|
|
1073
|
-
}
|
|
1074
|
-
async _removeExposedBindings() {
|
|
1075
|
-
const toRetain = [];
|
|
1076
|
-
const toRemove = [];
|
|
1077
|
-
for (const name of this._exposedBindingNames)
|
|
1078
|
-
(name.startsWith("__pw_") ? toRetain : toRemove).push(name);
|
|
1079
|
-
this._exposedBindingNames = toRetain;
|
|
1080
|
-
await Promise.all(toRemove.map((name) => this._client.send("Runtime.removeBinding", { name })));
|
|
1081
|
-
}
|
|
1082
939
|
}
|
|
1083
940
|
async function emulateLocale(session, locale) {
|
|
1084
941
|
try {
|
|
@@ -1100,49 +957,6 @@ async function emulateTimezone(session, timezoneId) {
|
|
|
1100
957
|
throw exception;
|
|
1101
958
|
}
|
|
1102
959
|
}
|
|
1103
|
-
function calculateUserAgentMetadata(options) {
|
|
1104
|
-
const ua = options.userAgent;
|
|
1105
|
-
if (!ua)
|
|
1106
|
-
return void 0;
|
|
1107
|
-
const metadata = {
|
|
1108
|
-
mobile: !!options.isMobile,
|
|
1109
|
-
model: "",
|
|
1110
|
-
architecture: "x86",
|
|
1111
|
-
platform: "Windows",
|
|
1112
|
-
platformVersion: ""
|
|
1113
|
-
};
|
|
1114
|
-
const androidMatch = ua.match(/Android (\d+(\.\d+)?(\.\d+)?)/);
|
|
1115
|
-
const iPhoneMatch = ua.match(/iPhone OS (\d+(_\d+)?)/);
|
|
1116
|
-
const iPadMatch = ua.match(/iPad; CPU OS (\d+(_\d+)?)/);
|
|
1117
|
-
const macOSMatch = ua.match(/Mac OS X (\d+(_\d+)?(_\d+)?)/);
|
|
1118
|
-
const windowsMatch = ua.match(/Windows\D+(\d+(\.\d+)?(\.\d+)?)/);
|
|
1119
|
-
if (androidMatch) {
|
|
1120
|
-
metadata.platform = "Android";
|
|
1121
|
-
metadata.platformVersion = androidMatch[1];
|
|
1122
|
-
metadata.architecture = "arm";
|
|
1123
|
-
} else if (iPhoneMatch) {
|
|
1124
|
-
metadata.platform = "iOS";
|
|
1125
|
-
metadata.platformVersion = iPhoneMatch[1];
|
|
1126
|
-
metadata.architecture = "arm";
|
|
1127
|
-
} else if (iPadMatch) {
|
|
1128
|
-
metadata.platform = "iOS";
|
|
1129
|
-
metadata.platformVersion = iPadMatch[1];
|
|
1130
|
-
metadata.architecture = "arm";
|
|
1131
|
-
} else if (macOSMatch) {
|
|
1132
|
-
metadata.platform = "macOS";
|
|
1133
|
-
metadata.platformVersion = macOSMatch[1];
|
|
1134
|
-
if (!ua.includes("Intel"))
|
|
1135
|
-
metadata.architecture = "arm";
|
|
1136
|
-
} else if (windowsMatch) {
|
|
1137
|
-
metadata.platform = "Windows";
|
|
1138
|
-
metadata.platformVersion = windowsMatch[1];
|
|
1139
|
-
} else if (ua.toLowerCase().includes("linux")) {
|
|
1140
|
-
metadata.platform = "Linux";
|
|
1141
|
-
}
|
|
1142
|
-
if (ua.includes("ARM"))
|
|
1143
|
-
metadata.architecture = "arm";
|
|
1144
|
-
return metadata;
|
|
1145
|
-
}
|
|
1146
960
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1147
961
|
0 && (module.exports = {
|
|
1148
962
|
CRPage
|
|
@@ -45,13 +45,14 @@ class CRServiceWorker extends import_page.Worker {
|
|
|
45
45
|
this.browserContext = browserContext;
|
|
46
46
|
if (!process.env.PLAYWRIGHT_DISABLE_SERVICE_WORKER_NETWORK)
|
|
47
47
|
this._networkManager = new import_crNetworkManager.CRNetworkManager(null, this);
|
|
48
|
-
session.
|
|
48
|
+
session.on("Inspector.targetCrashed", () => this._prepareContextForRestart());
|
|
49
|
+
session.on("Runtime.executionContextCreated", (event) => {
|
|
49
50
|
this.createExecutionContext(new import_crExecutionContext.CRExecutionContext(session, event.context));
|
|
51
|
+
if (this.browserContext._browser.majorVersion() < 143)
|
|
52
|
+
this.workerScriptLoaded();
|
|
50
53
|
});
|
|
51
54
|
if (this.browserContext._browser.majorVersion() >= 143)
|
|
52
55
|
session.on("Inspector.workerScriptLoaded", () => this.workerScriptLoaded());
|
|
53
|
-
else
|
|
54
|
-
this.workerScriptLoaded();
|
|
55
56
|
if (this._networkManager && this._isNetworkInspectionEnabled()) {
|
|
56
57
|
this.updateRequestInterception();
|
|
57
58
|
this.updateExtraHTTPHeaders();
|
|
@@ -69,24 +70,16 @@ class CRServiceWorker extends import_page.Worker {
|
|
|
69
70
|
if (!this.existingExecutionContext || process.env.PLAYWRIGHT_DISABLE_SERVICE_WORKER_CONSOLE)
|
|
70
71
|
return;
|
|
71
72
|
const args = event.args.map((o) => (0, import_crExecutionContext.createHandle)(this.existingExecutionContext, o));
|
|
72
|
-
const message = new import_console.ConsoleMessage(null, this, event.type, void 0, args, (0, import_crProtocolHelper.toConsoleMessageLocation)(event.stackTrace));
|
|
73
|
+
const message = new import_console.ConsoleMessage(null, this, event.type, void 0, args, (0, import_crProtocolHelper.toConsoleMessageLocation)(event.stackTrace), event.timestamp);
|
|
73
74
|
this.browserContext.emit(import_browserContext.BrowserContext.Events.Console, message);
|
|
74
75
|
});
|
|
76
|
+
session.send("Runtime.enable", {}).catch((e) => {
|
|
77
|
+
});
|
|
75
78
|
session.send("Runtime.runIfWaitingForDebugger").catch((e) => {
|
|
76
79
|
});
|
|
77
80
|
session.on("Inspector.targetReloadedAfterCrash", () => {
|
|
78
81
|
session._sendMayFail("Runtime.runIfWaitingForDebugger", {});
|
|
79
82
|
});
|
|
80
|
-
session._sendMayFail("Runtime.evaluate", {
|
|
81
|
-
expression: "globalThis",
|
|
82
|
-
serializationOptions: { serialization: "idOnly" }
|
|
83
|
-
}).then((globalThis) => {
|
|
84
|
-
if (globalThis && globalThis.result) {
|
|
85
|
-
var globalThisObjId = globalThis.result.objectId;
|
|
86
|
-
var executionContextId = parseInt(globalThisObjId.split(".")[1], 10);
|
|
87
|
-
this.createExecutionContext(new import_crExecutionContext.CRExecutionContext(session, { id: executionContextId }));
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
83
|
}
|
|
91
84
|
didClose() {
|
|
92
85
|
this._networkManager?.removeSession(this._session);
|