Monday, May 20, 2024
75
rated 0 times [  82] [ 7]  / answers: 1 / hits: 28479  / 5 Years ago, mon, march 18, 2019, 12:00:00

I have searched around but it's all about people complaining the bug. Many posts say that you should check all your extensions.



However, this is something I encountered when I am developing an extension.



Here is how it happens:



I have a listener on background.js:



chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
console.log('get:', request);
if (request.hasOwnProperty('opt')) {
trackPage('opt/' + request.opt);
}
return Promise.resolve();
});


And here is the trigger in my option page:



track('something');
function track(msg){
chrome.runtime.sendMessage({opt: msg}, function(response) {
console.log(response);
});
}


The error occurs when the track function is fired.



How can I fix the error totally?


More From » google-chrome-extension

 Answers
28

You can't return a Promise to make the function async, you have to return true. So change this:


return Promise.resolve("");

To this:


Promise.resolve("").then(result => sendResponse(result));
return true;

[#52409] Tuesday, March 12, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kalynn

Total Points: 309
Total Questions: 105
Total Answers: 90

Location: Azerbaijan
Member since Fri, May 12, 2023
1 Year ago
;