Skip to content
Advertisement

javascript how to modify the current response in service worker?

I use service worker to modify the fetch response with below code,

JavaScript

Whichi will lead to this warning and error,

The FetchEvent for “” resulted in a network error response: the promise was rejected.

sw.js:60 Uncaught (in promise) TypeError: Failed to execute ‘clone’ on ‘Response’: Response body is already used at sw.js:60


If I put the clone() before arrayBuffer() like below,

JavaScript

It will lead to below warning and error,

The FetchEvent for “” resulted in a network error response: a Response whose “body” is locked cannot be used to respond to a request.

GET http://localhost/web/357765_decrypted.mp4 net::ERR_FAILED

Advertisement

Answer

Try instantiating and returning a new Response() with the decrypted bytes:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement