从 Google Chrome 扩展程序启动外部应用程序?

发布于 2024-08-29 07:05:40 字数 133 浏览 4 评论 0原文

如何从 Google Chrome 扩展程序启动外部应用程序?

所以基本上我有一个可执行文件,当您启动它时它会执行该工作。我需要能够在没有窗口的情况下启动它(它是一个控制台应用程序)并在参数中将当前 URL 传递给它,

How to start an external application from a Google Chrome Extension?

So basically I have an executable file which does the job when you launch it. I need to be able to start it without a window (it is a console application) and pass the current URL to it in an argument,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

心安伴我暖 2024-09-05 07:05:40

以前,您可以通过NPAPI 插件来执行此操作。

不过,Google 正在逐步淘汰 NPAPI Chrome,因此首选方法是使用原生消息 API 。外部应用程序必须注册本机消息传递主机才能与您的应用程序交换消息。

Previously, you would do this through NPAPI plugins.

However, Google is now phasing out NPAPI for Chrome, so the preferred way to do this is using the native messaging API. The external application would have to register a native messaging host in order to exchange messages with your application.

删除→记忆 2024-09-05 07:05:40

您无法启动任意命令,但如果您的用户愿意进行一些额外的设置,您可以使用 自定义协议

例如,您让用户进行设置,以便 some-app:// 链接启动“SomeApp”,然后在 my-awesome-extension 中打开一个指向的选项卡some-app://some-data-the-app-wants,就可以开始了!

You can't launch arbitrary commands, but if your users are willing to go through some extra setup, you can use custom protocols.

E.g. you have the users set things up so that some-app:// links start "SomeApp", and then in my-awesome-extension you open a tab pointing to some-app://some-data-the-app-wants, and you're good to go!

终弃我 2024-09-05 07:05:40

原生消息传递主机

Chrome 扩展程序

{
"name": "AppName",
"description": "",
"version": "1.0",
"manifest_version": 3,
"permissions": [
"nativeMessaging" //

Native messaging host

Chrome-extensions

{
  "name": "AppName",
  "description": "",
  "version": "1.0",
  "manifest_version": 3,
  "permissions": [
    "nativeMessaging"  // ???? https://developer.chrome.com/docs/extensions/mv3/declare_permissions/
  ]
  // ...
}

Host

Add schema

@echo off
:: If you add "/f" then you can force write.
REG ADD "HKCU\Software\Google\Chrome\NativeMessagingHosts\com.my_company.my_application" ^
 /ve /t REG_SZ ^
 /d "%~dp0Mymanifest.json"
// Mymanifest.json
{
  "name": "com.my_company.my_application",
  "description": "My Application",
  "path": "relative_dir/my.exe",
  "type": "stdio",
  "allowed_origins": [
    "chrome-extension://nbjjflbnekmabedahdolabcpahfjojjb/"
  ]
}

chrome.runtime.sendNativeMessage

example:

// your.js
chrome.runtime.sendNativeMessage("com.my_company.my_application",
  {key1: "value1", key2: "value2"}, // ???? Send those parameters to your program.
  (response) => {
    console.log(response)
  }
)

Example repository

I have created a project thunder/e11fde9 whose ultimate goal is to be able to use a browser as input and then open a specified file locally (without a mouse, if possible)

It is still in development, but I think the early code is enough. The link is below.

Which already has a log that records the results of the browser's transmission, while the browser can also get the program's return value.

Reference

勿忘初心 2024-09-05 07:05:40

我选择假设,因为我现在无法验证。

使用 Apache,如果您在本地计算机上创建一个调用可执行文件的 php 脚本,然后通过 html/javascript 通过 POST 或 GET 调用该脚本?

它会起作用吗?

让我知道。

I go for hypothesys since I can't verify now.

With Apache, if you make a php script on your local machine calling your executable, and then call this script via POST or GET via html/javascript?

would it function?

let me know.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文