WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
238866
ServiceWorker downloads do not start in reopened tabs
https://bugs.webkit.org/show_bug.cgi?id=238866
Summary
ServiceWorker downloads do not start in reopened tabs
mrskman
Reported
2022-04-06 06:37:47 PDT
Safari supports ServiceWorker downloads since 15.4 (Technology Preview 138). It is working great (big thank you for that) unless you want to do downloads in a reopened tab. How to reproduce #1: 1. Open a new tab and go to
https://stat-info.cz/safari-download-reopened-tab.html
. 2. Close the tab. 3. Reopen the closed tab (Menu -> Edit -> Undo Close Tab) 4. Download buttons are not working now. How to reproduce #2: 1. Set your Safari to open all windows from last session (Menu -> Safari -> Preferences -> General). 2. Open a new tab and go to
https://stat-info.cz/safari-download-reopened-tab.html
. 3. Quit Safari (Menu -> Safari -> Quit). 4. Start Safari again. 5. Download buttons are not working now. I expect both buttons to download file named file.bin (5 bytes). But it is working only in freshly opened new tab or after you do manual reload of the tab. Tested on Safari 15.4 and Technology Preview 142.
Attachments
Add attachment
proposed patch, testcase, etc.
Radar WebKit Bug Importer
Comment 1
2022-04-13 06:38:16 PDT
<
rdar://problem/91686107
>
youenn fablet
Comment 2
2022-04-13 07:26:11 PDT
Quickly looking at it, I can see that WebPage::didReceivePolicyDecision policyAction is set to 2 (ignore) in the download failure case while it is set to 1 (download) in the working case.
mrskman
Comment 3
2022-05-26 00:20:31 PDT
(In reply to youenn fablet from
comment #2
)
> Quickly looking at it, I can see that WebPage::didReceivePolicyDecision > policyAction is set to 2 (ignore) in the download failure case while it is > set to 1 (download) in the working case.
Is there any workaround for this? Is the "Service Workers" component category correct or should I change it? Thank you!
youenn fablet
Comment 4
2022-06-02 04:38:34 PDT
The workaround is to trigger the download synchronously as part of the click event handler. Then everything will work fine from there. This is not specific to service worker, I would expect that a setTimeout would also trigger that same behavior. This is controlled by Safari code and I am not sure why this behavior is like this. I will send the bug report there.
mrskman
Comment 5
2022-06-02 04:58:09 PDT
Downloads there are always asynchronous (navigator.serviceWorker.register is called first), so setTimeout is working fine until you reopen the tab. You can test it with the third button I've added.
youenn fablet
Comment 6
2022-06-02 05:55:48 PDT
(In reply to mrskman from
comment #5
)
> Downloads there are always asynchronous (navigator.serviceWorker.register is > called first), so setTimeout is working fine until you reopen the tab.
Right, so one workaround so far is to register a service worker specifically for downloads, in advance, then the download can be triggered synchronously in the click event handler.
> You can test it with the third button I've added.
Thanks for the updated test.
mrskman
Comment 7
2022-06-02 06:13:32 PDT
(In reply to youenn fablet from
comment #6
)
> Right, so one workaround so far is to register a service worker specifically > for downloads, in advance, then the download can be triggered synchronously > in the click event handler.
Which is pain if you need to negotiate the download with server first based on what user chooses. And then there is a chance, that browser has already unregistered the service worker. Anyway thank you!
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug