Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
Cómo enviar mensajes desde el fondo al script de contenido

Mi secuencia de comandos en segundo plano tiene un bucle que sigue solicitando datos de una API . Intento enviar mensajes desde una secuencia de comandos en segundo plano a una secuencia de comandos de contenido, pero el mensaje no llega.

Obtuve el siguiente error:

 Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.

fondo.js

 setInterval(async () => { try { //get some data in an API //send the resuturn content to send message var port = chrome.runtime.connect({ name: "knockknock" }); port.postMessage({ joke: "Knock knock" }); port.onMessage.addListener(function (msg) { if (msg.question === "Who's there?") port.postMessage({ answer: "Madame" }); else if (msg.question === "Madame who?") port.postMessage({ answer: "Madame... Bovary" }); }); } catch (e) { console.error(e); }

}, 10000);

contenido.js

 chrome.runtime.onConnect.addListener(function (port) { console.assert(port.name === "knockknock"); port.onMessage.addListener(function (msg) { if (msg.joke === "Knock knock") port.postMessage({ question: "Who's there?" }); else if (msg.answer === "Madame") port.postMessage({ question: "Madame who?" }); else if (msg.answer === "Madame... Bovary") port.postMessage({ question: "I don't get it." }); });

});

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!