Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

202
Visualizações
Socket.io and Chrome Extension MV3

I am trying to use socket.io in my chrome extension. I have setup express server and it is up and running perfectly includes socket.io as follow:

const express = require("express");
const cors = require("cors");
const http = require("http");
const { Server } = require("socket.io");
const app = express();
app.use(cors());
const httpServer = http.createServer(app);
const io = new Server(httpServer, {
    cors: {
        origin: "*",
    },
});

io.on('connection', (socket) => {
    //all of our things  we are going to use in sockets, different pipelines 
    console.log("User connected: " + socket.id);

    socket.on("Alert", (data) => {
        console.log(data);
    })
});

I have tried adding socket.io in manifest content_scripts js as follow:

"content_scripts": [
     {
       "js": [
         "socket.io.4.5.1.js"
        ]
     }
]

and content.js file includes following code as below:

const socket = io('ws://localhost:3001');
socket.on('connection');

After getting above setup when I try to load chrome extension, it displays an error that Uncaught ReferenceError: io is not defined in content.js. Along with this I also get an other error of Uncaught SyntaxError: Unexpected token 'export' in my socket.io file.

I have tried having look in community asked question but couldn't get any fix for this. The one thing I am assuming from wOxxOm answer from here is that I can not use MV3 if need to use socket.io If I can not use it then what is the best other way round as I need to communicate with my server for multiple times and couldn't use an API due to frequent updates on page content.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use socketio in service worker itself, to keep service worker up you need to open a window thread, you can create it by using chrome.windows.create function, see more on javascript documentation. We are using it same way and this approach worked for us.

Additionally if socket io uses window or document, then use jsdom to make window and document available.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda