我有兴趣编写一个打包应用程序,可以访问有关Chrome的数据,即chrome.windows.onCreated
和chrome.windows.onRemoved
事件。如果我尝试添加一个侦听其中任一,我在控制台得到一个错误:Chrome打包应用程序访问Chrome API
Uncaught TypeError: Cannot read property 'onRemoved' of undefined
有没有解决这个办法吗?
我有兴趣编写一个打包应用程序,可以访问有关Chrome的数据,即chrome.windows.onCreated
和chrome.windows.onRemoved
事件。如果我尝试添加一个侦听其中任一,我在控制台得到一个错误:Chrome打包应用程序访问Chrome API
Uncaught TypeError: Cannot read property 'onRemoved' of undefined
有没有解决这个办法吗?
其他答案是正确的,这是不可能从打包的应用程序中直接获得的,但有一种解决方案可以满足您的需求:您可以编写扩展以及打包的应用程序,并让它们与chrome.runtime.sendMessage
进行通信。
用户将不得不安装应用程序和扩展程序,但是您可以通过从应用程序中将它们引导至Chrome网上应用店来简化操作。你可以阅读这个在这里:Communicating between a Chrome packaged app and a Chrome extension?
编辑:和在该线程评论指出的那样,有一个Chrome应用示例,有助于行动证明这一点:https://github.com/GoogleChrome/chrome-app-samples/tree/master/messaging
一个简单的拼写错误的位置:它是chrome.windows.onRemoved
不chrome.windows.OnRemoved
;)
注意小写o
。
C#是爬行通过。错字只是因为我在这里输入了它。它不存在于我的* .js文件中。 –
chrome.windows
API是Chrome扩展API,而不是打包的应用程序API。它被扩展用来与浏览器窗口进行交互。
如果您可以将您的应用程序作为扩展编写,它将能够使用该API。然而,打包的应用程序无法操作除自己以外的其他窗口。
这就是我所害怕的。 –
感谢您的建议。这允许我完全做我想做的事情。 –