question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

browser.runtime.onMessage.addListener only accepts 2 arguments

See original GitHub issue

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/onMessage

The actual browser.runtime.onMessage.addListener accepts 3 arguments:, message, sender, sendResponse. However, the current implementation only accepts 2 arguments: message, sender

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
brnbscommented, Apr 27, 2021

I landed here from Chrome Developer website where I found no mention about returning a Promise, however I gave it a try and just wanted to confirm that this works the same as calling sendResponse:

browser.runtime.onMessage.addListener((message: string) => {
    if (message == "whatever") {
        // Do something
        return Promise.resolve("response");
    }
});
2reactions
joshsmithcommented, Aug 3, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

runtime.onMessage - Mozilla - MDN Web Docs
This argument is passed back to the message sender. If you have more than one onMessage() listener in the same document, then only...
Read more >
runtime.sendMessage doesn't pass callback to onMessage ...
It appears that the implementation of runtime.sendMessage accepts a callback as the second argument, but doesn't actually pass it to the ...
Read more >
onMessage.addListener : sendResponse
I am coding a chrome extension and have 2 JS scripts, "script.js" and "background.js". In my script.js, I am using chrome.runtime.sendMessage to ...
Read more >
onMessage listener is installed multiple times in a content ...
chrome.runtime.onMessage.addListener(function(message, sender, sendResponseFn){ ...} in it will install the listener repeatedly and will thus lead to ...
Read more >
runtime.onMessage
sendMessage() or (to send a message to a content script) tabs. ... The function takes a single argument, which may be any JSON-ifiable ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found