Reputation: 3013
In a ServiceWorker
's onfetch
handler I want to be able to identify what page a Request
is coming from. For example, if I have 2 pages that both request /resource.js
, and this request is passed to the service worker (the onfetch
handler is called with a FetchEvent
), how do I tell if it is one instance of a page requesting /resource.js
twice, or 2 different pages requesting /resource.js
?
Is this possible?
Upvotes: 1
Views: 270
Reputation: 56064
It's not currently possible. The original poster seems to have already found and commented on https://github.com/slightlyoff/ServiceWorker/issues/723, but for the record, that's where it's currently being discussed in the service worker specification.
Once there's some agreement on the specification, you should expect browsers that support service workers to add in the functionality over time.
Upvotes: 2
Reputation: 1647
You might be able to use event.request.referrer
to identify the page from which request originates.
See: https://developer.mozilla.org/en-US/docs/Web/API/Request/referrer
Upvotes: 0