GoogleChrome / GoogleChrome/workbox

Audio/Video element with preload can lead to precaching getting a 206 response and crashing

Open
#3,288 13 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
13k
Forks
880
Avg merge
2h 44m
Merged PRs (30d)
8

Description

**Library Affected**:
workbox-precaching

**Browser & Platform**:
Google Chrome 120.0.6099.199 Desktop

**Issue or Feature Request Description**:
On a page with an audio/video elements with `preload="auto"`, where workbox is also set to precache the audio/video src file, sometimes the service worker ends up getting a 206 in its install event for its precache request, which leads to the following error:
```
workbox-0f22832a.js:2064 Uncaught (in promise) TypeError: Failed to execute 'put' on 'Cache': Partial response (status code 206) is unsupported
at StrategyHandler.cachePut (workbox-0f22832a.js:2064:23)
at async PrecacheStrategy._handleInstall (workbox-0f22832a.js:3072:27)
at async PrecacheStrategy._handle (workbox-0f22832a.js:3005:18)
at async PrecacheStrategy._getResponse (workbox-0f22832a.js:2402:22)
cachePut @ workbox-0f22832a.js:2064
```

I'd assume it's taking the request to preload from the browser which has a `Range` request, before the pre-caching is done, and sending it to the network, trying to pre-cache based on it, instead of simply dropping the uncachable partial response, and still sending a normal pre-cache request separately.

I did follow https://developer.chrome.com/docs/workbox/serving-cached-audio-and-video (P.S. I guess the `cacheableResponse` plugin for this is redundant nowadays?)

_When reporting bugs, please include relevant JavaScript Console logs and links to public URLs at which the issue could be reproduced._
The site is private, I will create a standalone repro later on.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.