gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 22:21:58 26 4
gpt4 key购买 nike

我需要将仅在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com