我尝试使用 chrome.windows.onCreated 但我得到了未捕获的TypeError:无法读取未定义的属性'onCreated'。我注意到在示例中,所有对 chrome。* API的调用似乎都源自后台脚本?我不能在内容脚本中使用它们吗?
I am trying to use chrome.windows.onCreated but I got Uncaught TypeError: Cannot read property 'onCreated' of undefined. I noticed in the samples, all calls to chrome.* API's seem to originate from background scripts? Can I not use them in content scripts?
我想在浏览器中触发点击。然后在弹出窗口中获取一些信息(刮擦)。为此,我想我需要知道何时打开一个窗口。所以我需要 windows.onCreated ?我可以在内容脚本中使用它吗?或者我将如何结合背景和内容脚本?
I want to trigger clicks in my browser. Then get some information (scrape) in popup window. For that I think I will need to know when a window is opened. So I need windows.onCreated? Can I use that in content scripts? Or how will I combine background and content scripts?
推荐答案来自内容脚本: b $ b
From the documentation for Content scripts:
但是,内容脚本有一些限制。 :
- 使用 chrome。* API (除了部分 chrome.extension )
- 使用由其扩展页面定义的变量或函数
- 使用由网页或其他内容脚本定义的变量或函数
- Use chrome.* APIs (except for parts of chrome.extension)
- Use variables or functions defined by their extension's pages
- Use variables or functions defined by web pages or by other content scripts
可以避免间接这些限制,主要通过发送邮件。该文档提供了几个涉及消息传递的示例。在之前的Chrome 20中,消息API方法被称为 onRequest 和 sendRequest 。自20版以来,它们被称为 onMessage 和 sendMessage 。
These limitations can indirectly be avoided, mainly by sending messages within the extension. The documentation offers several examples which involves message passing. Prior Chrome 20, the message API methods was called onRequest and sendRequest. Since version 20, they're called onMessage and sendMessage.
下面的答案提到了如何将消息从内容脚本传递到弹出窗口的步骤: https:// stackoverflow / a / 11617742
Here's an answer which mentions the steps how to pass a message from a content script to a popup: stackoverflow/a/11617742
更多推荐
在内容脚本中可以使用`chrome。*`扩展API吗?
发布评论