Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(chromium): support main resource request interception for popups (#1449)

Yury Semikhatskybae56ea9d368
diff --git a/src/chromium/crNetworkManager.ts b/src/chromium/crNetworkManager.ts
index b73893ab2a..fa2743f707 100644
--- a/src/chromium/crNetworkManager.ts
+++ b/src/chromium/crNetworkManager.ts
@@ -23,6 +23,7 @@ import * as network from '../network';
import * as frames from '../frames';
import * as platform from '../platform';
import { Credentials } from '../types';
+import { CRTarget } from './crTarget';
export class CRNetworkManager {
private _client: CRSession;
@@ -165,7 +166,16 @@ export class CRNetworkManager {
redirectedFrom = request.request;
}
}
- const frame = event.frameId ? this._page._frameManager.frame(event.frameId) : workerFrame;
+ let frame = event.frameId ? this._page._frameManager.frame(event.frameId) : workerFrame;
+
+ // Check if it's main resource request interception (targetId === main frame id).
+ if (!frame && interceptionId && event.frameId === CRTarget.fromPage(this._page)._targetId) {
+ // Main resource request for the page is being intercepted so the Frame is not created
+ // yet. Precreate it here for the purposes of request interception. It will be updated
+ // later as soon as the request contnues and we receive frame tree from the page.
+ frame = this._page._frameManager.frameAttached(event.frameId, null);
+ }
+
if (!frame) {
if (interceptionId)
this._client.send('Fetch.continueRequest', { requestId: interceptionId }).catch(debugError);
diff --git a/test/popup.spec.js b/test/popup.spec.js
index 09b33b4061..00ac656a36 100644
--- a/test/popup.spec.js
+++ b/test/popup.spec.js
@@ -39,7 +39,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, WE
expect(userAgent).toBe('hey');
expect(request.headers['user-agent']).toBe('hey');
});
- it.fail(CHROMIUM || FFOX)('should respect routes from browser context', async function({browser, server}) {
+ it.fail(FFOX)('should respect routes from browser context', async function({browser, server}) {
const context = await browser.newContext();
const page = await context.newPage();
await page.goto(server.EMPTY_PAGE);