Google chrome 在单独的窗口中启动扩展时,将消息从Chrome扩展发送到内容脚本

Google chrome 在单独的窗口中启动扩展时,将消息从Chrome扩展发送到内容脚本,google-chrome,google-chrome-extension,communication,content-script,Google Chrome,Google Chrome Extension,Communication,Content Script,我正在开发一个chrome扩展,它需要向内容脚本发送消息,直到我用单独的窗口替换默认的弹出窗口为止,一切都正常。在那之后,信息交流就不起作用了 我的舱单: { "manifest_version": 2, "name": "Overlight Live Reload", "description": "Overlight Testing Tool", "version": "0.0.1", "content_security_policy": "script-src 'se

我正在开发一个chrome扩展,它需要向内容脚本发送消息,直到我用单独的窗口替换默认的弹出窗口为止,一切都正常。在那之后,信息交流就不起作用了

我的舱单:

{
  "manifest_version": 2,

  "name": "Overlight Live Reload",
  "description": "Overlight Testing Tool",
  "version": "0.0.1",
  "content_security_policy": "script-src 'self' http://localhost:3000/; object-src 'self'",
  "permissions": ["activeTab", "tabs", "storage", "declarativeContent", "<all_urls>"],

  "browser_action": {
    "default_title": "Overlight"
  },
  "background": {
    "scripts": ["background/background.js"],
    "persistent": false
  },
  "icons": {
      "16": "images/get_started16.png",
      "32": "images/get_started32.png",
      "48": "images/get_started48.png",
      "128": "images/get_started128.png"
  },
  "content_scripts": [
    {
      "matches": ["http://*/*","https://*/*"],
      "css": [],
      "js": ["contentScripts/lodash.js", "contentScripts/listeners.js"]
    }
  ]
}
从扩展应用程序执行:

export const testSendToPage = () => {
    console.log('Sending message to web page')
    window.chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
        window.chrome.tabs.sendMessage(tabs[0].id, {greeting: "hello"}, function(response) {
          console.log(response.farewell);
        });
      });
}
创建扩展窗口的背景scipt:

chrome.browserAction.onClicked.addListener(function(tab) {
    chrome.windows.create({
        height: 400,
        width:400,
        url: chrome.runtime.getURL("../popup.html"),
      type: "popup"
    });
});
一切都很好,当我使用默认的弹出窗口来创建单独的窗口时。更重要的是,当我尝试使用window.chrome.tabs.executeScript from separated window exception时,我得到了这个

运行tabs时未选中runtime.lastError.executeScript:无法访问url“chrome”的内容-extension://ciipdholchghlckepfaecipbjleanmbg/popup.html". 扩展清单必须请求访问此主机的权限


从内容脚本到extesion应用程序的消息非常有效。如何从分机窗口从分机应用程序到内容脚本进行通信?

类型为“popup”的分机窗口不是browserAction弹出窗口-它是一个实际的分机窗口,因此您可以在chrome.tabs.query中接收自己的页面id。我如何从分机窗口向分机内容脚本发送消息?在webstore中有这样的扩展可以通信。您可以在查询参数中使用lastFocusedWindow:true而不是currentWindow。通过使用启用扩展及其内容脚本之间的通信。任何一方都可以监听从另一端发送的消息,并在同一通道上做出响应。有一个用于一次性请求的简单API,还有一个更复杂的API,允许您拥有长寿命的连接,以便使用共享上下文交换多条消息。另外,请阅读更多指南。CurrentWindow为我提供扩展窗口,但当我筛选选项卡以找到我需要的选项卡时,它会工作!谢谢你的帮助。
chrome.browserAction.onClicked.addListener(function(tab) {
    chrome.windows.create({
        height: 400,
        width:400,
        url: chrome.runtime.getURL("../popup.html"),
      type: "popup"
    });
});