同时定位Google Chrome和Edge Chromium时,我应该何时启动本机消息主机? [英] When should I start a native message host when targeting both Google Chrome and Edge Chromium?

查看:59
本文介绍了同时定位Google Chrome和Edge Chromium时,我应该何时启动本机消息主机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用本机主机的Google Chrome扩展程序.这仅在Windows框上使用,并且扩展名的注册表设置与本机主机exe的安装一起添加.当前,在加载扩展程序后台脚本时,将启动端口(chrome.runtime.connectNative)或本机主机.当前,这意味着只要运行Chrome浏览器,本地主机就会运行.

I have a Google Chrome Extension which uses a native host. This is used only on a windows box and the extension's registry settings are added along with the installation of the native host exe. Currently the the port (chrome.runtime.connectNative) or native host is started when the extensions background script is loaded. This currently means that the native host runs whenever Google Chrome is running.

该扩展名仅用于1个网站"www.example.com",因此内容脚本仅在加载带有该网站的选项卡时运行.这意味着仅当加载带有该网站的选项卡时才需要本机主机,而不是一直都需要.

The extension is used for only 1 website "www.example.com" and so content scripts only run when a tab with this website is loaded. This means that the native host would only be needed when a tab with this website is loaded and not all the time.

我现在还想创建一个Edge Chromium扩展,并为用户提供使用Edge或Chrome的选项.正如我在上面指出的那样,两个扩展名都将被安装",这意味着在安装本机主机时添加了注册表项.这意味着扩展程序将在两个浏览器中都存在.

I now want to also create an Edge Chromium extension and give users the option to use either Edge or Chrome. As I indicated above both extensions would be "installed" meaning the registry keys added on installation of the native host. This means the extensions would be there for both browsers.

因此,我的主要问题是何时以及如何启动本机主机.

My main question is thus when and how should the native host be started.

在这个主要问题上,我有很多想法或问题;

From this main question I have a whole host of thoughts or questions;

  1. 当用户选择使用Edge或Chromium时,我应该在那时对注册表进行更改吗?问题是用户当然可以独立于我的应用安装扩展程序.
  2. 仅保留原样存在问题吗?换句话说,如果Edge和Chromium正在运行,则有2个不同的本机主机在运行,我的应用程序仅根据用户的选择选择要与之通信的本机主机.这里的问题是您可以看到本机宿主进程在任务管理器中运行,因此它将在用户未选择的浏览器上运行,这对于某些用户而言可能不是很好.
  3. 我想到了该扩展带有一个标志,该标志可以知道是否应启动本机主机.这里的问题是如何打开此标志.没有本地主机,我不知道与扩展进行交互的方法.

也许还有更多选择很高兴听到它们.

There are possibly more options so happy to hear them as well.

推荐答案

更改注册表

将具有第二个扩展名的 chrome-extension://id/添加到主机清单中的 allowed_origins 中,如

Add chrome-extension://id/ with the id of your second extension to allowed_origins in the host's manifest as shown in the documentation.

有2个不同的本机主机在运行

there are 2 different native hosts running

每个主机都由其各自的扩展名启动,并且只能与该父扩展名通信,不会造成混乱.

Each host is started by its respective extension and it can communicate only to that parent extension, there's no confusion.

一个标志,以了解是否应启动本机主机.这里的问题是如何打开此标志.没有本地主机,我不知道与扩展交互的方式.

a flag to know if it should start the native host. Problem here is how could I turn this flag on. Without the native host I am unaware of a way to interact with the extension.

这取决于主机和扩展的功能.也许您不需要一直运行主机,或者仅当加载了具有匹配URL的选项卡时才可以启动主机.也许您可以使用新的实验性 onConnectNative 机制.

It depends on what the host and the extension do. Maybe you don't need to run the host all the time or maybe you can start it only when a tab with the matching URL is loaded. Maybe you can use the new experimental onConnectNative mechanism.

这篇关于同时定位Google Chrome和Edge Chromium时,我应该何时启动本机消息主机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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