I want to use socket.io in its extension, but when I import the library, it throws the error "Uncaught ReferenceError: document is not defined". I realized that this socket.io does document and window checks, however, in the background.js I can't use either the document API or the window object. I use manifest v3. What should I do to use sockets?
Asked
Active
Viewed 153 times
2
-
You can't use it in a ManifestV3 service worker. You'll have to open a separate tab. This is yet another use case broken in ManifestV3. – wOxxOm Oct 08 '21 at 09:08
-
@wOxxOm, but what can I do? I need to use Socket.io – Slava Oct 08 '21 at 09:13
-
Don't use ManifestV3, which is still actually half-broken, or always keep an open tab. – wOxxOm Oct 08 '21 at 09:16
-
@wOxxOm, but the problem is the same, as due to the transition to the second version of the manifest, I will be able to use socket.io when the problem is that socket io is doing a document and window check that are not available in the background – Slava Oct 08 '21 at 09:34
-
No, in ManifestV2 you will use a standard background page script which has document and window. – wOxxOm Oct 08 '21 at 09:36
-
Okay, I'll try to use it – Slava Oct 08 '21 at 09:39
-
@wOxxOm, still exist https://i.imgur.com/qZnMVAw.png – Slava Oct 08 '21 at 10:30
-
You're seeing an old error. Click the `clear all` button to remove it and use [background.js console](/a/10258029). Also don't forget to reload the extension. – wOxxOm Oct 08 '21 at 10:43