patchright-core 1.52.5 → 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 +54 -32
- 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 +30 -26
- 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 +421 -345
- 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 +43 -31
- package/lib/server/chromium/crPage.js +98 -72
- 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 +98 -101
- 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 +63 -20
- package/lib/server/frames.js +495 -555
- 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 +8 -16
- 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 +232 -177
- 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 +128 -17
- 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,6 +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" });
|
|
511
|
+
if (response.isDownload)
|
|
512
|
+
throw new frames.NavigationAbortedError(response.loaderId, "Download is starting");
|
|
498
513
|
if (response.errorText)
|
|
499
514
|
throw new frames.NavigationAbortedError(response.loaderId, `${response.errorText} at ${url}`);
|
|
500
515
|
return { newDocumentId: response.loaderId };
|
|
@@ -503,9 +518,9 @@ class FrameSession {
|
|
|
503
518
|
if (this._eventBelongsToStaleFrame(event.frameId))
|
|
504
519
|
return;
|
|
505
520
|
if (event.name === "load")
|
|
506
|
-
this._page.
|
|
521
|
+
this._page.frameManager.frameLifecycleEvent(event.frameId, "load");
|
|
507
522
|
else if (event.name === "DOMContentLoaded")
|
|
508
|
-
this._page.
|
|
523
|
+
this._page.frameManager.frameLifecycleEvent(event.frameId, "domcontentloaded");
|
|
509
524
|
await this._client._sendMayFail("Runtime.runIfWaitingForDebugger");
|
|
510
525
|
var document = await this._client._sendMayFail("DOM.getDocument");
|
|
511
526
|
if (!document) return;
|
|
@@ -517,7 +532,7 @@ class FrameSession {
|
|
|
517
532
|
for (const nodeId of query.nodeIds) await this._client._sendMayFail("DOM.removeNode", { nodeId });
|
|
518
533
|
await this._client._sendMayFail("Runtime.runIfWaitingForDebugger");
|
|
519
534
|
try {
|
|
520
|
-
await this._page.
|
|
535
|
+
await this._page.frameManager.frame(this._targetId)._context("utility");
|
|
521
536
|
} catch {
|
|
522
537
|
}
|
|
523
538
|
;
|
|
@@ -531,7 +546,7 @@ class FrameSession {
|
|
|
531
546
|
this._handleFrameTree(child);
|
|
532
547
|
}
|
|
533
548
|
_eventBelongsToStaleFrame(frameId) {
|
|
534
|
-
const frame = this._page.
|
|
549
|
+
const frame = this._page.frameManager.frame(frameId);
|
|
535
550
|
if (!frame)
|
|
536
551
|
return true;
|
|
537
552
|
const session = this._crPage._sessionForFrame(frame);
|
|
@@ -541,20 +556,20 @@ class FrameSession {
|
|
|
541
556
|
const frameSession = this._crPage._sessions.get(frameId);
|
|
542
557
|
if (frameSession && frameId !== this._targetId) {
|
|
543
558
|
frameSession._swappedIn = true;
|
|
544
|
-
const frame = this._page.
|
|
559
|
+
const frame = this._page.frameManager.frame(frameId);
|
|
545
560
|
if (frame)
|
|
546
|
-
this._page.
|
|
561
|
+
this._page.frameManager.removeChildFramesRecursively(frame);
|
|
547
562
|
return;
|
|
548
563
|
}
|
|
549
|
-
if (parentFrameId && !this._page.
|
|
564
|
+
if (parentFrameId && !this._page.frameManager.frame(parentFrameId)) {
|
|
550
565
|
return;
|
|
551
566
|
}
|
|
552
|
-
this._page.
|
|
567
|
+
this._page.frameManager.frameAttached(frameId, parentFrameId);
|
|
553
568
|
}
|
|
554
569
|
async _onFrameNavigated(framePayload, initial) {
|
|
555
570
|
if (this._eventBelongsToStaleFrame(framePayload.id))
|
|
556
571
|
return;
|
|
557
|
-
this._page.
|
|
572
|
+
this._page.frameManager.frameCommittedNewDocumentNavigation(framePayload.id, framePayload.url + (framePayload.urlFragment || ""), framePayload.name || "", framePayload.loaderId, initial);
|
|
558
573
|
if (!initial)
|
|
559
574
|
this._firstNonInitialNavigationCommittedFulfill();
|
|
560
575
|
await this._client._sendMayFail("Runtime.runIfWaitingForDebugger");
|
|
@@ -568,7 +583,7 @@ class FrameSession {
|
|
|
568
583
|
for (const nodeId of query.nodeIds) await this._client._sendMayFail("DOM.removeNode", { nodeId });
|
|
569
584
|
await this._client._sendMayFail("Runtime.runIfWaitingForDebugger");
|
|
570
585
|
try {
|
|
571
|
-
await this._page.
|
|
586
|
+
await this._page.frameManager.frame(this._targetId)._context("utility");
|
|
572
587
|
} catch {
|
|
573
588
|
}
|
|
574
589
|
;
|
|
@@ -577,28 +592,29 @@ class FrameSession {
|
|
|
577
592
|
if (this._eventBelongsToStaleFrame(payload.frameId))
|
|
578
593
|
return;
|
|
579
594
|
if (payload.disposition === "currentTab")
|
|
580
|
-
this._page.
|
|
595
|
+
this._page.frameManager.frameRequestedNavigation(payload.frameId);
|
|
581
596
|
}
|
|
582
597
|
_onFrameNavigatedWithinDocument(frameId, url) {
|
|
583
598
|
if (this._eventBelongsToStaleFrame(frameId))
|
|
584
599
|
return;
|
|
585
|
-
this._page.
|
|
600
|
+
this._page.frameManager.frameCommittedSameDocumentNavigation(frameId, url);
|
|
586
601
|
}
|
|
587
602
|
_onFrameDetached(frameId, reason) {
|
|
588
603
|
if (this._crPage._sessions.has(frameId)) {
|
|
589
604
|
return;
|
|
590
605
|
}
|
|
591
606
|
if (reason === "swap") {
|
|
592
|
-
const frame = this._page.
|
|
607
|
+
const frame = this._page.frameManager.frame(frameId);
|
|
593
608
|
if (frame)
|
|
594
|
-
this._page.
|
|
609
|
+
this._page.frameManager.removeChildFramesRecursively(frame);
|
|
595
610
|
return;
|
|
596
611
|
}
|
|
597
|
-
this._page.
|
|
612
|
+
this._page.frameManager.frameDetached(frameId);
|
|
598
613
|
}
|
|
599
614
|
_onExecutionContextCreated(contextPayload) {
|
|
600
|
-
for (const name of this._exposedBindingNames)
|
|
601
|
-
|
|
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;
|
|
602
618
|
if (contextPayload.auxData.type == "worker") throw new Error("ExecutionContext is worker");
|
|
603
619
|
if (!frame || this._eventBelongsToStaleFrame(frame._id))
|
|
604
620
|
return;
|
|
@@ -631,10 +647,10 @@ class FrameSession {
|
|
|
631
647
|
const session = this._client.createChildSession(event.sessionId);
|
|
632
648
|
if (event.targetInfo.type === "iframe") {
|
|
633
649
|
const targetId = event.targetInfo.targetId;
|
|
634
|
-
const frame = this._page.
|
|
650
|
+
const frame = this._page.frameManager.frame(targetId);
|
|
635
651
|
if (!frame)
|
|
636
652
|
return;
|
|
637
|
-
this._page.
|
|
653
|
+
this._page.frameManager.removeChildFramesRecursively(frame);
|
|
638
654
|
for (const [contextId, context] of this._contextIdToContext) {
|
|
639
655
|
if (context.frame === frame)
|
|
640
656
|
this._onExecutionContextDestroyed(contextId);
|
|
@@ -650,11 +666,11 @@ class FrameSession {
|
|
|
650
666
|
return;
|
|
651
667
|
}
|
|
652
668
|
const url = event.targetInfo.url;
|
|
653
|
-
const worker = new
|
|
654
|
-
this._page.
|
|
669
|
+
const worker = new import_page.Worker(this._page, url);
|
|
670
|
+
this._page.addWorker(event.sessionId, worker);
|
|
655
671
|
this._workerSessions.set(event.sessionId, session);
|
|
656
672
|
session.once("Runtime.executionContextCreated", async (event2) => {
|
|
657
|
-
worker.
|
|
673
|
+
worker.createExecutionContext(new import_crExecutionContext.CRExecutionContext(session, event2.context));
|
|
658
674
|
});
|
|
659
675
|
var globalThis = await session._sendMayFail("Runtime.evaluate", {
|
|
660
676
|
expression: "globalThis",
|
|
@@ -663,17 +679,25 @@ class FrameSession {
|
|
|
663
679
|
if (globalThis && globalThis.result) {
|
|
664
680
|
var globalThisObjId = globalThis.result.objectId;
|
|
665
681
|
var executionContextId = parseInt(globalThisObjId.split(".")[1], 10);
|
|
666
|
-
worker.
|
|
682
|
+
worker.createExecutionContext(new import_crExecutionContext.CRExecutionContext(session, { id: executionContextId }));
|
|
667
683
|
}
|
|
668
|
-
this._crPage._networkManager.addSession(session, this._page.
|
|
684
|
+
this._crPage._networkManager.addSession(session, this._page.frameManager.frame(this._targetId) ?? void 0).catch(() => {
|
|
669
685
|
});
|
|
670
686
|
session._sendMayFail("Runtime.runIfWaitingForDebugger");
|
|
671
|
-
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
|
+
});
|
|
672
696
|
session.on("Target.attachedToTarget", (event2) => this._onAttachedToTarget(event2));
|
|
673
697
|
session.on("Target.detachedFromTarget", (event2) => this._onDetachedFromTarget(event2));
|
|
674
698
|
session.on("Runtime.consoleAPICalled", (event2) => {
|
|
675
|
-
const args = event2.args.map((o) => (0, import_crExecutionContext.createHandle)(worker.
|
|
676
|
-
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));
|
|
677
701
|
});
|
|
678
702
|
session.on("Runtime.exceptionThrown", (exception) => this._page.emitOnContextOnceInitialized(import_browserContext.BrowserContext.Events.PageError, (0, import_crProtocolHelper.exceptionToError)(exception.exceptionDetails), this._page));
|
|
679
703
|
}
|
|
@@ -681,7 +705,7 @@ class FrameSession {
|
|
|
681
705
|
const workerSession = this._workerSessions.get(event.sessionId);
|
|
682
706
|
if (workerSession) {
|
|
683
707
|
workerSession.dispose();
|
|
684
|
-
this._page.
|
|
708
|
+
this._page.removeWorker(event.sessionId);
|
|
685
709
|
return;
|
|
686
710
|
}
|
|
687
711
|
const childFrameSession = this._crPage._sessions.get(event.targetId);
|
|
@@ -693,7 +717,7 @@ class FrameSession {
|
|
|
693
717
|
}
|
|
694
718
|
this._client.send("Page.enable").catch((e) => null).then(() => {
|
|
695
719
|
if (!childFrameSession._swappedIn)
|
|
696
|
-
this._page.
|
|
720
|
+
this._page.frameManager.frameDetached(event.targetId);
|
|
697
721
|
childFrameSession.dispose();
|
|
698
722
|
});
|
|
699
723
|
}
|
|
@@ -708,26 +732,26 @@ class FrameSession {
|
|
|
708
732
|
if (!context)
|
|
709
733
|
return;
|
|
710
734
|
const values = event.args.map((arg) => (0, import_crExecutionContext.createHandle)(context, arg));
|
|
711
|
-
this._page.
|
|
735
|
+
this._page.addConsoleMessage(event.type, values, (0, import_crProtocolHelper.toConsoleMessageLocation)(event.stackTrace));
|
|
712
736
|
}
|
|
713
737
|
async _onBindingCalled(event) {
|
|
714
738
|
const pageOrError = await this._crPage._page.waitForInitializedOrError();
|
|
715
739
|
if (!(pageOrError instanceof Error)) {
|
|
716
740
|
const context = this._contextIdToContext.get(event.executionContextId);
|
|
717
|
-
if (context)
|
|
718
|
-
|
|
741
|
+
if (context)
|
|
742
|
+
await this._page.onBindingCalled(event.payload, context);
|
|
719
743
|
}
|
|
720
744
|
}
|
|
721
745
|
_onDialog(event) {
|
|
722
|
-
if (!this._page.
|
|
746
|
+
if (!this._page.frameManager.frame(this._targetId))
|
|
723
747
|
return;
|
|
724
|
-
this._page.
|
|
748
|
+
this._page.browserContext.dialogManager.dialogDidOpen(new dialog.Dialog(
|
|
725
749
|
this._page,
|
|
726
750
|
event.type,
|
|
727
751
|
event.message,
|
|
728
752
|
async (accept, promptText) => {
|
|
729
753
|
if (this._isMainFrame() && event.type === "beforeunload" && !accept)
|
|
730
|
-
this._page.
|
|
754
|
+
this._page.frameManager.frameAbortedNavigation(this._page.mainFrame()._id, "navigation cancelled by beforeunload dialog");
|
|
731
755
|
await this._client.send("Page.handleJavaScriptDialog", { accept, promptText });
|
|
732
756
|
},
|
|
733
757
|
event.defaultPrompt
|
|
@@ -750,13 +774,13 @@ class FrameSession {
|
|
|
750
774
|
lineNumber: lineNumber || 0,
|
|
751
775
|
columnNumber: 0
|
|
752
776
|
};
|
|
753
|
-
this._page.
|
|
777
|
+
this._page.addConsoleMessage(level, [], location, text);
|
|
754
778
|
}
|
|
755
779
|
}
|
|
756
780
|
async _onFileChooserOpened(event) {
|
|
757
781
|
if (!event.backendNodeId)
|
|
758
782
|
return;
|
|
759
|
-
const frame = this._page.
|
|
783
|
+
const frame = this._page.frameManager.frame(event.frameId);
|
|
760
784
|
if (!frame)
|
|
761
785
|
return;
|
|
762
786
|
let handle;
|
|
@@ -779,7 +803,7 @@ class FrameSession {
|
|
|
779
803
|
});
|
|
780
804
|
});
|
|
781
805
|
const buffer = Buffer.from(payload.data, "base64");
|
|
782
|
-
this._page.emit(
|
|
806
|
+
this._page.emit(import_page.Page.Events.ScreencastFrame, {
|
|
783
807
|
buffer,
|
|
784
808
|
frameSwapWallTime: payload.metadata.timestamp ? payload.metadata.timestamp * 1e3 : void 0,
|
|
785
809
|
width: payload.metadata.deviceWidth,
|
|
@@ -788,14 +812,14 @@ class FrameSession {
|
|
|
788
812
|
}
|
|
789
813
|
async _createVideoRecorder(screencastId, options) {
|
|
790
814
|
(0, import_assert.assert)(!this._screencastId);
|
|
791
|
-
const ffmpegPath = import_registry.registry.findExecutable("ffmpeg").executablePathOrDie(this._page.
|
|
815
|
+
const ffmpegPath = import_registry.registry.findExecutable("ffmpeg").executablePathOrDie(this._page.browserContext._browser.sdkLanguage());
|
|
792
816
|
this._videoRecorder = await import_videoRecorder.VideoRecorder.launch(this._crPage._page, ffmpegPath, options);
|
|
793
817
|
this._screencastId = screencastId;
|
|
794
818
|
}
|
|
795
819
|
async _startVideoRecording(options) {
|
|
796
820
|
const screencastId = this._screencastId;
|
|
797
821
|
(0, import_assert.assert)(screencastId);
|
|
798
|
-
this._page.once(
|
|
822
|
+
this._page.once(import_page.Page.Events.Close, () => this._stopVideoRecording().catch(() => {
|
|
799
823
|
}));
|
|
800
824
|
const gotFirstFrame = new Promise((f) => this._client.once("Page.screencastFrame", f));
|
|
801
825
|
await this._startScreencast(this._videoRecorder, {
|
|
@@ -842,7 +866,7 @@ class FrameSession {
|
|
|
842
866
|
(0, import_assert.assert)(this._isMainFrame());
|
|
843
867
|
const options = this._crPage._browserContext._options;
|
|
844
868
|
const emulatedSize = this._page.emulatedSize();
|
|
845
|
-
if (emulatedSize
|
|
869
|
+
if (!emulatedSize)
|
|
846
870
|
return;
|
|
847
871
|
const viewportSize = emulatedSize.viewport;
|
|
848
872
|
const screenSize = emulatedSize.screen;
|
|
@@ -859,9 +883,7 @@ class FrameSession {
|
|
|
859
883
|
};
|
|
860
884
|
if (JSON.stringify(this._metricsOverride) === JSON.stringify(metricsOverride))
|
|
861
885
|
return;
|
|
862
|
-
const promises = [
|
|
863
|
-
this._client.send("Emulation.setDeviceMetricsOverride", metricsOverride)
|
|
864
|
-
];
|
|
886
|
+
const promises = [];
|
|
865
887
|
if (!preserveWindowBoundaries && this._windowId) {
|
|
866
888
|
let insets = { width: 0, height: 0 };
|
|
867
889
|
if (this._crPage._browserContext._browser.options.headful) {
|
|
@@ -881,6 +903,7 @@ class FrameSession {
|
|
|
881
903
|
height: viewportSize.height + insets.height
|
|
882
904
|
}));
|
|
883
905
|
}
|
|
906
|
+
promises.push(this._client.send("Emulation.setDeviceMetricsOverride", metricsOverride));
|
|
884
907
|
await Promise.all(promises);
|
|
885
908
|
this._metricsOverride = metricsOverride;
|
|
886
909
|
}
|
|
@@ -930,19 +953,22 @@ class FrameSession {
|
|
|
930
953
|
await this._client.send("Page.setInterceptFileChooserDialog", { enabled }).catch(() => {
|
|
931
954
|
});
|
|
932
955
|
}
|
|
933
|
-
async _evaluateOnNewDocument(initScript, world) {
|
|
956
|
+
async _evaluateOnNewDocument(initScript, world, runImmediately) {
|
|
934
957
|
this._evaluateOnNewDocumentScripts.push(initScript);
|
|
935
958
|
}
|
|
936
|
-
async _removeEvaluatesOnNewDocument() {
|
|
959
|
+
async _removeEvaluatesOnNewDocument(initScripts) {
|
|
937
960
|
this._evaluateOnNewDocumentScripts = [];
|
|
938
961
|
}
|
|
962
|
+
async exposePlaywrightBinding() {
|
|
963
|
+
await this._client.send("Runtime.addBinding", { name: import_page.PageBinding.kBindingName });
|
|
964
|
+
}
|
|
939
965
|
async _getContentFrame(handle) {
|
|
940
966
|
const nodeInfo = await this._client.send("DOM.describeNode", {
|
|
941
967
|
objectId: handle._objectId
|
|
942
968
|
});
|
|
943
969
|
if (!nodeInfo || typeof nodeInfo.node.frameId !== "string")
|
|
944
970
|
return null;
|
|
945
|
-
return this._page.
|
|
971
|
+
return this._page.frameManager.frame(nodeInfo.node.frameId);
|
|
946
972
|
}
|
|
947
973
|
async _getOwnerFrame(handle) {
|
|
948
974
|
const documentElement = await handle.evaluateHandle((node) => {
|
|
@@ -979,7 +1005,7 @@ class FrameSession {
|
|
|
979
1005
|
return { x: x + position.x, y: y + position.y, width, height };
|
|
980
1006
|
}
|
|
981
1007
|
async _framePosition() {
|
|
982
|
-
const frame = this._page.
|
|
1008
|
+
const frame = this._page.frameManager.frame(this._targetId);
|
|
983
1009
|
if (!frame)
|
|
984
1010
|
return null;
|
|
985
1011
|
if (frame === this._page.mainFrame())
|
|
@@ -1092,7 +1118,7 @@ function calculateUserAgentMetadata(options) {
|
|
|
1092
1118
|
const metadata = {
|
|
1093
1119
|
mobile: !!options.isMobile,
|
|
1094
1120
|
model: "",
|
|
1095
|
-
architecture: "
|
|
1121
|
+
architecture: "x86",
|
|
1096
1122
|
platform: "Windows",
|
|
1097
1123
|
platformVersion: ""
|
|
1098
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() {
|