Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket.io v3 client from within chrome extension Uncaught ReferenceError: window is not defined

I am seeing this error Uncaught ReferenceError: window is not defined in my chrome extension when I update the socket.io library from v2.3.0 to v3.1.0

If I leave the old socket.io client, it seems unable to work with socket.io server 3.1.0 (I see this message on the request from browser developer tools network tab: {"code":5,"message":"Unsupported protocol version"} with an http 400 bad request )

Is there an issue with socket.io v3.x and chrome extension?

thank you

like image 436
teaoverflow Avatar asked Jan 18 '21 19:01

teaoverflow


1 Answers

v3 change way for setup: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/index.html

Сrucial point it's explicitly, set cors policy in initialization:

 const io = new Server(server, { cors: { origin: "*" } });
like image 87
Dimitir Avatar answered Jan 04 '23 07:01

Dimitir