Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make an http request in the service worker Chrome extension?

I am trying to develop a Chrome extension. Now background scripts are replaced by service workers in manifest v3. How can I make an http request in the service worker?

like image 294
m97i Avatar asked Oct 20 '25 05:10

m97i


1 Answers

Use this in your service worker:

fetch('http://example.com/movies.json')
  .then((response) => response.json())
  .then((data) => console.log(data));

Don't forget to set proper permissions in the manifest file:

  "host_permissions": [
    "http://example.com/"
  ],
like image 158
Antonio Ercole De Luca Avatar answered Oct 21 '25 19:10

Antonio Ercole De Luca



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!