Communicating between a Chrome packaged app and a Chrome extension?

对着背影说爱祢 提交于 2019-11-26 09:39:33

问题


I need to combine functionality available only in a Chrome packaged app (access to syncFileSystem) and functionality available only in a Chrome extension (injecting a script into a 3rd party website).

It seems that neither a packaged app nor an extension can achieve both these things, so I\'m now considering trying to achieve what I\'m after with a separate packaged app and extension communicating.

I see that Chrome\'s documentation explains how two extensions can communicate via chrome.runtime.onMessageExternal.addListener and chrome.runtime.sendMessage, but nothing about packaged apps and extensions communicating.

Does anyone know if this is allowed? Is there any documentation, or a working example out there?


回答1:


Yes, that is possible. The code sample in the documentation you linked works for any combination of app and extension.

The extension documentation for chrome.runtime.sendMessage says:

Sends a single message to onMessage event listeners within the extension (or another extension/app).

Messaging works the same in both extensions and apps, and they seem to be fully compatible; simply use the ID for the destination extension or app. If you look at the docs for the app version of chrome.runtime.sendMessage, you'll see that it is identical to the extension version.



来源:https://stackoverflow.com/questions/16015874/communicating-between-a-chrome-packaged-app-and-a-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!