Skip to content

Service worker doesn't support seeking in videos #25865

Closed as not planned
Closed as not planned

Description

@tehXor

I'm submitting a...


[x] Bug report  
[x] Feature request (not sure, maybe this is more a feature request?)

Current behavior

If you ng run app:build:production and your pwa comes with a <video> element where you also utilize seeking (setting currentTime depending on your app logic and/or user input) it will not work or only very inconsistently. Most videos will simply run from start and not at the setted currentTime position. This is only the case when videos are delivered/fetched by the service worker. So it works in development mode.

Expected behavior

Videos should start at the setted currentTime.

Minimal reproduction of the problem with instructions

// on template
<video id="myVideo"><source id="myVideoSrc" src="video.mp4" type="video/mp4"></video>

// in page.ts
let videoObject = document.getElementById("myVideo");
videoObject.currentTime = 100;
videoObject.play();

// now build for production
// @angular/pwa has to be installed
> ng run app:build:production

Environment

Angular version: 6.1.2

Browser:
Chrome (desktop) version 69

Others:

This seems to be a known problem since service workers don't know Range requests. However it also looks like very easily fixable if I understand this thread comment correctly: https://bugs.chromium.org/p/chromium/issues/detail?id=575357#c10

A workaround would be a convenient way to completely exclude requests from service worker (not just set strategies for them). But obviously it would be better if we also could cache some videos. For exclusion also this issue may be relevant : #21191

EDIT(gkalpak): Issue summary in #25865 (comment).

Activity

  1. added
    area: service-worker
    on Sep 7, 2018
  2. added this to the needsTriage milestone on Sep 7, 2018
  3. gkalpak commented on Sep 17, 2018

    @gkalpak
    Member

    Fixing #21191 would indeed provide a workaround for this usecase (but this could be properly fixable on its own as well).
    Does anyone want to take a stub at incorporating this fix into @angular/service-worker.

  4. mordka commented on Nov 30, 2018

    @mordka

    We hit this issue, because requests to video needed to be withCredentials and SW failed over without applying cookies to headers. A workaround was to skip handling request via SW. We used patch-package to maintain this patch. Here is the patch

    diff --git a/node_modules/@angular/service-worker/ngsw-worker.js b/node_modules/@angular/service-worker/ngsw-worker.js
    index 51c431b..1216506 100755
    --- a/node_modules/@angular/service-worker/ngsw-worker.js
    +++ b/node_modules/@angular/service-worker/ngsw-worker.js
    @@ -1896,6 +1896,10 @@ ${msgIdle}`, { headers: this.adapter.newHeaders({ 'Content-Type': 'text/plain' }
              */
             onFetch(event) {
                 const req = event.request;
    +            //PATCH to prevent caching certain kinds of requests
    +            // - PUT requests which breaks files upload
    +            // - requests with 'Range' header which breaks credentialed video irequests
    +            if (req.method==="PUT" || !!req.headers.get('range')) return;
                 // The only thing that is served unconditionally is the debug page.
                 if (this.adapter.parseUrl(req.url, this.scope.registration.scope).path === '/ngsw/state') {
                     // Allow the debugger to handle the request, but don't affect SW state in any
    
    
  5. marod424 commented on Dec 10, 2018

    @marod424

    @mordka Thank you for your suggested fix.

    I was having a slightly different issue where range requests were breaking audio in Safari due to the SW failing to apply the Content-Range header. I applied the range header patch using patch-package and it fixed the issue.

  6. added
    feature
    on Apr 23, 2019
  7. modified the milestones: needsTriage, Backlog on Apr 23, 2019
  8. fergalmoran commented on Jun 9, 2019

    @fergalmoran
  9. tehXor commented on Jun 10, 2019

    @tehXor
    Author

    Turns out this is actually fixed now by appending ngsw-ignore to your querystring or as a header.
    https://github.com/angular/angular/blob/master/aio/content/guide/service-worker-devops.md

    That is just another workaround to ignore videos (though it is one of the best workarounds in that regard so far).
    But you still cannot include videos in your service worker's caching strategy when you need seeking. So no, I wouldn't say this is fixed.

  10. gkalpak commented on Jun 10, 2019

    @gkalpak
    Member

    As mentioned in #25865 (comment), if someone wants to take a stub at incorporating range handling into the SW, I'd be happy to help/review. How do other implementations (e.g. workbox) handle this?

  11. 24 remaining items

  12. muuvmuuv commented on Mar 10, 2023

    @muuvmuuv

    Hm, what is needed here to get this to work properly?

    In our case, we load many PDFs, each must be cached for offline usage, which works, but range requests do not. Weirdly, it only does not work for giant PDFs, above 6 MB.

  13. StrixOSG commented on Dec 14, 2023

    @StrixOSG

    Same issue here with range requests and the service worker. We're using @philnash's patch, but we shouldn't have to. Any updates on this?

  14. nabby27 commented on May 1, 2024

    @nabby27

    I would like this issue to be resolved, which is why I have posted a $60 reward. I would like to contribute but I don't have time to solve it and that's why I thought that a monetary contribution could help attract people who want to help (especially seeing that it is an issue that has been open for quite some time)

  15. turijanAldo commented on Nov 25, 2024

    @turijanAldo

    If the video file is still being served by the Service Worker, you can force the video to load directly from the network by appending a unique parameter to the video URL, such as a timestamp or identifier:

    const videoElement = document.getElementById('myVideo');
    const videoSource = document.getElementById('myVideoSrc');
    videoSource.src = video.mp4?nocache=${Date.now()}; // Prevent caching
    videoElement.load();
    videoElement.currentTime = 100;
    videoElement.play();

    If you need to serve large videos, consider configuring a web server with range request support, such as Nginx or Apache. This ensures that the browser can handle seeking (currentTime) properly.

  16. Beanminchild commented on Feb 19, 2025

    @Beanminchild
    Contributor

    #60007

    Hey i took a stab at it ... is this looking like what you all wanted to do?

    I just made a quick draft to confirm if this is the solution desired since there was a lot of discussion over this. Open to any and all feedback or requested changes.

  17. Beanminchild commented on Feb 20, 2025

    @Beanminchild
    Contributor

    can anyone take a look and tell me if im missing anything ? i think this is all we need to do.

  18. Beanminchild commented on Jun 22, 2025

    @Beanminchild
    Contributor

    @nabby27 hey i fixed this issue can i get the opire bounty?

  19. added a commit that references this issue on Mar 2, 2026
    a1ff4cb
  20. arturovt commented on Sep 29, 2026

    @arturovt
    Contributor

    @JeanMeche this can be closed. Range request support is a new feature for the service worker, and the package is in maintenance mode where only security fixes are accepted. Open since 2018 at P4, so it is not going to happen.

  21. JeanMeche commented on Sep 29, 2026

    @JeanMeche
    Member

    Per

    # @angular/service-worker
    IMPORTANT: The Angular Service Worker is a basic caching utility for simple offline support with a limited featureset. We will not be accepting any new features or bug fixes other than security fixes. For more advanced caching and offline capabilities, we recommend exploring native browser APIs directly.
    Implements a service worker for Angular apps.
    For more information, see the [`@angular/service-worker` API documentation](https://angular.dev/api/service-worker).

    We'll be closing this issue.

  22. angular-automatic-lock-bot commented on Oct 30, 2026

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  23. locked and limited conversation to collaborators on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4area: service-workerbrowser: safarifreq2: mediumopen for contributionsstate: confirmedtype: bug/fixworkaround2: non-obvious

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions