Skip to content
Merged
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
22 changes: 22 additions & 0 deletions packages/playwright-core/src/server/bidi/bidiPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export class BidiPage implements PageDelegate {
eventsHelper.addEventListener(bidiSession, 'browsingContext.historyUpdated', this._onHistoryUpdated.bind(this)),
eventsHelper.addEventListener(bidiSession, 'browsingContext.domContentLoaded', this._onDomContentLoaded.bind(this)),
eventsHelper.addEventListener(bidiSession, 'browsingContext.load', this._onLoad.bind(this)),
eventsHelper.addEventListener(bidiSession, 'browsingContext.downloadWillBegin', this._onDownloadWillBegin.bind(this)),
eventsHelper.addEventListener(bidiSession, 'browsingContext.downloadEnd', this._onDownloadEnded.bind(this)),
eventsHelper.addEventListener(bidiSession, 'browsingContext.userPromptOpened', this._onUserPromptOpened.bind(this)),
eventsHelper.addEventListener(bidiSession, 'log.entryAdded', this._onLogEntryAdded.bind(this)),
];
Expand Down Expand Up @@ -217,6 +219,26 @@ export class BidiPage implements PageDelegate {
event.defaultValue));
}

private _onDownloadWillBegin(event: bidi.BrowsingContext.DownloadWillBeginParams) {
if (!event.navigation)
Copy link
Member

Choose a reason for hiding this comment

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

Does it mean the code only applies to the navigations converted into downloads or what is this check for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

event.navigation is required by _downloadCreated(), I could have used event.navigation! since I expect these events to always set it (including when the link contained a download attribute) but I prefer to avoid ! in Typescript.

return;

let originPage = this._page.initializedOrUndefined();
// If it's a new window download, report it on the opener page.
if (!originPage && this._opener)
originPage = this._opener._page.initializedOrUndefined();
if (!originPage)
return;

this._browserContext._browser._downloadCreated(originPage, event.navigation, event.url, event.suggestedFilename);
}

private _onDownloadEnded(event: bidi.BrowsingContext.DownloadEndParams) {
if (!event.navigation)
return;
this._browserContext._browser._downloadFinished(event.navigation, event.status === 'canceled' ? 'canceled' : undefined);
}

private _onLogEntryAdded(params: bidi.Log.Entry) {
if (params.type !== 'console')
return;
Expand Down
Loading