Chrome Extension Message passing: response not sent

前端 未结 3 1854
挽巷
挽巷 2020-11-21 06:14

I am trying to pass messages between content script and the extension

Here is what I have in content-script

chrome.runtime.sendMessage({type: \"getUr         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-11-21 06:58

    From the documentation for chrome.runtime.onMessage.addListener:

    This function becomes invalid when the event listener returns, unless you return true from the event listener to indicate you wish to send a response asynchronously (this will keep the message channel open to the other end until sendResponse is called).

    So you just need to add return true; after the call to getUrls to indicate that you'll call the response function asynchronously.

提交回复
热议问题