Start an external application from a Google Chrome Extension?
Asked Answered
A

4

85

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,

Apostatize answered 16/4, 2010 at 10:14 Comment(4)
If there is a god then Google will never allow anyone to do this under any circumstances.Windle
Question has a good pagerank on google, so for anyone who's looking for answer to this question this might be helpful. There is an extension in google chrome marketspace to do exactly that: chrome.google.com/webstore/detail/…Hanghangar
Possible duplicate of Execute a program from a Chrome ExtensionAnnulate
@Annulate Since the question you mention is posterior to this one it should be considered as the duplicate.Ulmaceous
M
88

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.

Malinowski answered 12/11, 2013 at 6:51 Comment(1)
I actually think you can, using FileIO: developer.chrome.com/native-client/pepper_stableUropygium
G
28

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!

Gora answered 21/8, 2016 at 0:31 Comment(2)
The link has expired.Gamester
Archived page for the dead "custom protocols" link: web.archive.org/web/20210601082308/https://…Lacreshalacrimal
B
5

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

Biamonte answered 15/9, 2021 at 6:57 Comment(0)
I
1

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.

Interrogate answered 20/7, 2016 at 9:46 Comment(1)
Of course this would work if the Apache process had the required permissions, but what's the point when you would then need to install Apache and open webserver ports on the user's computer....Otalgia

© 2022 - 2024 — McMap. All rights reserved.