Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: clientURL property on FetchEvent #1532

Open
jeffposnick opened this issue Aug 21, 2020 · 3 comments
Open

Proposal: clientURL property on FetchEvent #1532

jeffposnick opened this issue Aug 21, 2020 · 3 comments

Comments

@jeffposnick
Copy link
Contributor

I have a use case for a new property, clientURL, being added to the FetchEvent interface.

In scenarios in which a FetchEvent's clientId is populated (including subresource requests), clientURL would be set to a URL string representing the client's current location. In scenarios in which clientId is not populated, it would be set to an empty string.

I would like to use this client URL information as part of an advanced routing option in the Workbox service worker framework—basically, to allow developers to opt-in to different routing and caching rules for subresource requests that originate from different logical sections of their web app, all from within the same registered service worker instance. In order to accomplish this, I need to obtain the client's full URL synchronously, so that within the fetch handler that Workbox sets up, a synchronous decision can be made about whether or not to call respondWith() on the FetchEvent.

There are some alternatives to creating a new property that rely on existing functionality, but neither is appropriate for my use case:

  • Similar information is already exposed synchronously via the request.referrer property of a FetchEvent when a lax Referrer-Policy is in effect, but when a more restrictive policy is in place, request.referrer may not contain the full URL.

  • Similar information is already exposed asynchronously by passing the clientId of a FetchEvent to clients.get(), and then obtaining the location of that return value.

@wanderview
Copy link
Member

If its not too expensive, we could even provide a Client object snapshot at the time of the fetch.

@wanderview
Copy link
Member

How would this work with resultingClientId and replacesClientId? Would it just not be populated?

@jeffposnick
Copy link
Contributor Author

I was assuming it wouldn't be populated for scenarios in which clientId wasn't populated.

Specifically, this is useful (for me, at least) only for subresource requests, when clientId would be populated. resultingClientId and replacesClientId only come into play during navigations, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants