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: report new window downloads #2019

Merged
merged 3 commits into from
Apr 30, 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
2 changes: 1 addition & 1 deletion browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
{
"name": "firefox",
"revision": "1087"
"revision": "1088"
Copy link
Member

Choose a reason for hiding this comment

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

run npm run doc to generate readme.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. I don't see any diff though.

},
{
"name": "webkit",
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-firefox/browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"browsers": [
{
"name": "firefox",
"revision": "1087"
"revision": "1088"
}
]
}
2 changes: 1 addition & 1 deletion packages/playwright/browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
{
"name": "firefox",
"revision": "1087"
"revision": "1088"
},
{
"name": "webkit",
Expand Down
15 changes: 13 additions & 2 deletions src/chromium/crPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class CRPage implements PageDelegate {
readonly rawMouse: RawMouseImpl;
readonly rawKeyboard: RawKeyboardImpl;
readonly _targetId: string;
private readonly _opener: CRPage | null;
readonly _opener: CRPage | null;
private readonly _pdf: CRPDF;
private readonly _coverage: CRCoverage;
readonly _browserContext: CRBrowserContext;
Expand Down Expand Up @@ -654,7 +654,18 @@ class FrameSession {
}

_onDownloadWillBegin(payload: Protocol.Page.downloadWillBeginPayload) {
this._crPage._browserContext._browser._downloadCreated(this._page, payload.guid, payload.url);
let originPage = this._crPage._initializedPage;
// If it's a new window download, report it on the opener page.
if (!originPage) {
// Resume the page creation with an error. The page will automatically close right
// after the download begins.
this._firstNonInitialNavigationCommittedReject(new Error('Starting new page download'));
if (this._crPage._opener)
originPage = this._crPage._opener._initializedPage;
}
if (!originPage)
return;
this._crPage._browserContext._browser._downloadCreated(originPage, payload.guid, payload.url);
}

_onDownloadProgress(payload: Protocol.Page.downloadProgressPayload) {
Expand Down
13 changes: 12 additions & 1 deletion src/firefox/ffBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,18 @@ export class FFBrowser extends BrowserBase {
assert(ffPage);
if (!ffPage)
return;
this._downloadCreated(ffPage._page, payload.uuid, payload.url);
let originPage = ffPage._initializedPage;
// If it's a new window download, report it on the opener page.
if (!originPage) {
// Resume the page creation with an error. The page will automatically close right
// after the download begins.
ffPage._pageCallback(new Error('Starting new page download'));
if (ffPage._opener)
originPage = ffPage._opener._initializedPage;
}
if (!originPage)
return;
this._downloadCreated(originPage, payload.uuid, payload.url);
}

_onDownloadFinished(payload: Protocol.Browser.downloadFinishedPayload) {
Expand Down
4 changes: 2 additions & 2 deletions src/firefox/ffPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export class FFPage implements PageDelegate {
readonly _networkManager: FFNetworkManager;
readonly _browserContext: FFBrowserContext;
private _pagePromise: Promise<Page | Error>;
private _pageCallback: (pageOrError: Page | Error) => void = () => {};
_pageCallback: (pageOrError: Page | Error) => void = () => {};
_initializedPage: Page | null = null;
private readonly _opener: FFPage | null;
readonly _opener: FFPage | null;
private readonly _contextIdToContext: Map<string, dom.FrameExecutionContext>;
private _eventListeners: RegisteredListener[];
private _workers = new Map<string, { frameId: string, session: FFSession }>();
Expand Down
13 changes: 12 additions & 1 deletion src/webkit/wkBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,18 @@ export class WKBrowser extends BrowserBase {
// here by simulating cancelled provisional load which matches downloads from network.
frameManager.provisionalLoadFailed(frame, '', 'Download is starting');
}
this._downloadCreated(page._page, payload.uuid, payload.url);
let originPage = page._initializedPage;
// If it's a new window download, report it on the opener page.
if (!originPage) {
// Resume the page creation with an error. The page will automatically close right
// after the download begins.
page._firstNonInitialNavigationCommittedReject(new Error('Starting new page download'));
if (page._opener)
originPage = page._opener._initializedPage;
}
if (!originPage)
return;
this._downloadCreated(originPage, payload.uuid, payload.url);
}

_onDownloadFinished(payload: Protocol.Playwright.downloadFinishedPayload) {
Expand Down
4 changes: 2 additions & 2 deletions src/webkit/wkPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class WKPage implements PageDelegate {
private readonly _pagePromise: Promise<Page | Error>;
private _pagePromiseCallback: (page: Page | Error) => void = () => {};
private readonly _pageProxySession: WKSession;
private readonly _opener: WKPage | null;
readonly _opener: WKPage | null;
private readonly _requestIdToRequest = new Map<string, WKInterceptableRequest>();
private readonly _workers: WKWorkers;
private readonly _contextIdToContext: Map<number, dom.FrameExecutionContext>;
Expand All @@ -65,7 +65,7 @@ export class WKPage implements PageDelegate {
_initializedPage: Page | null = null;
private _firstNonInitialNavigationCommittedPromise: Promise<void>;
private _firstNonInitialNavigationCommittedFulfill = () => {};
private _firstNonInitialNavigationCommittedReject = (e: Error) => {};
_firstNonInitialNavigationCommittedReject = (e: Error) => {};
private _lastConsoleMessage: { derivedType: string, text: string, handles: JSHandle[]; count: number, location: ConsoleMessageLocation; } | null = null;

constructor(browserContext: WKBrowserContext, pageProxySession: WKSession, opener: WKPage | null) {
Expand Down
5 changes: 4 additions & 1 deletion test/download.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ describe('Download', function() {
expect(fs.readFileSync(path).toString()).toBe('Hello world');
await page.close();
});
it.fail(CHROMIUM || WEBKIT || FFOX)('should report new window downloads', async({browser, server}) => {
it('should report new window downloads', async({browser, server}) => {
// TODO: - the test fails in headful Chromium as the popup page gets closed along
// with the session before download completed event arrives.
// - WebKit doesn't close the popup page
const page = await browser.newPage({ acceptDownloads: true });
await page.setContent(`<a target=_blank href="${server.PREFIX}/download">download</a>`);
const [ download ] = await Promise.all([
Expand Down