mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix: report new window downloads (#2019)
This commit is contained in:
parent
5993a6a0e0
commit
78b44ed2a0
@ -6,7 +6,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "firefox",
|
"name": "firefox",
|
||||||
"revision": "1087"
|
"revision": "1088"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "webkit",
|
"name": "webkit",
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"browsers": [
|
"browsers": [
|
||||||
{
|
{
|
||||||
"name": "firefox",
|
"name": "firefox",
|
||||||
"revision": "1087"
|
"revision": "1088"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "firefox",
|
"name": "firefox",
|
||||||
"revision": "1087"
|
"revision": "1088"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "webkit",
|
"name": "webkit",
|
||||||
|
@ -49,7 +49,7 @@ export class CRPage implements PageDelegate {
|
|||||||
readonly rawMouse: RawMouseImpl;
|
readonly rawMouse: RawMouseImpl;
|
||||||
readonly rawKeyboard: RawKeyboardImpl;
|
readonly rawKeyboard: RawKeyboardImpl;
|
||||||
readonly _targetId: string;
|
readonly _targetId: string;
|
||||||
private readonly _opener: CRPage | null;
|
readonly _opener: CRPage | null;
|
||||||
private readonly _pdf: CRPDF;
|
private readonly _pdf: CRPDF;
|
||||||
private readonly _coverage: CRCoverage;
|
private readonly _coverage: CRCoverage;
|
||||||
readonly _browserContext: CRBrowserContext;
|
readonly _browserContext: CRBrowserContext;
|
||||||
@ -654,7 +654,18 @@ class FrameSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_onDownloadWillBegin(payload: Protocol.Page.downloadWillBeginPayload) {
|
_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) {
|
_onDownloadProgress(payload: Protocol.Page.downloadProgressPayload) {
|
||||||
|
@ -153,7 +153,18 @@ export class FFBrowser extends BrowserBase {
|
|||||||
assert(ffPage);
|
assert(ffPage);
|
||||||
if (!ffPage)
|
if (!ffPage)
|
||||||
return;
|
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) {
|
_onDownloadFinished(payload: Protocol.Browser.downloadFinishedPayload) {
|
||||||
|
@ -45,9 +45,9 @@ export class FFPage implements PageDelegate {
|
|||||||
readonly _networkManager: FFNetworkManager;
|
readonly _networkManager: FFNetworkManager;
|
||||||
readonly _browserContext: FFBrowserContext;
|
readonly _browserContext: FFBrowserContext;
|
||||||
private _pagePromise: Promise<Page | Error>;
|
private _pagePromise: Promise<Page | Error>;
|
||||||
private _pageCallback: (pageOrError: Page | Error) => void = () => {};
|
_pageCallback: (pageOrError: Page | Error) => void = () => {};
|
||||||
_initializedPage: Page | null = null;
|
_initializedPage: Page | null = null;
|
||||||
private readonly _opener: FFPage | null;
|
readonly _opener: FFPage | null;
|
||||||
private readonly _contextIdToContext: Map<string, dom.FrameExecutionContext>;
|
private readonly _contextIdToContext: Map<string, dom.FrameExecutionContext>;
|
||||||
private _eventListeners: RegisteredListener[];
|
private _eventListeners: RegisteredListener[];
|
||||||
private _workers = new Map<string, { frameId: string, session: FFSession }>();
|
private _workers = new Map<string, { frameId: string, session: FFSession }>();
|
||||||
|
@ -107,7 +107,18 @@ export class WKBrowser extends BrowserBase {
|
|||||||
// here by simulating cancelled provisional load which matches downloads from network.
|
// here by simulating cancelled provisional load which matches downloads from network.
|
||||||
frameManager.provisionalLoadFailed(frame, '', 'Download is starting');
|
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) {
|
_onDownloadFinished(payload: Protocol.Playwright.downloadFinishedPayload) {
|
||||||
|
@ -53,7 +53,7 @@ export class WKPage implements PageDelegate {
|
|||||||
private readonly _pagePromise: Promise<Page | Error>;
|
private readonly _pagePromise: Promise<Page | Error>;
|
||||||
private _pagePromiseCallback: (page: Page | Error) => void = () => {};
|
private _pagePromiseCallback: (page: Page | Error) => void = () => {};
|
||||||
private readonly _pageProxySession: WKSession;
|
private readonly _pageProxySession: WKSession;
|
||||||
private readonly _opener: WKPage | null;
|
readonly _opener: WKPage | null;
|
||||||
private readonly _requestIdToRequest = new Map<string, WKInterceptableRequest>();
|
private readonly _requestIdToRequest = new Map<string, WKInterceptableRequest>();
|
||||||
private readonly _workers: WKWorkers;
|
private readonly _workers: WKWorkers;
|
||||||
private readonly _contextIdToContext: Map<number, dom.FrameExecutionContext>;
|
private readonly _contextIdToContext: Map<number, dom.FrameExecutionContext>;
|
||||||
@ -65,7 +65,7 @@ export class WKPage implements PageDelegate {
|
|||||||
_initializedPage: Page | null = null;
|
_initializedPage: Page | null = null;
|
||||||
private _firstNonInitialNavigationCommittedPromise: Promise<void>;
|
private _firstNonInitialNavigationCommittedPromise: Promise<void>;
|
||||||
private _firstNonInitialNavigationCommittedFulfill = () => {};
|
private _firstNonInitialNavigationCommittedFulfill = () => {};
|
||||||
private _firstNonInitialNavigationCommittedReject = (e: Error) => {};
|
_firstNonInitialNavigationCommittedReject = (e: Error) => {};
|
||||||
private _lastConsoleMessage: { derivedType: string, text: string, handles: JSHandle[]; count: number, location: ConsoleMessageLocation; } | null = null;
|
private _lastConsoleMessage: { derivedType: string, text: string, handles: JSHandle[]; count: number, location: ConsoleMessageLocation; } | null = null;
|
||||||
|
|
||||||
constructor(browserContext: WKBrowserContext, pageProxySession: WKSession, opener: WKPage | null) {
|
constructor(browserContext: WKBrowserContext, pageProxySession: WKSession, opener: WKPage | null) {
|
||||||
|
@ -117,7 +117,10 @@ describe('Download', function() {
|
|||||||
expect(fs.readFileSync(path).toString()).toBe('Hello world');
|
expect(fs.readFileSync(path).toString()).toBe('Hello world');
|
||||||
await page.close();
|
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 });
|
const page = await browser.newPage({ acceptDownloads: true });
|
||||||
await page.setContent(`<a target=_blank href="${server.PREFIX}/download">download</a>`);
|
await page.setContent(`<a target=_blank href="${server.PREFIX}/download">download</a>`);
|
||||||
const [ download ] = await Promise.all([
|
const [ download ] = await Promise.all([
|
||||||
|
Loading…
x
Reference in New Issue
Block a user