Reputation:
I am trying to make my chrome extension using socket.io, but I am facing a lot of difficulties importing the socket.io client into my application.
I am using Manifest V3 which means I only have one service_worker, so I tried using importScripts
but that does not work for some reason. I cannot call the io()
function after using importScripts
. Then I tried changing the Content Security Policy to get it from the CDN but I get an error saying that it's invalid.
Any idea on how I can do this?
Upvotes: 0
Views: 310
Reputation: 201
About the importScripts
, you can try to bundle the background script by using webpack, rollup or esbuild. This will make it more complicated, or you can search a boilerplate on github.
Service worker may be inactive at any time. so that you won't be able to stay connected to the server all the time when you use socketio on service worker. Otherwise you need some hack to keep service worker alive. For example, content scripts sendMessage
to it orderly and continuously. (I just imagined it this way but haven't try it yet.)
Upvotes: 1