Open lolaraghvendra opened 4 months ago
Isnt this the same as https://stackoverflow.com/a/20077854/3711660?
Meaning you need to return true and then use async code like await fetch(). Wrap async code in a function call it (with void operator, not await like soe void runAsyncCode();return true;
)and return true
I used to add await directly while calling the
chrome.tabs.sendMessage
and it used to work great:for some unknown reasons it stopped working that way months ago and i desperately need to use it asynchronously!
the solution i tried looks something like this:
i created a utility function in another file
utils.js
to use it anywhere i neededand i use it in my popup.jsx like this:
The thing is i am not getting a response from the
sendMessageToContent
and instead thechrome.runtime.lastError
is set in callback of this function and this following error is caught:as per the code in my content script (mentioned below) the code is executed successfully and there is no error in the logic but there is always a delay between the last log of the content script and the callback in the
sendMessageToContent
content script log:popup log:
afaik, the call back is called only when the
sendResponse
is called, so i guess the flow is OK. but why am i getting the response in this callback asundefined
This is how far i have reached and i cant understand what shall i do exactly to make it work asynchronously!BTW, here is the code in content script: