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

292
Views
Javascript envía un mensaje desde content.js a background.js

Leí algunos de los documentos de Chrome y obtuve este ejemplo básico funcionando.

Ahora quiero hacer la solicitud basada en un evento que está ocurriendo. El evento se activa y se ejecuta contentUpdateData(), pero chrome.runtime.sendMessage dentro de la función no parece funcionar. ¿Alguna idea de por qué?

 /* content.js */ var data = [] chrome.runtime.onMessage.addListener( function(request, sesnder, sendResponse) { if (request.message === 'popupClicked') { contentUpdateData(); } } ) function contentUpdateData() { console.log('Code works up to here. Button clicked in popup.html, recieved in content.js. Need to get info from background.js') chrome.runtime.sendMessage({greeting: "hello"}, function(response) { console.log(response.farewell); data = response.data }); }
 /* background.js basic example from chrome */ chrome.runtime.onMessage.addListener( function(request, sender, sendResponse) { console.log(sender.tab ? "from a content script:" + sender.tab.url : "from the extension"); if (request.greeting === "hello") sendResponse({farewell: "goodbye", data: null}); } );
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Debe return true desde el detector de eventos en backgroundjs. Esto guarda sendResponse() de la recolección de basura .

 chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { if (request.greeting === "hello") sendResponse({ farewell: "goodbye", data: null }); // VERY IMPORTANT return true; });
about 4 years ago · Juan Pablo Isaza Report

0

De alguna manera, background.js no se sincronizó correctamente después de actualizar la extensión. Esta fue la causa del error.

about 4 years ago · Juan Pablo Isaza Report
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!