0

`

chrome.runtime.onMessage.addListener(async function (message, sender, sendResponse) {
    if (message.action === "showContextMenu") {


        chrome.tabs.query({ active: true }, function (tabs) {

            let tab = tabs[0];
            setTimeout(() => {

                chrome.scripting.executeScript({
                    target: {
                        tabId: tab.id,
                    },
                    func: injectedFunction,

                }, (injectionResults => {
                    console.log("in injection result"); // it's printed in console
                    console.log(injectionResults);
                    sendResponse({ message: "s", value: "injectionResults[0].result" });
                    alert("ss");
                    return true;// doesn't work either
                }))
                    // tried return true here, doesn't work
                }, 100); 
                  // tried return true here, doesn't work

        });
                  // tried return true here, doesn't work

    }
              // tried return true here, doesn't work

              //sendResponse({message:"s", value:"s" }); this works

});

`

Here's my background.js code. What i'm trying to achieve is notify my popup.js code that the api calls have been executed succesfully. I need to sendResponse inside injectionResult closure because I want to send the api call response back to popup.js.

How can I achieve that and where should I put return true?

UPDATE: This question does not solve my problem if I still use executeScript. sendResponse not waiting for async function or Promise's resolve

I ended up not using executeScript anymore and it's working

0 Answers0