javascript - Chrome 打包应用程序和 Chrome 扩展程序之间进行通信?

标签 javascript google-chrome google-chrome-extension google-chrome-app

我需要将仅在 Chrome 打包应用程序中可用的功能(访问同步文件系统)与仅在 Chrome 扩展程序中可用的功能(将脚本注入(inject)第三方网站)结合起来。

似乎打包应用程序和扩展程序都无法实现这两件事,因此我现在正在考虑尝试通过单独的打包应用程序和扩展程序通信来实现我所追求的目标。

我看到Chrome's documentation解释了两个扩展程序如何通过chrome.runtime.onMessageExternal.addListenerchrome.runtime.sendMessage进行通信,但没有介绍打包应用程序和扩展程序的通信.

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

最佳答案

是的,这是可能的。您链接的文档中的代码示例适用于应用程序和扩展程序的任意组合。

chrome.runtime.sendMessage 的扩展文档说:

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

消息传递在扩展程序和应用程序中的工作方式相同,并且它们似乎完全兼容;只需使用目标扩展程序或应用程序的 ID。如果您查看 app version of chrome.runtime.sendMessage 的文档,您会发现它与扩展版本相同。

关于javascript - Chrome 打包应用程序和 Chrome 扩展程序之间进行通信?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16015874/

相关文章:

javascript - 将 React 组件从函数重构为 ES6 类

javascript - 未捕获类型错误 : Failed to execute 'drawImage' on Vue. js

javascript - http 页面调用的 https iframe 中的 getUserMedia

如果我刷新页面,jQuery 会起作用,但在原始加载时则不起作用。 Chrome 扩展程序

html - 尝试在谷歌浏览器中使用 HTML5 文件 api 时出现 FileError

javascript - 用 JQuery 替换没有 ID/类的图像

javascript - PHP 与 JavaScript,按位运算符

javascript - 从 Django 为 D3 图直接输入数据

google-chrome - 相当于宽度 :-moz-available in Google Chrome

javascript - 如何在谷歌浏览器中禁用网络存储?