From 8ac3c1d11fa54602aac5dcdb2237bdd7f480470c Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Fri, 20 Mar 2020 15:47:26 -0700 Subject: [PATCH] fix(chromium): support main resource request interception for popups --- src/chromium/crNetworkManager.ts | 12 +++++++++++- test/popup.spec.js | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/chromium/crNetworkManager.ts b/src/chromium/crNetworkManager.ts index b73893ab2a1d4..fa2743f70770c 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 09b33b4061299..00ac656a36871 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);