sendMessage requires synchronous response

RESOLVED INVALID

Status

()

Toolkit
WebExtensions: Untriaged
RESOLVED INVALID
2 years ago
2 years ago

People

(Reporter: daleharvey, Unassigned)

Tracking

(Blocks: 1 bug)

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

2 years ago
I have an addon that calls

    chrome.runtime.sendMessage(json, function (response) {
      console.log(response);
    });

It is handled basically like: 

    chrome.runtime.onMessage.addListener(function (req, sender, respond) { 
      var response = localSorage['things'];
      respond(response);
    });

However if I try to switch to chrome.storage (that has an async api, or even if I just

    chrome.runtime.onMessage.addListener(function (req, sender, respond) { 
      var response = localSorage['things'];
      setTimeout(function() { 
        respond(response)
      });
    });

Then the called never gets the response
(Reporter)

Updated

2 years ago
Blocks: 877648
(Reporter)

Comment 1

2 years ago
Fabrice if you know who would be good to get this in front of it would be useful, cheers, ill stop bothering you shortly when I have more of an idea who else is working on the addon stuff
Flags: needinfo?(fabrice)
Please read the docs for onMessage.
https://developer.chrome.com/extensions/runtime#event-onMessage
You need to |return true| from it if you want to respond asynchronously.
Status: NEW → RESOLVED
Last Resolved: 2 years ago
Flags: needinfo?(fabrice)
Resolution: --- → INVALID
(Reporter)

Comment 3

2 years ago
Awesome thanks, apologies for missing that
You need to log in before you can comment on or make changes to this bug.