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

Safari Support #69

Open
aileen-shih opened this Issue Sep 10, 2018 · 6 comments

Comments

Projects
None yet
3 participants
@aileen-shih
Copy link

aileen-shih commented Sep 10, 2018

First of all, just want to thank you for this great work, it works beautifully in Chrome!

I see Safari's missing support for serviceWorker is already supported in their latest version 11.1. https://caniuse.com/#search=serviceWorker
So I tested in v11.1.2 Safari but it is not working, am I missing something?
(for testing, I removed support check for WritableStream)

@jimmywarting

This comment has been minimized.

Copy link
Owner

jimmywarting commented Sep 10, 2018

safari supports both ReadableStream and service worker. But it seems like they have some bug when it comes to assemble a response with a stream and returning it.

stream = new ReadableStream({
  start(controller) {
    controller.enqueue(uint8array)
  }
})
response = new Response(stream, { headers })
respondWith(response)
@alippai

This comment has been minimized.

Copy link

alippai commented Sep 26, 2018

What about Safari 12 now? Did anybody test it? :P

@alippai

This comment has been minimized.

Copy link

alippai commented Sep 26, 2018

May this statement "The implementation does not support ReadableStreamBYOBReader." cause the problem? https://webkit.org/status/#feature-readable-streams

@jimmywarting

This comment has been minimized.

Copy link
Owner

jimmywarting commented Sep 26, 2018

I tested safari like 3 days ago. My plan later is not to use PostMessage but to use the fetch api once request.body is available in as a readable stream. Safari was first to implement it in request

The idea is just to pipe the request back to response
something like this:

onfetch = evt => {
  const { request } = evt
  const response = new Response(request.body, {
    headers: new Headers(request.headers)
  })
  evt.respondWith(response)
}

It worked just fine to stream the request back to the response but whenever i added the content-disposition header if would just fail with a 404 result. So i tried other hack: When Content-Type is set to something that the browser can't handle like a application/zip it will download it also using the url's filename if no attachment header is available. but it was same problem there as well :(

So i tried with simple Content-Type: text/html it works, it's displayed properly... now add download attribute to the link and press it - fail 😢

The problem don't seem to be BYOB reader or any readable stream. It seems to me whenever safari would like to save something. it switches techniques and tries fetch the url directly instead of going throught with what the service worker respond with.

A simple example such as this dose not work:

event.respondWith(new Response('hi', {
  headers: {
    Content-Disposition: attachment; filename="world.txt"
  }
}))

Then we are not even using streams... the result is you download some file but it's not the content you responded with. it's the response you would get as if you didn't used service worker.

somebody should report this...

@alippai

This comment has been minimized.

Copy link

alippai commented Sep 26, 2018

Added as a quick comment here: https://bugs.webkit.org/show_bug.cgi?id=167341
I'm not sure, the issues are connected, however Frédéric Wang's comment could cause this behavior.

@jimmywarting

This comment has been minimized.

Copy link
Owner

jimmywarting commented Sep 26, 2018

Thanks the "decide policy for navigation action" seems to be in wrong order...?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment