Open Bug 1459781 Opened 6 years ago Updated 2 years ago

service worker fetch event not happen when html generated from document.write

Categories

(Core :: DOM: Service Workers, defect, P3)

59 Branch
defect

Tracking

()

People

(Reporter: jamesyang999, Unassigned)

References

(Blocks 1 open bug)

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36

Steps to reproduce:

Using the code below:
https://gist.github.com/futurist/697b9d7153042dba4e53e9404509cf38

Online demo:
https://service-worker-fail-urzkvexbkh.now.sh/




Actual results:

The console log did not show the fetch event for `b.js`, since the url is generated by `document.write`



Expected results:

The console log should show the fetch event for `b.js`.
the tested firefox UA is "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:59.0) Gecko/20100101 Firefox/59.0"
Priority: -- → P3
Currently firefox implements the part of the html spec that creates a new window global on document.open().  There is nothing in the spec AFAICT, though, that causes the service worker controller from the original window to be inherited by the new window.  

This would be fixed by aligning the spec and firefox to other browsers in bug 1456313.
Depends on: 1456313
I see, may I ask how to get around with this problem when have to use `document.open`? Any solution for current version of FF?
NI myself to file a spec issue to determine what the correct service worker behavior should be here.  If the group agrees inheriting the service worker is desired we can possibly do a work around in gecko code to make it work that way.

Until then, though, I think the only work around would be to have your service worker provide the final html content directly via FetchEvent handling instead of using document.write().
Flags: needinfo?(bkelly)
I wrote a demo of the problem here:

https://sw-document-open.glitch.me/

Chrome and safari inherit the controller, but edge matches firefox behavior.

I wrote a spec issue to discuss what the desired behavior should be:

https://github.com/w3c/ServiceWorker/issues/1313
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(bkelly)
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.