Downloads triggered by a link with target="_blank" are not linked to their navigation
Categories
(Remote Protocol :: WebDriver BiDi, defect, P2)
Tracking
(firefox150 fixed)
| Tracking | Status | |
|---|---|---|
| firefox150 | --- | fixed |
People
(Reporter: hbenl, Assigned: Sasha)
References
(Blocks 1 open bug)
Details
(Whiteboard: [webdriver:m19], [wptsync upstream])
Attachments
(4 files)
When a download is triggered by a click on a link with target="_blank", the navigation property of the download events is set to null even though the click does trigger a browsingContext.navigationStarted event.
This can be reproduced by modifying this test:
Comment 1•4 months ago
|
||
Good catch. We match downloadWillBegin with a navigation based on the fact that they have the same navigable id: https://searchfox.org/firefox-main/rev/c82adde571c24d89da3ef13f11245c8f572ba1e6/remote/shared/NavigationManager.sys.mjs#762-785
#onDownloadStarted = (eventName, data) => {
const { download } = data;
const contextId = download.source.browsingContextId;
const browsingContext =
lazy.NavigableManager.getBrowsingContextById(contextId);
if (!browsingContext) {
return;
}
const navigableId =
lazy.NavigableManager.getIdForBrowsingContext(browsingContext);
const url = download.source.url;
const navigation = this.#navigations.get(navigableId);
let navigationId = null;
if (navigation && navigation.state === NavigationState.Started) {
// navigationId is optional and should only be set if there is an ongoing
// navigation.
navigationId = navigation.navigationId;
// Track the navigation id for this download object, for the upcoming
// NAVIGATION_EVENTS.DownloadEnd event.
this.#downloadNavigations.set(download, navigationId);
}
In this case, the download is registered for the browsing context where the link is located, but the navigation is registered for another (temporary?) context.
Updated•4 months ago
|
| Reporter | ||
Comment 2•4 months ago
|
||
This Playwright test is failing due to this issue.
What I found in the HTML spec:
The Beginning Navigation algorithm creates a navigationId in step 7. and passes it to Attempt to populate the history entry's document in step 23.9. That algorithm passes the navigationId to Handle as a download in step 5.5.5.1. and that algorithm sets the navigationId in the BiDi download events.
However, when following this path of the spec, the navigable for the BiDi navigation started event (step 17. in Beginning Navigation) is the same as in the download events. I couldn't find anything in the spec that "retargets" the download from a popup's initial navigation to the popup's opener, which is what Playwright expects here.
| Assignee | ||
Updated•1 month ago
|
| Assignee | ||
Comment 3•1 month ago
|
||
Ok, so reading the spec, the most reasonable thing for me was to map the downloadWillBegin to the navigationStarted event, so use the same navigationId as the navigation from the temporary browsing context. As Holger said, there is no retargeting, so the spec implies that we should map the download to the navigation (even if it happens in the temporary browsing context). We can do this by checking the opener of the browsing context that started navigation (comparing it to the browsing context that triggers download). With the fix, the mentioned Playwright test started passing.
BUT now running the tests in CI it looks like we cannot guarantee that we will detect this navigation (e.g., https://treeherder.mozilla.org/logviewer?job_id=549729753&repo=try&task=MZN-Wqy5Qz-RphrWL8Wnfw.0&lineNumber=6837, there is no navigationStarted event). From the download event, as far as I know, we cannot understand that it came not from the link, so we cannot just create a new navigation if it's missing.
We could theoretically create navigations for all downloads (if it's missing), but as far as I know, that's not what we want. So I guess we need something to tell us where the download comes from.
| Assignee | ||
Comment 4•1 month ago
|
||
| Assignee | ||
Comment 5•1 month ago
|
||
| Assignee | ||
Comment 6•1 month ago
|
||
Updated•1 month ago
|
Updated•1 month ago
|
| Assignee | ||
Comment 7•1 month ago
|
||
Comment 10•1 month ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/897dc490588c
https://hg.mozilla.org/mozilla-central/rev/b69126a93461
https://hg.mozilla.org/mozilla-central/rev/c8432f0bfa4c
https://hg.mozilla.org/mozilla-central/rev/b723de799a41
Description
•