D
D
dy_ma2020-08-11 14:04:09
JavaScript
dy_ma, 2020-08-11 14:04:09

How to send message from background to popup?

You can send a message from popup.js to the background (chrome.runtime.sendMessage), and get the response in the callback. But if the response cannot be sent immediately, then the connection is closed.
It would be convenient to make a message listener in the popup, like this:

// popup.js
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
  console.log(msg);
});

To be able to send a message from the background at any time like this:
// background.js
chrome.tabs.sendMessage(id, data, function (r) {
  console.log(r);
});

Is it possible to do something similar?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-08-11
@dy_ma

https://developer.chrome.com/extensions/messaging#...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question