https://264-education-heitbuiyfy.now.sh/
Visit the reproduction link in any browser / OS combination and the video plays without problems. Do so on Mobile Safari on iOS and the video freezes after 1–3s and / or doesn’t load at all.
This only happens when the pwa-module (the workbox part of it) is used. The video then plays only the very first time and often freezes after 1–3s, often it doesn’t load / play at all.
This issue looks very similar to this https://github.com/angular/angular/issues/23447 Angular issue, so it might be a core problem inside iOS / their SW implementation? I am not sure, I just ran into this.
I have tried explicitly ignoring the file with globIgnores and/or exclude, but wasn’t successful.
Thank you in advance, I appreciate it and the work you have put into this. :)
Video should play when SW is activated in any browser / on any OS.
Video freezes after 1–3s and / or doesn’t play on Mobile Safari on iOS when SW is activated.
Can confirm this happens
I was trying resolving this issue by adding workbox range-request plugin:
// plugins/workbox-range-request.js
workbox.routing.registerRoute(
/.*\.(mp4|webm)/,
workbox.strategies.cacheFirst({
plugins: [
new workbox.rangeRequests.Plugin(),
],
}),
'GET'
);
// nuxt.config.js
{ workbox: { cachingExtensions: '@/plugins/workbox-range-request.js' } }
We can't use routingExtensions because it's generated after default routes (https://github.com/nuxt-community/pwa-module/blob/develop/packages/workbox/templates/sw.template.js#L27), all requests that matches default routes won't be handled by custom routes.
We can't use strategyOptions because it's JSON stringified when rendering (https://github.com/nuxt-community/pwa-module/blob/develop/packages/workbox/templates/sw.template.js#L14). new workbox.rangeRequests.Plugin is not a plain js object.
Please see if it helps
Docs: https://developers.google.com/web/tools/workbox/modules/workbox-range-requests
@CarterLi Has that resolved the issue for you? The Angular thread I linked above also mentions the range-request plugin.
@mixn Yes. SW can correctly return 206 when using range-request plugin.
Thanks, @CarterLi. Added the to docs.
I'm unsure if this is the issue I am hitting, but videos will not ever load on Safari. It tries to grab them from the service worker and fails every time. Any ideas?
I'm unsure if this is the issue I am hitting, but videos will not ever load on Safari. It tries to grab them from the service worker and fails every time. Any ideas?
Hi @rwwagner90,
I had the same problem and the solution of this issue fixed it for me.
Do you still have the problem?
@mirkopoloni I am trying the fix now. I did not see that there was a recommended fix. If this is necessary to have video files, why is it not included by default?
@rwwagner90 I didn't investigate why the solution isn't included by default and I can't answer this question.
Maybe someone else can tell us more about this.
Hope it solved your problem.
It seems that APIs are changed in workbox 5.x. Scripts updated:
/* eslint-disable no-undef */
workbox.routing.registerRoute(
/.*\.(mp4|webm)/,
new workbox.strategies.CacheFirst({
cacheName: 'videos',
plugins: [
new workbox.rangeRequests.RangeRequestsPlugin(),
],
}),
'GET'
);
@CarterLi do we need to support both, based on what Safari version a user might have?
@CarterLi do we need to support both, based on what Safari version a user might have?
What did you mean with based on what Safari version a user might have
@CarterLi I mean based on the Safari version the user has, wouldn't the API be different? This new version works in new Safari I assume?
Hi, are there any news on this ? I'm still facing issues with videos on Safari.
Most helpful comment
I was trying resolving this issue by adding workbox range-request plugin:
We can't use
routingExtensionsbecause it's generated after default routes (https://github.com/nuxt-community/pwa-module/blob/develop/packages/workbox/templates/sw.template.js#L27), all requests that matches default routes won't be handled by custom routes.We can't use
strategyOptionsbecause it's JSON stringified when rendering (https://github.com/nuxt-community/pwa-module/blob/develop/packages/workbox/templates/sw.template.js#L14).new workbox.rangeRequests.Pluginis not a plain js object.Please see if it helps
Docs: https://developers.google.com/web/tools/workbox/modules/workbox-range-requests