在Chrome打包的应用和Chrome扩展之间进行通信? [英] Communicating between a Chrome packaged app and a Chrome extension?

查看:553
本文介绍了在Chrome打包的应用和Chrome扩展之间进行通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将仅适用于Chrome打包应用程序(可访问syncFileSystem)的功能和仅在Chrome扩展程序中提供的功能(将脚本注入第三方网站)结合使用。

看起来,打包的应用程序和扩展程序都无法实现这两种功能,所以我现在正在考虑尝试使用单独的打包应用程序来实现我的目标和扩展程序进行通信。



我看到 Chrome的文档解释了两个扩展如何通过 chrome.runtime.onMessageExternal.addListener chrome.runtime.sendMessage
$ b


有人知道这是否允许吗?是否有任何文档或工作示例?


解决方案

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



chrome.runtime.sendMessage 表示:


向扩展程序(或其他扩展程序/应用程序)中的 onMessage 事件侦听器发送单个消息。


Messaging在扩展程序和应用程序中的工作方式都是相同的,它们似乎完全兼容;只需使用目标扩展程序或应用程序的ID即可。如果您查看应用程序版本 chrome.runtime.sendMessage ,您会看到它与扩展版本相同。


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?

解决方案

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.

这篇关于在Chrome打包的应用和Chrome扩展之间进行通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆