37

DevTip: Two steps for using Workbox in a Chrome Extension

 5 years ago
source link: https://www.tuicool.com/articles/hit/7NZFNra
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Recently the Chrome team enabled using service worker in Chrome Extensions, which is great news! Now we can intercept the extension requests which is good especially for caching and performance.

One library that really shines in terms of service worker caching is Google's Workbox but using it in a Chrome Extension is not that obvious so here is my tip:

iYreMrR.png!web
ruuQVb.jpg!web

Ido Shamun

@idoshamun

juMjqyB.png!web

#DevTip : Two steps for using @workboxjs in #ChromeExtension :

- disable precache as workbox can't handle chrome-extension schema

- add the following to your script-src csp storage.googleapis.com

Otherwise you will get these nasty errors!

14:32 PM - 24 Sep 2018

vmMNNbr.png!web 1 maa6Vna.png!web 1

If you are using the webpack plugin for workbox simply add:

exclude: [/.*/], as part of your configuration

In your extension manifest.json set the following:

"content_security_policy": "script-src 'self' https://storage.googleapis.com; object-src 'self'",

Let me know how it goes for you :)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK