Skip to content

Commit bae56ea

Browse files
authored
fix(chromium): support main resource request interception for popups (#1449)
1 parent 053bab1 commit bae56ea

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/chromium/crNetworkManager.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import * as network from '../network';
2323
import * as frames from '../frames';
2424
import * as platform from '../platform';
2525
import { Credentials } from '../types';
26+
import { CRTarget } from './crTarget';
2627

2728
export class CRNetworkManager {
2829
private _client: CRSession;
@@ -165,7 +166,16 @@ export class CRNetworkManager {
165166
redirectedFrom = request.request;
166167
}
167168
}
168-
const frame = event.frameId ? this._page._frameManager.frame(event.frameId) : workerFrame;
169+
let frame = event.frameId ? this._page._frameManager.frame(event.frameId) : workerFrame;
170+
171+
// Check if it's main resource request interception (targetId === main frame id).
172+
if (!frame && interceptionId && event.frameId === CRTarget.fromPage(this._page)._targetId) {
173+
// Main resource request for the page is being intercepted so the Frame is not created
174+
// yet. Precreate it here for the purposes of request interception. It will be updated
175+
// later as soon as the request contnues and we receive frame tree from the page.
176+
frame = this._page._frameManager.frameAttached(event.frameId, null);
177+
}
178+
169179
if (!frame) {
170180
if (interceptionId)
171181
this._client.send('Fetch.continueRequest', { requestId: interceptionId }).catch(debugError);

test/popup.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, WE
3939
expect(userAgent).toBe('hey');
4040
expect(request.headers['user-agent']).toBe('hey');
4141
});
42-
it.fail(CHROMIUM || FFOX)('should respect routes from browser context', async function({browser, server}) {
42+
it.fail(FFOX)('should respect routes from browser context', async function({browser, server}) {
4343
const context = await browser.newContext();
4444
const page = await context.newPage();
4545
await page.goto(server.EMPTY_PAGE);

0 commit comments

Comments
 (0)