Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/chromium/crNetworkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit worried about this (user can call request.frame().url() and be surprised, or even try to evaluate in it), but oh well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see, if it becomes a problem we can put additional protection to ensure the page will throw meaningful errors.

}

if (!frame) {
if (interceptionId)
this._client.send('Fetch.continueRequest', { requestId: interceptionId }).catch(debugError);
Expand Down
2 changes: 1 addition & 1 deletion test/popup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down