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

should EventSource bypass service worker interception? #885

Closed
wanderview opened this issue Apr 15, 2016 · 8 comments
Closed

should EventSource bypass service worker interception? #885

wanderview opened this issue Apr 15, 2016 · 8 comments

Comments

@wanderview
Copy link
Member

Currently we support intercepting EventSource. I'm even adding a wpt test for this since its a way to observe a different FetchEvent.request.cache value.

While writing that test, though, it became apparent that EventSource is currently difficult to use with ServiceWorker. EventSource is designed with the idea that the connection will be held open and lines will be flushed across the connection to trigger events. This is quite difficult to do today with synthetic responses. It might be possible in the future with streams, but you would still have to hold the SW alive.

@sicking suggested that we might want to treat EventSource like WebSocket and just bypass the service worker for now.

I feel like this is kind of a low priority item, but wanted to file the issue so we don't lose track of it.

@annevk
Copy link
Member

annevk commented Apr 16, 2016

WebSocket is special in that it's an HTTP handshake and then uses the connection for something else. EventSource is just like any other API that fetches something, it's just by design a longer-lived transaction, but that is not too different from <video> or <audio> really.

@annevk
Copy link
Member

annevk commented Apr 16, 2016

Also, in the no-streams scenario the service worker would just return the response from the server directly and then the user agent can close the service worker, right? There's no need to wait for end-of-file unless the developer is trying to observe it. And again, that would be no different from other places that fetch.

@NekR
Copy link

NekR commented Apr 16, 2016

Anne's explanation sounds right to me

@wanderview
Copy link
Member Author

Yes, but I believe the browser will immediately trigger another connection unless you send evenetsource content providing a retry delay, etc. So in the naive case it will keep spinning up the service worker over and over again.

@annevk
Copy link
Member

annevk commented Apr 18, 2016

If the connection closes for some reason, sure. But that's not the common scenario and also does not seem like a good enough reason. It's still equivalent to all other things that fetch.

@wanderview
Copy link
Member Author

Well, "closes for some reason" means passing anything to evt.respondWith() in a no-streams implementation. The network connection is considered closed immediately after processing that Response body which will be fixed length.

I'm fine continuing to intercept EventSource. To be honest, I doubt many people will ever run into this interaction. Its just a bit wonky to use with ServiceWorkers.

@annevk
Copy link
Member

annevk commented Apr 18, 2016

Passing a network response (whose body is streaming) to it should work, no?

@wanderview
Copy link
Member Author

Right. It should.

I'll just close this for now.

bibyzan pushed a commit to bibyzan/stitch-js-sdk that referenced this issue May 2, 2019
…e worker onFetch implementation and lets the browser handle the request, specific to angular.

Background on root issue w3c/ServiceWorker#885
Issue leading to work around angular/angular#21191
Workaround that checks for the header petersalomonsen/angular@c7b357a
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

4 participants
@NekR @wanderview @annevk and others