patchright-core 1.52.4 → 1.55.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 +65 -123
- package/bin/reinstall_chrome_beta_mac.sh +1 -1
- package/bin/reinstall_chrome_stable_mac.sh +1 -1
- package/bin/reinstall_msedge_beta_mac.sh +1 -1
- package/bin/reinstall_msedge_dev_mac.sh +1 -1
- package/bin/reinstall_msedge_stable_mac.sh +1 -1
- package/browsers.json +14 -14
- package/index.js +1 -1
- package/lib/androidServerImpl.js +4 -2
- package/lib/browserServerImpl.js +47 -12
- package/lib/cli/program.js +116 -50
- package/lib/cli/programWithTestStub.js +1 -1
- package/lib/client/android.js +30 -34
- package/lib/client/browser.js +54 -17
- package/lib/client/browserContext.js +67 -71
- package/lib/client/browserType.js +25 -34
- package/lib/client/channelOwner.js +20 -24
- package/lib/client/connection.js +6 -10
- package/lib/client/electron.js +8 -3
- package/lib/client/elementHandle.js +18 -21
- package/lib/client/fetch.js +5 -3
- package/lib/client/frame.js +57 -35
- package/lib/client/input.js +3 -1
- package/lib/client/jsHandle.js +4 -0
- package/lib/client/localUtils.js +0 -1
- package/lib/client/locator.js +32 -28
- package/lib/client/network.js +5 -12
- package/lib/client/page.js +32 -32
- package/lib/client/playwright.js +6 -16
- package/lib/client/selectors.js +18 -38
- package/lib/client/timeoutSettings.js +12 -8
- package/lib/client/tracing.js +24 -20
- package/lib/client/waiter.js +2 -2
- package/lib/client/webSocket.js +4 -22
- package/lib/generated/bindingsControllerSource.js +28 -0
- 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 +28 -0
- package/lib/generated/utilityScriptSource.js +1 -1
- package/lib/generated/webSocketMockSource.js +12 -50
- package/lib/inProcessFactory.js +9 -6
- package/lib/outofprocess.js +0 -2
- package/lib/protocol/validator.js +423 -346
- package/lib/protocol/validatorPrimitives.js +18 -4
- package/lib/remote/playwrightConnection.js +29 -166
- package/lib/remote/playwrightServer.js +233 -35
- package/lib/server/android/android.js +97 -83
- package/lib/server/android/backendAdb.js +0 -2
- package/lib/server/bidi/bidiBrowser.js +139 -73
- package/lib/server/bidi/bidiChromium.js +23 -22
- package/lib/server/bidi/bidiExecutionContext.js +2 -1
- package/lib/server/bidi/bidiFirefox.js +17 -14
- package/lib/server/bidi/bidiInput.js +22 -22
- package/lib/server/bidi/bidiNetworkManager.js +8 -11
- package/lib/server/bidi/bidiPage.js +42 -86
- package/lib/server/bidi/third_party/bidiProtocol.js +5 -133
- package/lib/server/bidi/third_party/bidiProtocolCore.js +179 -0
- package/lib/server/{dispatchers/selectorsDispatcher.js → bidi/third_party/bidiProtocolPermissions.js} +20 -18
- package/lib/server/browser.js +30 -21
- package/lib/server/browserContext.js +203 -165
- package/lib/server/browserType.js +109 -107
- package/lib/server/chromium/chromium.js +84 -69
- package/lib/server/chromium/chromiumSwitches.js +13 -20
- package/lib/server/chromium/crBrowser.js +74 -40
- package/lib/server/chromium/crConnection.js +8 -9
- package/lib/server/chromium/crCoverage.js +11 -8
- package/lib/server/chromium/crDragDrop.js +25 -20
- package/lib/server/chromium/crExecutionContext.js +2 -1
- package/lib/server/chromium/crInput.js +32 -29
- package/lib/server/chromium/crNetworkManager.js +45 -33
- package/lib/server/chromium/crPage.js +98 -73
- package/lib/server/chromium/crServiceWorker.js +13 -18
- package/lib/server/chromium/videoRecorder.js +10 -18
- package/lib/server/clock.js +51 -39
- package/lib/server/codegen/csharp.js +10 -5
- package/lib/server/codegen/java.js +1 -1
- package/lib/server/codegen/javascript.js +1 -1
- package/lib/server/codegen/jsonl.js +2 -1
- package/lib/server/codegen/language.js +22 -1
- package/lib/server/codegen/languages.js +4 -4
- package/lib/server/codegen/python.js +1 -1
- package/lib/server/cookieStore.js +3 -1
- package/lib/server/debugController.js +105 -71
- package/lib/server/debugger.js +6 -23
- package/lib/server/deviceDescriptorsSource.json +237 -127
- package/lib/server/dialog.js +50 -6
- package/lib/server/dispatchers/androidDispatcher.js +77 -62
- package/lib/server/dispatchers/artifactDispatcher.js +18 -18
- package/lib/server/dispatchers/browserContextDispatcher.js +141 -91
- package/lib/server/dispatchers/browserDispatcher.js +55 -88
- package/lib/server/dispatchers/browserTypeDispatcher.js +18 -9
- package/lib/server/dispatchers/cdpSessionDispatcher.js +4 -4
- package/lib/server/dispatchers/debugControllerDispatcher.js +12 -21
- package/lib/server/dispatchers/dialogDispatcher.js +4 -4
- package/lib/server/dispatchers/dispatcher.js +78 -53
- package/lib/server/dispatchers/electronDispatcher.js +19 -20
- package/lib/server/dispatchers/elementHandlerDispatcher.js +83 -93
- package/lib/server/dispatchers/frameDispatcher.js +99 -102
- package/lib/server/dispatchers/jsHandleDispatcher.js +21 -16
- package/lib/server/dispatchers/jsonPipeDispatcher.js +4 -4
- package/lib/server/dispatchers/localUtilsDispatcher.js +53 -59
- package/lib/server/dispatchers/networkDispatchers.js +41 -35
- package/lib/server/dispatchers/pageDispatcher.js +156 -107
- package/lib/server/dispatchers/playwrightDispatcher.js +37 -25
- package/lib/server/dispatchers/streamDispatcher.js +15 -8
- package/lib/server/dispatchers/tracingDispatcher.js +22 -13
- package/lib/server/dispatchers/webSocketRouteDispatcher.js +46 -35
- package/lib/server/dispatchers/writableStreamDispatcher.js +16 -10
- package/lib/server/dom.js +198 -266
- package/lib/server/download.js +3 -3
- package/lib/server/electron/electron.js +96 -103
- package/lib/server/electron/loader.js +1 -1
- package/lib/server/fetch.js +22 -41
- package/lib/server/fileUploadUtils.js +1 -1
- package/lib/server/firefox/ffBrowser.js +79 -55
- package/lib/server/firefox/ffExecutionContext.js +2 -1
- package/lib/server/firefox/ffInput.js +23 -23
- package/lib/server/firefox/ffNetworkManager.js +8 -6
- package/lib/server/firefox/ffPage.js +39 -36
- package/lib/server/firefox/firefox.js +9 -10
- package/lib/server/frameSelectors.js +65 -22
- package/lib/server/frames.js +516 -544
- package/lib/server/har/harRecorder.js +1 -1
- package/lib/server/har/harTracer.js +4 -2
- package/lib/server/helper.js +3 -7
- package/lib/server/index.js +0 -3
- package/lib/server/input.js +47 -54
- package/lib/server/instrumentation.js +8 -14
- package/lib/server/javascript.js +9 -17
- package/lib/server/launchApp.js +48 -30
- package/lib/server/localUtils.js +45 -38
- package/lib/server/network.js +44 -10
- package/lib/server/page.js +233 -178
- package/lib/server/pageBinding.js +6 -7
- package/lib/server/playwright.js +4 -14
- package/lib/server/progress.js +57 -49
- package/lib/server/recorder/recorderApp.js +298 -95
- package/lib/server/recorder/recorderRunner.js +23 -24
- package/lib/server/recorder/recorderSignalProcessor.js +83 -0
- package/lib/server/recorder/recorderUtils.js +67 -10
- package/lib/server/recorder.js +284 -146
- package/lib/server/registry/index.js +83 -48
- package/lib/server/registry/nativeDeps.js +175 -0
- package/lib/server/registry/oopDownloadBrowserMain.js +1 -1
- package/lib/server/screenshotter.js +84 -83
- package/lib/server/selectors.js +12 -12
- package/lib/server/socksClientCertificatesInterceptor.js +198 -136
- package/lib/server/trace/recorder/snapshotter.js +12 -19
- package/lib/server/trace/recorder/tracing.js +36 -27
- package/lib/server/trace/viewer/traceViewer.js +11 -20
- package/lib/server/transport.js +20 -22
- package/lib/server/utils/comparators.js +2 -2
- package/lib/server/utils/debug.js +3 -8
- package/lib/server/utils/debugLogger.js +8 -0
- package/lib/server/utils/hostPlatform.js +3 -1
- package/lib/server/utils/network.js +35 -25
- package/lib/server/utils/nodePlatform.js +1 -1
- package/lib/server/utils/processLauncher.js +4 -1
- package/lib/server/utils/wsServer.js +11 -17
- package/lib/server/webkit/webkit.js +5 -2
- package/lib/server/webkit/wkBrowser.js +51 -28
- package/lib/server/webkit/wkExecutionContext.js +2 -1
- package/lib/server/webkit/wkInput.js +25 -25
- package/lib/server/webkit/wkInterceptableRequest.js +1 -1
- package/lib/server/webkit/wkPage.js +80 -59
- package/lib/server/webkit/wkProvisionalPage.js +1 -1
- package/lib/server/webkit/wkWorkers.js +7 -7
- package/lib/utils/isomorphic/ariaSnapshot.js +13 -7
- package/lib/utils/isomorphic/cssParser.js +1 -2
- package/lib/utils/isomorphic/locatorGenerators.js +18 -0
- package/lib/utils/isomorphic/manualPromise.js +1 -2
- package/lib/utils/isomorphic/mimeType.js +1 -2
- package/lib/utils/isomorphic/multimap.js +1 -2
- package/lib/utils/isomorphic/oldUtilityScriptSerializers.js +248 -0
- package/lib/utils/isomorphic/protocolFormatter.js +78 -0
- package/lib/utils/isomorphic/protocolMetainfo.js +318 -0
- package/lib/utils/isomorphic/selectorParser.js +3 -4
- package/lib/utils/isomorphic/stringUtils.js +3 -24
- package/lib/utils/isomorphic/time.js +9 -4
- package/lib/utils/isomorphic/timeoutRunner.js +3 -4
- package/lib/utils/isomorphic/traceUtils.js +2 -3
- package/lib/utils/isomorphic/urlMatch.js +21 -7
- package/lib/utils/isomorphic/utilityScriptSerializers.js +208 -205
- package/lib/utils.js +8 -2
- package/lib/utilsBundleImpl/index.js +160 -150
- package/lib/vite/htmlReport/index.html +17 -17
- package/lib/vite/recorder/assets/{codeMirrorModule-CXVeovup.js → codeMirrorModule-DzQ0k89p.js} +1 -1
- package/lib/vite/recorder/assets/{index-eHBmevrY.css → index-CI4HQ-Zb.css} +1 -1
- package/lib/vite/recorder/assets/index-D7C7daHH.js +184 -0
- package/lib/vite/recorder/index.html +3 -3
- package/lib/vite/traceViewer/assets/{codeMirrorModule-_GLjJL-7.js → codeMirrorModule-Di48jgWx.js} +1 -1
- package/lib/vite/traceViewer/assets/defaultSettingsView-szBn8781.js +256 -0
- package/lib/vite/traceViewer/defaultSettingsView.DVJHpiGt.css +1 -0
- package/lib/vite/traceViewer/index.BFsek2M6.css +1 -0
- package/lib/vite/traceViewer/index.DQvXoPLL.js +2 -0
- package/lib/vite/traceViewer/index.html +6 -6
- package/lib/vite/traceViewer/sw.bundle.js +3 -3
- package/lib/vite/traceViewer/uiMode.dBV3oN9h.js +5 -0
- package/lib/vite/traceViewer/uiMode.html +4 -4
- package/lib/zipBundleImpl.js +4 -4
- package/package.json +1 -1
- package/types/protocol.d.ts +712 -107
- package/types/types.d.ts +148 -37
- package/lib/generated/consoleApiSource.js +0 -28
- package/lib/protocol/debug.js +0 -211
- package/lib/server/recorder/contextRecorder.js +0 -286
- package/lib/server/recorder/recorderCollection.js +0 -116
- package/lib/server/recorder/recorderFrontend.js +0 -16
- package/lib/server/storageScript.js +0 -154
- package/lib/server/timeoutSettings.js +0 -89
- package/lib/utils/isomorphic/builtins.js +0 -86
- package/lib/vite/recorder/assets/index-BsWQsSGl.js +0 -184
- package/lib/vite/traceViewer/assets/defaultSettingsView-DtCQiGHe.js +0 -265
- package/lib/vite/traceViewer/defaultSettingsView.QdHITyLI.css +0 -1
- package/lib/vite/traceViewer/index.CFOW-Ezb.css +0 -1
- package/lib/vite/traceViewer/index.cFZzK9RN.js +0 -2
- package/lib/vite/traceViewer/uiMode.XVPIqBeS.js +0 -5
|
@@ -43,7 +43,6 @@ var frames = __toESM(require("../frames"));
|
|
|
43
43
|
var import_helper = require("../helper");
|
|
44
44
|
var network = __toESM(require("../network"));
|
|
45
45
|
var import_page = require("../page");
|
|
46
|
-
var import_page2 = require("../page");
|
|
47
46
|
var import_registry = require("../registry");
|
|
48
47
|
var import_crAccessibility = require("./crAccessibility");
|
|
49
48
|
var import_crBrowser = require("./crBrowser");
|
|
@@ -59,7 +58,6 @@ var import_videoRecorder = require("./videoRecorder");
|
|
|
59
58
|
var import_browserContext = require("../browserContext");
|
|
60
59
|
var import_errors = require("../errors");
|
|
61
60
|
var import_protocolError = require("../protocolError");
|
|
62
|
-
const UTILITY_WORLD_NAME = "__playwright_utility_world__";
|
|
63
61
|
class CRPage {
|
|
64
62
|
constructor(client, targetId, browserContext, opener, bits) {
|
|
65
63
|
this._sessions = /* @__PURE__ */ new Map();
|
|
@@ -79,7 +77,8 @@ class CRPage {
|
|
|
79
77
|
this._pdf = new import_crPdf.CRPDF(client);
|
|
80
78
|
this._coverage = new import_crCoverage.CRCoverage(client);
|
|
81
79
|
this._browserContext = browserContext;
|
|
82
|
-
this._page = new
|
|
80
|
+
this._page = new import_page.Page(this, browserContext);
|
|
81
|
+
this.utilityWorldName = `__playwright_utility_world_${this._page.guid}`;
|
|
83
82
|
this._networkManager = new import_crNetworkManager.CRNetworkManager(this._page, null);
|
|
84
83
|
this.updateOffline();
|
|
85
84
|
this.updateExtraHTTPHeaders();
|
|
@@ -92,7 +91,7 @@ class CRPage {
|
|
|
92
91
|
const features = opener._nextWindowOpenPopupFeatures.shift() || [];
|
|
93
92
|
const viewportSize = import_helper.helper.getViewportSizeFromWindowFeatures(features);
|
|
94
93
|
if (viewportSize)
|
|
95
|
-
this._page.
|
|
94
|
+
this._page.setEmulatedSizeFromWindowOpen({ viewport: viewportSize, screen: viewportSize });
|
|
96
95
|
}
|
|
97
96
|
const createdEvent = this._isBackgroundPage ? import_crBrowser.CRBrowserContext.CREvents.BackgroundPage : import_browserContext.BrowserContext.Events.Page;
|
|
98
97
|
this._mainFrameSession._initialize(bits.hasUIWindow).then(
|
|
@@ -101,7 +100,7 @@ class CRPage {
|
|
|
101
100
|
);
|
|
102
101
|
}
|
|
103
102
|
static mainFrameSession(page) {
|
|
104
|
-
const crPage = page.
|
|
103
|
+
const crPage = page.delegate;
|
|
105
104
|
return crPage._mainFrameSession;
|
|
106
105
|
}
|
|
107
106
|
async _forAllFrameSessions(cb) {
|
|
@@ -198,8 +197,11 @@ class CRPage {
|
|
|
198
197
|
this._page.initScripts.push(initScript);
|
|
199
198
|
await this._forAllFrameSessions((frame) => frame._evaluateOnNewDocument(initScript, world));
|
|
200
199
|
}
|
|
201
|
-
async
|
|
202
|
-
await this._forAllFrameSessions((frame) => frame.
|
|
200
|
+
async exposePlaywrightBinding() {
|
|
201
|
+
await this._forAllFrameSessions((frame) => frame.exposePlaywrightBinding());
|
|
202
|
+
}
|
|
203
|
+
async removeInitScripts(initScripts) {
|
|
204
|
+
await this._forAllFrameSessions((frame) => frame._removeEvaluatesOnNewDocument(initScripts));
|
|
203
205
|
}
|
|
204
206
|
async closePage(runBeforeUnload) {
|
|
205
207
|
if (runBeforeUnload)
|
|
@@ -211,7 +213,7 @@ class CRPage {
|
|
|
211
213
|
await this._mainFrameSession._client.send("Emulation.setDefaultBackgroundColorOverride", { color });
|
|
212
214
|
}
|
|
213
215
|
async takeScreenshot(progress, format, documentRect, viewportRect, quality, fitsViewport, scale) {
|
|
214
|
-
const { visualViewport } = await this._mainFrameSession._client.send("Page.getLayoutMetrics");
|
|
216
|
+
const { visualViewport } = await progress.race(this._mainFrameSession._client.send("Page.getLayoutMetrics"));
|
|
215
217
|
if (!documentRect) {
|
|
216
218
|
documentRect = {
|
|
217
219
|
x: visualViewport.pageX + viewportRect.x,
|
|
@@ -227,8 +229,7 @@ class CRPage {
|
|
|
227
229
|
const deviceScaleFactor = this._browserContext._options.deviceScaleFactor || 1;
|
|
228
230
|
clip.scale /= deviceScaleFactor;
|
|
229
231
|
}
|
|
230
|
-
progress.
|
|
231
|
-
const result = await this._mainFrameSession._client.send("Page.captureScreenshot", { format, quality, clip, captureBeyondViewport: !fitsViewport });
|
|
232
|
+
const result = await progress.race(this._mainFrameSession._client.send("Page.captureScreenshot", { format, quality, clip, captureBeyondViewport: !fitsViewport }));
|
|
232
233
|
return Buffer.from(result.data, "base64");
|
|
233
234
|
}
|
|
234
235
|
async getContentFrame(handle) {
|
|
@@ -281,8 +282,8 @@ class CRPage {
|
|
|
281
282
|
await this._mainFrameSession._client.send("Page.enable").catch((e) => {
|
|
282
283
|
});
|
|
283
284
|
}
|
|
284
|
-
async resetForReuse() {
|
|
285
|
-
await this.rawMouse.move(-1, -1, "none", /* @__PURE__ */ new Set(), /* @__PURE__ */ new Set(), true);
|
|
285
|
+
async resetForReuse(progress) {
|
|
286
|
+
await this.rawMouse.move(progress, -1, -1, "none", /* @__PURE__ */ new Set(), /* @__PURE__ */ new Set(), true);
|
|
286
287
|
}
|
|
287
288
|
async pdf(options) {
|
|
288
289
|
return this._pdf.generate(options);
|
|
@@ -332,8 +333,8 @@ class FrameSession {
|
|
|
332
333
|
this._videoRecorder = null;
|
|
333
334
|
this._screencastId = null;
|
|
334
335
|
this._screencastClients = /* @__PURE__ */ new Set();
|
|
335
|
-
this._evaluateOnNewDocumentIdentifiers = [];
|
|
336
336
|
this._workerSessions = /* @__PURE__ */ new Map();
|
|
337
|
+
this._initScriptIds = /* @__PURE__ */ new Map();
|
|
337
338
|
this._exposedBindingNames = [];
|
|
338
339
|
this._evaluateOnNewDocumentScripts = [];
|
|
339
340
|
this._parsedExecutionContextIds = [];
|
|
@@ -383,13 +384,12 @@ class FrameSession {
|
|
|
383
384
|
]);
|
|
384
385
|
}
|
|
385
386
|
async _initialize(hasUIWindow) {
|
|
386
|
-
|
|
387
|
-
if (!isSettingStorageState && hasUIWindow && !this._crPage._browserContext._browser.isClank() && !this._crPage._browserContext._options.noDefaultViewport) {
|
|
387
|
+
if (!this._page.isStorageStatePage && hasUIWindow && !this._crPage._browserContext._browser.isClank() && !this._crPage._browserContext._options.noDefaultViewport) {
|
|
388
388
|
const { windowId } = await this._client.send("Browser.getWindowForTarget");
|
|
389
389
|
this._windowId = windowId;
|
|
390
390
|
}
|
|
391
391
|
let screencastOptions;
|
|
392
|
-
if (!
|
|
392
|
+
if (!this._page.isStorageStatePage && this._isMainFrame() && this._crPage._browserContext._options.recordVideo && hasUIWindow) {
|
|
393
393
|
const screencastId = (0, import_crypto2.createGuid)();
|
|
394
394
|
const outputFile = import_path.default.join(this._crPage._browserContext._options.recordVideo.dir, screencastId + ".webm");
|
|
395
395
|
screencastOptions = {
|
|
@@ -423,9 +423,9 @@ class FrameSession {
|
|
|
423
423
|
this._eventListeners.push(import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.lifecycleEvent", (event) => this._onLifecycleEvent(event)));
|
|
424
424
|
});
|
|
425
425
|
} else {
|
|
426
|
-
const localFrames = this._isMainFrame() ? this._page.frames() : [this._page.
|
|
426
|
+
const localFrames = this._isMainFrame() ? this._page.frames() : [this._page.frameManager.frame(this._targetId)];
|
|
427
427
|
for (const frame of localFrames) {
|
|
428
|
-
this._page.
|
|
428
|
+
this._page.frameManager.frame(frame._id)._context("utility");
|
|
429
429
|
for (const binding of this._crPage._browserContext._pageBindings.values())
|
|
430
430
|
frame.evaluateExpression(binding.source).catch((e) => {
|
|
431
431
|
});
|
|
@@ -441,12 +441,23 @@ class FrameSession {
|
|
|
441
441
|
lifecycleEventsEnabled = this._client.send("Page.setLifecycleEventsEnabled", { enabled: true }),
|
|
442
442
|
this._client.send("Page.addScriptToEvaluateOnNewDocument", {
|
|
443
443
|
source: "",
|
|
444
|
-
worldName:
|
|
444
|
+
worldName: this._crPage.utilityWorldName
|
|
445
445
|
}),
|
|
446
446
|
this._crPage._networkManager.addSession(this._client, void 0, this._isMainFrame()),
|
|
447
|
-
this._client.send("Target.setAutoAttach", {
|
|
447
|
+
this._client.send("Target.setAutoAttach", {
|
|
448
|
+
autoAttach: true,
|
|
449
|
+
waitForDebuggerOnStart: true,
|
|
450
|
+
flatten: true,
|
|
451
|
+
filter: [
|
|
452
|
+
{ type: "iframe" },
|
|
453
|
+
{ type: "worker" },
|
|
454
|
+
{ type: "service_worker", exclude: !process.env.PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS }
|
|
455
|
+
]
|
|
456
|
+
})
|
|
448
457
|
];
|
|
449
|
-
if (!
|
|
458
|
+
if (!this._page.isStorageStatePage) {
|
|
459
|
+
if (this._crPage._browserContext.needsPlaywrightBinding())
|
|
460
|
+
promises.push(this.exposePlaywrightBinding());
|
|
450
461
|
if (this._isMainFrame())
|
|
451
462
|
promises.push(this._client.send("Emulation.setFocusEmulationEnabled", { enabled: true }));
|
|
452
463
|
const options = this._crPage._browserContext._options;
|
|
@@ -477,10 +488,12 @@ class FrameSession {
|
|
|
477
488
|
if (screencastOptions)
|
|
478
489
|
promises.push(this._startVideoRecording(screencastOptions));
|
|
479
490
|
}
|
|
480
|
-
if (!(this._crPage._page._pageBindings.size || this._crPage._browserContext._pageBindings.size))
|
|
491
|
+
if (!(this._crPage._page._pageBindings.size || this._crPage._browserContext._pageBindings.size))
|
|
492
|
+
promises.push(this._client.send("Runtime.runIfWaitingForDebugger"));
|
|
481
493
|
promises.push(this._firstNonInitialNavigationCommittedPromise);
|
|
482
494
|
await Promise.all(promises);
|
|
483
|
-
if (this._crPage._page._pageBindings.size || this._crPage._browserContext._pageBindings.size)
|
|
495
|
+
if (this._crPage._page._pageBindings.size || this._crPage._browserContext._pageBindings.size)
|
|
496
|
+
await this._client.send("Runtime.runIfWaitingForDebugger");
|
|
484
497
|
}
|
|
485
498
|
dispose() {
|
|
486
499
|
this._firstNonInitialNavigationCommittedReject(new import_errors.TargetClosedError());
|
|
@@ -495,7 +508,8 @@ class FrameSession {
|
|
|
495
508
|
}
|
|
496
509
|
async _navigate(frame, url, referrer) {
|
|
497
510
|
const response = await this._client.send("Page.navigate", { url, referrer, frameId: frame._id, referrerPolicy: "unsafeUrl" });
|
|
498
|
-
|
|
511
|
+
if (response.isDownload)
|
|
512
|
+
throw new frames.NavigationAbortedError(response.loaderId, "Download is starting");
|
|
499
513
|
if (response.errorText)
|
|
500
514
|
throw new frames.NavigationAbortedError(response.loaderId, `${response.errorText} at ${url}`);
|
|
501
515
|
return { newDocumentId: response.loaderId };
|
|
@@ -504,9 +518,9 @@ class FrameSession {
|
|
|
504
518
|
if (this._eventBelongsToStaleFrame(event.frameId))
|
|
505
519
|
return;
|
|
506
520
|
if (event.name === "load")
|
|
507
|
-
this._page.
|
|
521
|
+
this._page.frameManager.frameLifecycleEvent(event.frameId, "load");
|
|
508
522
|
else if (event.name === "DOMContentLoaded")
|
|
509
|
-
this._page.
|
|
523
|
+
this._page.frameManager.frameLifecycleEvent(event.frameId, "domcontentloaded");
|
|
510
524
|
await this._client._sendMayFail("Runtime.runIfWaitingForDebugger");
|
|
511
525
|
var document = await this._client._sendMayFail("DOM.getDocument");
|
|
512
526
|
if (!document) return;
|
|
@@ -518,7 +532,7 @@ class FrameSession {
|
|
|
518
532
|
for (const nodeId of query.nodeIds) await this._client._sendMayFail("DOM.removeNode", { nodeId });
|
|
519
533
|
await this._client._sendMayFail("Runtime.runIfWaitingForDebugger");
|
|
520
534
|
try {
|
|
521
|
-
await this._page.
|
|
535
|
+
await this._page.frameManager.frame(this._targetId)._context("utility");
|
|
522
536
|
} catch {
|
|
523
537
|
}
|
|
524
538
|
;
|
|
@@ -532,7 +546,7 @@ class FrameSession {
|
|
|
532
546
|
this._handleFrameTree(child);
|
|
533
547
|
}
|
|
534
548
|
_eventBelongsToStaleFrame(frameId) {
|
|
535
|
-
const frame = this._page.
|
|
549
|
+
const frame = this._page.frameManager.frame(frameId);
|
|
536
550
|
if (!frame)
|
|
537
551
|
return true;
|
|
538
552
|
const session = this._crPage._sessionForFrame(frame);
|
|
@@ -542,20 +556,20 @@ class FrameSession {
|
|
|
542
556
|
const frameSession = this._crPage._sessions.get(frameId);
|
|
543
557
|
if (frameSession && frameId !== this._targetId) {
|
|
544
558
|
frameSession._swappedIn = true;
|
|
545
|
-
const frame = this._page.
|
|
559
|
+
const frame = this._page.frameManager.frame(frameId);
|
|
546
560
|
if (frame)
|
|
547
|
-
this._page.
|
|
561
|
+
this._page.frameManager.removeChildFramesRecursively(frame);
|
|
548
562
|
return;
|
|
549
563
|
}
|
|
550
|
-
if (parentFrameId && !this._page.
|
|
564
|
+
if (parentFrameId && !this._page.frameManager.frame(parentFrameId)) {
|
|
551
565
|
return;
|
|
552
566
|
}
|
|
553
|
-
this._page.
|
|
567
|
+
this._page.frameManager.frameAttached(frameId, parentFrameId);
|
|
554
568
|
}
|
|
555
569
|
async _onFrameNavigated(framePayload, initial) {
|
|
556
570
|
if (this._eventBelongsToStaleFrame(framePayload.id))
|
|
557
571
|
return;
|
|
558
|
-
this._page.
|
|
572
|
+
this._page.frameManager.frameCommittedNewDocumentNavigation(framePayload.id, framePayload.url + (framePayload.urlFragment || ""), framePayload.name || "", framePayload.loaderId, initial);
|
|
559
573
|
if (!initial)
|
|
560
574
|
this._firstNonInitialNavigationCommittedFulfill();
|
|
561
575
|
await this._client._sendMayFail("Runtime.runIfWaitingForDebugger");
|
|
@@ -569,7 +583,7 @@ class FrameSession {
|
|
|
569
583
|
for (const nodeId of query.nodeIds) await this._client._sendMayFail("DOM.removeNode", { nodeId });
|
|
570
584
|
await this._client._sendMayFail("Runtime.runIfWaitingForDebugger");
|
|
571
585
|
try {
|
|
572
|
-
await this._page.
|
|
586
|
+
await this._page.frameManager.frame(this._targetId)._context("utility");
|
|
573
587
|
} catch {
|
|
574
588
|
}
|
|
575
589
|
;
|
|
@@ -578,28 +592,29 @@ class FrameSession {
|
|
|
578
592
|
if (this._eventBelongsToStaleFrame(payload.frameId))
|
|
579
593
|
return;
|
|
580
594
|
if (payload.disposition === "currentTab")
|
|
581
|
-
this._page.
|
|
595
|
+
this._page.frameManager.frameRequestedNavigation(payload.frameId);
|
|
582
596
|
}
|
|
583
597
|
_onFrameNavigatedWithinDocument(frameId, url) {
|
|
584
598
|
if (this._eventBelongsToStaleFrame(frameId))
|
|
585
599
|
return;
|
|
586
|
-
this._page.
|
|
600
|
+
this._page.frameManager.frameCommittedSameDocumentNavigation(frameId, url);
|
|
587
601
|
}
|
|
588
602
|
_onFrameDetached(frameId, reason) {
|
|
589
603
|
if (this._crPage._sessions.has(frameId)) {
|
|
590
604
|
return;
|
|
591
605
|
}
|
|
592
606
|
if (reason === "swap") {
|
|
593
|
-
const frame = this._page.
|
|
607
|
+
const frame = this._page.frameManager.frame(frameId);
|
|
594
608
|
if (frame)
|
|
595
|
-
this._page.
|
|
609
|
+
this._page.frameManager.removeChildFramesRecursively(frame);
|
|
596
610
|
return;
|
|
597
611
|
}
|
|
598
|
-
this._page.
|
|
612
|
+
this._page.frameManager.frameDetached(frameId);
|
|
599
613
|
}
|
|
600
614
|
_onExecutionContextCreated(contextPayload) {
|
|
601
|
-
for (const name of this._exposedBindingNames)
|
|
602
|
-
|
|
615
|
+
for (const name of this._exposedBindingNames)
|
|
616
|
+
this._client._sendMayFail("Runtime.addBinding", { name, executionContextId: contextPayload.id });
|
|
617
|
+
const frame = contextPayload.auxData ? this._page.frameManager.frame(contextPayload.auxData.frameId) : null;
|
|
603
618
|
if (contextPayload.auxData.type == "worker") throw new Error("ExecutionContext is worker");
|
|
604
619
|
if (!frame || this._eventBelongsToStaleFrame(frame._id))
|
|
605
620
|
return;
|
|
@@ -632,10 +647,10 @@ class FrameSession {
|
|
|
632
647
|
const session = this._client.createChildSession(event.sessionId);
|
|
633
648
|
if (event.targetInfo.type === "iframe") {
|
|
634
649
|
const targetId = event.targetInfo.targetId;
|
|
635
|
-
const frame = this._page.
|
|
650
|
+
const frame = this._page.frameManager.frame(targetId);
|
|
636
651
|
if (!frame)
|
|
637
652
|
return;
|
|
638
|
-
this._page.
|
|
653
|
+
this._page.frameManager.removeChildFramesRecursively(frame);
|
|
639
654
|
for (const [contextId, context] of this._contextIdToContext) {
|
|
640
655
|
if (context.frame === frame)
|
|
641
656
|
this._onExecutionContextDestroyed(contextId);
|
|
@@ -651,11 +666,11 @@ class FrameSession {
|
|
|
651
666
|
return;
|
|
652
667
|
}
|
|
653
668
|
const url = event.targetInfo.url;
|
|
654
|
-
const worker = new
|
|
655
|
-
this._page.
|
|
669
|
+
const worker = new import_page.Worker(this._page, url);
|
|
670
|
+
this._page.addWorker(event.sessionId, worker);
|
|
656
671
|
this._workerSessions.set(event.sessionId, session);
|
|
657
672
|
session.once("Runtime.executionContextCreated", async (event2) => {
|
|
658
|
-
worker.
|
|
673
|
+
worker.createExecutionContext(new import_crExecutionContext.CRExecutionContext(session, event2.context));
|
|
659
674
|
});
|
|
660
675
|
var globalThis = await session._sendMayFail("Runtime.evaluate", {
|
|
661
676
|
expression: "globalThis",
|
|
@@ -664,17 +679,25 @@ class FrameSession {
|
|
|
664
679
|
if (globalThis && globalThis.result) {
|
|
665
680
|
var globalThisObjId = globalThis.result.objectId;
|
|
666
681
|
var executionContextId = parseInt(globalThisObjId.split(".")[1], 10);
|
|
667
|
-
worker.
|
|
682
|
+
worker.createExecutionContext(new import_crExecutionContext.CRExecutionContext(session, { id: executionContextId }));
|
|
668
683
|
}
|
|
669
|
-
this._crPage._networkManager.addSession(session, this._page.
|
|
684
|
+
this._crPage._networkManager.addSession(session, this._page.frameManager.frame(this._targetId) ?? void 0).catch(() => {
|
|
670
685
|
});
|
|
671
686
|
session._sendMayFail("Runtime.runIfWaitingForDebugger");
|
|
672
|
-
session._sendMayFail("Target.setAutoAttach", {
|
|
687
|
+
session._sendMayFail("Target.setAutoAttach", {
|
|
688
|
+
autoAttach: true,
|
|
689
|
+
waitForDebuggerOnStart: true,
|
|
690
|
+
flatten: true,
|
|
691
|
+
filter: [
|
|
692
|
+
{ type: "worker" },
|
|
693
|
+
{ type: "service_worker", exclude: !process.env.PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS }
|
|
694
|
+
]
|
|
695
|
+
});
|
|
673
696
|
session.on("Target.attachedToTarget", (event2) => this._onAttachedToTarget(event2));
|
|
674
697
|
session.on("Target.detachedFromTarget", (event2) => this._onDetachedFromTarget(event2));
|
|
675
698
|
session.on("Runtime.consoleAPICalled", (event2) => {
|
|
676
|
-
const args = event2.args.map((o) => (0, import_crExecutionContext.createHandle)(worker.
|
|
677
|
-
this._page.
|
|
699
|
+
const args = event2.args.map((o) => (0, import_crExecutionContext.createHandle)(worker.existingExecutionContext, o));
|
|
700
|
+
this._page.addConsoleMessage(event2.type, args, (0, import_crProtocolHelper.toConsoleMessageLocation)(event2.stackTrace));
|
|
678
701
|
});
|
|
679
702
|
session.on("Runtime.exceptionThrown", (exception) => this._page.emitOnContextOnceInitialized(import_browserContext.BrowserContext.Events.PageError, (0, import_crProtocolHelper.exceptionToError)(exception.exceptionDetails), this._page));
|
|
680
703
|
}
|
|
@@ -682,7 +705,7 @@ class FrameSession {
|
|
|
682
705
|
const workerSession = this._workerSessions.get(event.sessionId);
|
|
683
706
|
if (workerSession) {
|
|
684
707
|
workerSession.dispose();
|
|
685
|
-
this._page.
|
|
708
|
+
this._page.removeWorker(event.sessionId);
|
|
686
709
|
return;
|
|
687
710
|
}
|
|
688
711
|
const childFrameSession = this._crPage._sessions.get(event.targetId);
|
|
@@ -694,7 +717,7 @@ class FrameSession {
|
|
|
694
717
|
}
|
|
695
718
|
this._client.send("Page.enable").catch((e) => null).then(() => {
|
|
696
719
|
if (!childFrameSession._swappedIn)
|
|
697
|
-
this._page.
|
|
720
|
+
this._page.frameManager.frameDetached(event.targetId);
|
|
698
721
|
childFrameSession.dispose();
|
|
699
722
|
});
|
|
700
723
|
}
|
|
@@ -709,26 +732,26 @@ class FrameSession {
|
|
|
709
732
|
if (!context)
|
|
710
733
|
return;
|
|
711
734
|
const values = event.args.map((arg) => (0, import_crExecutionContext.createHandle)(context, arg));
|
|
712
|
-
this._page.
|
|
735
|
+
this._page.addConsoleMessage(event.type, values, (0, import_crProtocolHelper.toConsoleMessageLocation)(event.stackTrace));
|
|
713
736
|
}
|
|
714
737
|
async _onBindingCalled(event) {
|
|
715
738
|
const pageOrError = await this._crPage._page.waitForInitializedOrError();
|
|
716
739
|
if (!(pageOrError instanceof Error)) {
|
|
717
740
|
const context = this._contextIdToContext.get(event.executionContextId);
|
|
718
|
-
if (context)
|
|
719
|
-
|
|
741
|
+
if (context)
|
|
742
|
+
await this._page.onBindingCalled(event.payload, context);
|
|
720
743
|
}
|
|
721
744
|
}
|
|
722
745
|
_onDialog(event) {
|
|
723
|
-
if (!this._page.
|
|
746
|
+
if (!this._page.frameManager.frame(this._targetId))
|
|
724
747
|
return;
|
|
725
|
-
this._page.
|
|
748
|
+
this._page.browserContext.dialogManager.dialogDidOpen(new dialog.Dialog(
|
|
726
749
|
this._page,
|
|
727
750
|
event.type,
|
|
728
751
|
event.message,
|
|
729
752
|
async (accept, promptText) => {
|
|
730
753
|
if (this._isMainFrame() && event.type === "beforeunload" && !accept)
|
|
731
|
-
this._page.
|
|
754
|
+
this._page.frameManager.frameAbortedNavigation(this._page.mainFrame()._id, "navigation cancelled by beforeunload dialog");
|
|
732
755
|
await this._client.send("Page.handleJavaScriptDialog", { accept, promptText });
|
|
733
756
|
},
|
|
734
757
|
event.defaultPrompt
|
|
@@ -751,13 +774,13 @@ class FrameSession {
|
|
|
751
774
|
lineNumber: lineNumber || 0,
|
|
752
775
|
columnNumber: 0
|
|
753
776
|
};
|
|
754
|
-
this._page.
|
|
777
|
+
this._page.addConsoleMessage(level, [], location, text);
|
|
755
778
|
}
|
|
756
779
|
}
|
|
757
780
|
async _onFileChooserOpened(event) {
|
|
758
781
|
if (!event.backendNodeId)
|
|
759
782
|
return;
|
|
760
|
-
const frame = this._page.
|
|
783
|
+
const frame = this._page.frameManager.frame(event.frameId);
|
|
761
784
|
if (!frame)
|
|
762
785
|
return;
|
|
763
786
|
let handle;
|
|
@@ -780,7 +803,7 @@ class FrameSession {
|
|
|
780
803
|
});
|
|
781
804
|
});
|
|
782
805
|
const buffer = Buffer.from(payload.data, "base64");
|
|
783
|
-
this._page.emit(
|
|
806
|
+
this._page.emit(import_page.Page.Events.ScreencastFrame, {
|
|
784
807
|
buffer,
|
|
785
808
|
frameSwapWallTime: payload.metadata.timestamp ? payload.metadata.timestamp * 1e3 : void 0,
|
|
786
809
|
width: payload.metadata.deviceWidth,
|
|
@@ -789,14 +812,14 @@ class FrameSession {
|
|
|
789
812
|
}
|
|
790
813
|
async _createVideoRecorder(screencastId, options) {
|
|
791
814
|
(0, import_assert.assert)(!this._screencastId);
|
|
792
|
-
const ffmpegPath = import_registry.registry.findExecutable("ffmpeg").executablePathOrDie(this._page.
|
|
815
|
+
const ffmpegPath = import_registry.registry.findExecutable("ffmpeg").executablePathOrDie(this._page.browserContext._browser.sdkLanguage());
|
|
793
816
|
this._videoRecorder = await import_videoRecorder.VideoRecorder.launch(this._crPage._page, ffmpegPath, options);
|
|
794
817
|
this._screencastId = screencastId;
|
|
795
818
|
}
|
|
796
819
|
async _startVideoRecording(options) {
|
|
797
820
|
const screencastId = this._screencastId;
|
|
798
821
|
(0, import_assert.assert)(screencastId);
|
|
799
|
-
this._page.once(
|
|
822
|
+
this._page.once(import_page.Page.Events.Close, () => this._stopVideoRecording().catch(() => {
|
|
800
823
|
}));
|
|
801
824
|
const gotFirstFrame = new Promise((f) => this._client.once("Page.screencastFrame", f));
|
|
802
825
|
await this._startScreencast(this._videoRecorder, {
|
|
@@ -843,7 +866,7 @@ class FrameSession {
|
|
|
843
866
|
(0, import_assert.assert)(this._isMainFrame());
|
|
844
867
|
const options = this._crPage._browserContext._options;
|
|
845
868
|
const emulatedSize = this._page.emulatedSize();
|
|
846
|
-
if (emulatedSize
|
|
869
|
+
if (!emulatedSize)
|
|
847
870
|
return;
|
|
848
871
|
const viewportSize = emulatedSize.viewport;
|
|
849
872
|
const screenSize = emulatedSize.screen;
|
|
@@ -860,9 +883,7 @@ class FrameSession {
|
|
|
860
883
|
};
|
|
861
884
|
if (JSON.stringify(this._metricsOverride) === JSON.stringify(metricsOverride))
|
|
862
885
|
return;
|
|
863
|
-
const promises = [
|
|
864
|
-
this._client.send("Emulation.setDeviceMetricsOverride", metricsOverride)
|
|
865
|
-
];
|
|
886
|
+
const promises = [];
|
|
866
887
|
if (!preserveWindowBoundaries && this._windowId) {
|
|
867
888
|
let insets = { width: 0, height: 0 };
|
|
868
889
|
if (this._crPage._browserContext._browser.options.headful) {
|
|
@@ -882,6 +903,7 @@ class FrameSession {
|
|
|
882
903
|
height: viewportSize.height + insets.height
|
|
883
904
|
}));
|
|
884
905
|
}
|
|
906
|
+
promises.push(this._client.send("Emulation.setDeviceMetricsOverride", metricsOverride));
|
|
885
907
|
await Promise.all(promises);
|
|
886
908
|
this._metricsOverride = metricsOverride;
|
|
887
909
|
}
|
|
@@ -931,19 +953,22 @@ class FrameSession {
|
|
|
931
953
|
await this._client.send("Page.setInterceptFileChooserDialog", { enabled }).catch(() => {
|
|
932
954
|
});
|
|
933
955
|
}
|
|
934
|
-
async _evaluateOnNewDocument(initScript, world) {
|
|
956
|
+
async _evaluateOnNewDocument(initScript, world, runImmediately) {
|
|
935
957
|
this._evaluateOnNewDocumentScripts.push(initScript);
|
|
936
958
|
}
|
|
937
|
-
async _removeEvaluatesOnNewDocument() {
|
|
959
|
+
async _removeEvaluatesOnNewDocument(initScripts) {
|
|
938
960
|
this._evaluateOnNewDocumentScripts = [];
|
|
939
961
|
}
|
|
962
|
+
async exposePlaywrightBinding() {
|
|
963
|
+
await this._client.send("Runtime.addBinding", { name: import_page.PageBinding.kBindingName });
|
|
964
|
+
}
|
|
940
965
|
async _getContentFrame(handle) {
|
|
941
966
|
const nodeInfo = await this._client.send("DOM.describeNode", {
|
|
942
967
|
objectId: handle._objectId
|
|
943
968
|
});
|
|
944
969
|
if (!nodeInfo || typeof nodeInfo.node.frameId !== "string")
|
|
945
970
|
return null;
|
|
946
|
-
return this._page.
|
|
971
|
+
return this._page.frameManager.frame(nodeInfo.node.frameId);
|
|
947
972
|
}
|
|
948
973
|
async _getOwnerFrame(handle) {
|
|
949
974
|
const documentElement = await handle.evaluateHandle((node) => {
|
|
@@ -980,7 +1005,7 @@ class FrameSession {
|
|
|
980
1005
|
return { x: x + position.x, y: y + position.y, width, height };
|
|
981
1006
|
}
|
|
982
1007
|
async _framePosition() {
|
|
983
|
-
const frame = this._page.
|
|
1008
|
+
const frame = this._page.frameManager.frame(this._targetId);
|
|
984
1009
|
if (!frame)
|
|
985
1010
|
return null;
|
|
986
1011
|
if (frame === this._page.mainFrame())
|
|
@@ -1093,7 +1118,7 @@ function calculateUserAgentMetadata(options) {
|
|
|
1093
1118
|
const metadata = {
|
|
1094
1119
|
mobile: !!options.isMobile,
|
|
1095
1120
|
model: "",
|
|
1096
|
-
architecture: "
|
|
1121
|
+
architecture: "x86",
|
|
1097
1122
|
platform: "Windows",
|
|
1098
1123
|
platformVersion: ""
|
|
1099
1124
|
};
|
|
@@ -40,11 +40,11 @@ class CRServiceWorker extends import_page.Worker {
|
|
|
40
40
|
constructor(browserContext, session, url) {
|
|
41
41
|
super(browserContext, url);
|
|
42
42
|
this._session = session;
|
|
43
|
-
this.
|
|
43
|
+
this.browserContext = browserContext;
|
|
44
44
|
if (!!process.env.PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS)
|
|
45
45
|
this._networkManager = new import_crNetworkManager.CRNetworkManager(null, this);
|
|
46
46
|
session.once("Runtime.executionContextCreated", (event) => {
|
|
47
|
-
this.
|
|
47
|
+
this.createExecutionContext(new import_crExecutionContext.CRExecutionContext(session, event.context));
|
|
48
48
|
});
|
|
49
49
|
if (this._networkManager && this._isNetworkInspectionEnabled()) {
|
|
50
50
|
this.updateRequestInterception();
|
|
@@ -73,19 +73,19 @@ class CRServiceWorker extends import_page.Worker {
|
|
|
73
73
|
async updateOffline() {
|
|
74
74
|
if (!this._isNetworkInspectionEnabled())
|
|
75
75
|
return;
|
|
76
|
-
await this._networkManager?.setOffline(!!this.
|
|
76
|
+
await this._networkManager?.setOffline(!!this.browserContext._options.offline).catch(() => {
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
79
|
async updateHttpCredentials() {
|
|
80
80
|
if (!this._isNetworkInspectionEnabled())
|
|
81
81
|
return;
|
|
82
|
-
await this._networkManager?.authenticate(this.
|
|
82
|
+
await this._networkManager?.authenticate(this.browserContext._options.httpCredentials || null).catch(() => {
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
async updateExtraHTTPHeaders() {
|
|
86
86
|
if (!this._isNetworkInspectionEnabled())
|
|
87
87
|
return;
|
|
88
|
-
await this._networkManager?.setExtraHTTPHeaders(this.
|
|
88
|
+
await this._networkManager?.setExtraHTTPHeaders(this.browserContext._options.extraHTTPHeaders || []).catch(() => {
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
async updateRequestInterception() {
|
|
@@ -95,29 +95,24 @@ class CRServiceWorker extends import_page.Worker {
|
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
needsRequestInterception() {
|
|
98
|
-
return this._isNetworkInspectionEnabled() &&
|
|
98
|
+
return this._isNetworkInspectionEnabled() && this.browserContext.requestInterceptors.length > 0;
|
|
99
99
|
}
|
|
100
100
|
reportRequestFinished(request, response) {
|
|
101
|
-
this.
|
|
101
|
+
this.browserContext.emit(import_browserContext.BrowserContext.Events.RequestFinished, { request, response });
|
|
102
102
|
}
|
|
103
103
|
requestFailed(request, _canceled) {
|
|
104
|
-
this.
|
|
104
|
+
this.browserContext.emit(import_browserContext.BrowserContext.Events.RequestFailed, request);
|
|
105
105
|
}
|
|
106
106
|
requestReceivedResponse(response) {
|
|
107
|
-
this.
|
|
107
|
+
this.browserContext.emit(import_browserContext.BrowserContext.Events.Response, response);
|
|
108
108
|
}
|
|
109
109
|
requestStarted(request, route) {
|
|
110
|
-
this.
|
|
111
|
-
if (route)
|
|
112
|
-
|
|
113
|
-
if (this._browserContext._requestInterceptor?.(r, request))
|
|
114
|
-
return;
|
|
115
|
-
r.continue({ isFallback: true }).catch(() => {
|
|
116
|
-
});
|
|
117
|
-
}
|
|
110
|
+
this.browserContext.emit(import_browserContext.BrowserContext.Events.Request, request);
|
|
111
|
+
if (route)
|
|
112
|
+
new network.Route(request, route).handle(this.browserContext.requestInterceptors);
|
|
118
113
|
}
|
|
119
114
|
_isNetworkInspectionEnabled() {
|
|
120
|
-
return this.
|
|
115
|
+
return this.browserContext._options.serviceWorkers !== "block";
|
|
121
116
|
}
|
|
122
117
|
}
|
|
123
118
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -22,13 +22,11 @@ __export(videoRecorder_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(videoRecorder_exports);
|
|
24
24
|
var import_utils = require("../../utils");
|
|
25
|
-
var import_instrumentation = require("../instrumentation");
|
|
26
25
|
var import_page = require("../page");
|
|
27
26
|
var import_processLauncher = require("../utils/processLauncher");
|
|
28
|
-
var import_progress = require("../progress");
|
|
29
27
|
const fps = 25;
|
|
30
28
|
class VideoRecorder {
|
|
31
|
-
constructor(page, ffmpegPath
|
|
29
|
+
constructor(page, ffmpegPath) {
|
|
32
30
|
this._process = null;
|
|
33
31
|
this._gracefullyClose = null;
|
|
34
32
|
this._lastWritePromise = Promise.resolve();
|
|
@@ -37,46 +35,40 @@ class VideoRecorder {
|
|
|
37
35
|
this._lastWriteTimestamp = 0;
|
|
38
36
|
this._frameQueue = [];
|
|
39
37
|
this._isStopped = false;
|
|
40
|
-
this._progress = progress;
|
|
41
38
|
this._ffmpegPath = ffmpegPath;
|
|
42
39
|
page.on(import_page.Page.Events.ScreencastFrame, (frame) => this.writeFrame(frame.buffer, frame.frameSwapWallTime / 1e3));
|
|
43
40
|
}
|
|
44
41
|
static async launch(page, ffmpegPath, options) {
|
|
45
42
|
if (!options.outputFile.endsWith(".webm"))
|
|
46
43
|
throw new Error("File must have .webm extension");
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
return
|
|
50
|
-
const recorder = new VideoRecorder(page, ffmpegPath, progress);
|
|
51
|
-
await recorder._launch(options);
|
|
52
|
-
return recorder;
|
|
53
|
-
});
|
|
44
|
+
const recorder = new VideoRecorder(page, ffmpegPath);
|
|
45
|
+
await recorder._launch(options);
|
|
46
|
+
return recorder;
|
|
54
47
|
}
|
|
55
48
|
async _launch(options) {
|
|
56
49
|
const w = options.width;
|
|
57
50
|
const h = options.height;
|
|
58
51
|
const args = `-loglevel error -f image2pipe -avioflags direct -fpsprobesize 0 -probesize 32 -analyzeduration 0 -c:v mjpeg -i pipe:0 -y -an -r ${fps} -c:v vp8 -qmin 0 -qmax 50 -crf 8 -deadline realtime -speed 8 -b:v 1M -threads 1 -vf pad=${w}:${h}:0:0:gray,crop=${w}:${h}:0:0`.split(" ");
|
|
59
52
|
args.push(options.outputFile);
|
|
60
|
-
const progress = this._progress;
|
|
61
53
|
const { launchedProcess, gracefullyClose } = await (0, import_processLauncher.launchProcess)({
|
|
62
54
|
command: this._ffmpegPath,
|
|
63
55
|
args,
|
|
64
56
|
stdio: "stdin",
|
|
65
|
-
log: (message) =>
|
|
57
|
+
log: (message) => import_utils.debugLogger.log("browser", message),
|
|
66
58
|
tempDirectories: [],
|
|
67
59
|
attemptToGracefullyClose: async () => {
|
|
68
|
-
|
|
60
|
+
import_utils.debugLogger.log("browser", "Closing stdin...");
|
|
69
61
|
launchedProcess.stdin.end();
|
|
70
62
|
},
|
|
71
63
|
onExit: (exitCode, signal) => {
|
|
72
|
-
|
|
64
|
+
import_utils.debugLogger.log("browser", `ffmpeg onkill exitCode=${exitCode} signal=${signal}`);
|
|
73
65
|
}
|
|
74
66
|
});
|
|
75
67
|
launchedProcess.stdin.on("finish", () => {
|
|
76
|
-
|
|
68
|
+
import_utils.debugLogger.log("browser", "ffmpeg finished input.");
|
|
77
69
|
});
|
|
78
70
|
launchedProcess.stdin.on("error", () => {
|
|
79
|
-
|
|
71
|
+
import_utils.debugLogger.log("browser", "ffmpeg error.");
|
|
80
72
|
});
|
|
81
73
|
this._process = launchedProcess;
|
|
82
74
|
this._gracefullyClose = gracefullyClose;
|
|
@@ -103,7 +95,7 @@ class VideoRecorder {
|
|
|
103
95
|
async _sendFrame(frame) {
|
|
104
96
|
return new Promise((f) => this._process.stdin.write(frame, f)).then((error) => {
|
|
105
97
|
if (error)
|
|
106
|
-
|
|
98
|
+
import_utils.debugLogger.log("browser", `ffmpeg failed to write: ${String(error)}`);
|
|
107
99
|
});
|
|
108
100
|
}
|
|
109
101
|
async stop() {
|