Chrome extension: Communication between content script and background.html

后端 未结 1 1676
感情败类
感情败类 2020-12-03 17:20

I am new to Chrome extensions. I am trying to communicate between the content script and the background.html page. The background.html sends a request, \"<

相关标签:
1条回答
  • 2020-12-03 17:58

    sendRequest/onRequest is replaced with sendMessage/onMessage in Chrome 20. *Message is not just an alias for *Request, it's a different API.

    If you want to support Chrome <20 (many Ubuntu users are still at Chromium 18, because the PPA is not updated), use onRequest and sendRequest. Otherwise, use the *Message methods.


    Another problem is that your function is located in the background page, and the call is made in the pop-up. These are different scopes, if you want to call a background page method from the popup, use chrome.extension.getBackgroundPage():

    chrome.extension.getBackgroundPage().testRequest();
    

    Final note: You're using manifest version 1 and inline event handlers. This practice is deprecated, for more information, see http://code.google.com/chrome/extensions/manifestVersion.html.

    0 讨论(0)
提交回复
热议问题