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
Interception of the fallback requests initiated from a SW for cross-origin resources #684
Comments
I'd be interested to hear peoples' thoughts on whether another use case for this could be for a cross-origin Service Worker to provide an HTTP web service which works even when offline mkruisselbrink/navigator-connect#23 This has been discussed as a use case on Mozilla's dev-webapi mailing list https://groups.google.com/forum/#!msg/mozilla.dev.webapi/2NWlXa9SlqY/mQ0zBI1SChUJ This could provide an avenue to replace many of Gecko's current proprietary APIs with potentially more webby solutions. |
You could have: // https://foo/sw.js
self.oninstall = event => {
event.waitUntil(
event.registerExternal('//font-service/sw.js')
);
};
// https://font-service/sw.js
self.oninstall = event => {
event.handleFallThroughRequests(['/resources', '/font']);
// …
}; URLs passed to My questions/concerns about this model:
|
@jakearchibald is your proposal that I don't think either way that this will significantly increase the number of workers that may be needed to display a single page. After all there already is a problem with things like social network "like" buttons, ads, and probably many more things that are typically implemented with iframes, which all potentially can have their own service workers. The update thing is a good question. I haven't really thought about that. On one hand I'm tempted to say to just leave this up to user agents (after all, a user agent is already allowed to call the Soft Update algorithm as often as it wants), but then on the other hand this does feel like something that should somehow be specced. |
That was my thinking. But at a minimum (if we have this feature) I should be able to specify another service as an install dependency.
Should we be adding to that problem? |
Per conversations in SF today, a few points that seem relevant:
|
Furthermore, if a new version fails to call
I still don't think this is necessary. The fall-through worker will be able to inspect the request and should be given details on the origin that will get access to the response. It'll be able to make a call without preflight access.
I'm not convinced opaque responses from a third party services are useful. One of the key usecases we have is fonts, and they require CORS. Isn't the new event name enough of an explicit action? |
CORS preflight is about protecting servers. In the case of a service worker that opts in there is nothing to protect so they should certainly not go there. |
https://wiki.whatwg.org/wiki/Foreign_Fetch is Mozilla's proposal, for the record. |
Was there any discussion on this in the face to face meeting this week? Any conclusions/meeting notes? |
I believe we had consensus that implementing a fallback- or foreign-fetch API was preferred to a postMessage-like API for the initial use cases. We just need to work through differences in our proposal and get it spec'd. I didn't get the sense that there were any major sticking points, but I guess we will see. I guess my personal hope is that this could be spec'd in Q3 and maybe first implementations could start showing up in Q4. |
Yes, that's pretty much what I think the consensus was as well. Both proposals are pretty similar so it's just a matter of working out details and speccing it out (and hope that the various security teams etc are happy with such an API). |
I started putting together a bit more of a concrete proposal in https://gist.github.com/mkruisselbrink/f6957bece64740926b84 although as I was doing so I realized I should probably just put this in a fork/pull request for the actual service worker spec, so unless somebody objects I'll start doing that and making the proposal even more concrete sometime next week. |
Can we call it foreign fetch? I find that much more clear. The service worker is already doing fetch interception. |
Pull request #749 (also visible at http://mkruisselbrink.github.io/ServiceWorker/spec/service_worker/) is my initial attempt at spec-ing this feature. I'm sure many refinements are still needed, so any comments are welcome. |
This fixes w3c#684.
While discussing use cases for
navigator.connect()
, we've encountered a case where interception of the fallback requests to a third-party resources and serving them through a cross-origin SW would greatly help the overall resource management. Here's the use case and the proposed extension API that enables the communication between a client SW and a service SW:https://github.com/mkruisselbrink/navigator-connect/blob/gh-pages/explainer.md#solving-the-fonts-problem
A service opts in to handle clients' fallback requests by calling
e.handleFallThroughRequests
from within itsoninstall
event listener. Then, the requests initiated from a client SW are intercepted, and fetch events tagged withe.isFallThrough
set to true are dispatched to the service SW instead of going out to the network.It was originally discussed as part of the
navigator.connect()
spec, but agreed to be proposed as an extension to the SW API (v2): mkruisselbrink/navigator-connect#28Comments would be appreciated.
The text was updated successfully, but these errors were encountered: