Custom Protocol Handler in Chrome

How to configure my own protocol handler in chrome? Something like:

myprotocol: // TestFile

I will need this to send a request to http://example.com?query=testfile and then send httpresponse to my extension.

+68
google-chrome-extension
Aug 17 2018-11-11T00:
source share
5 answers

The following method registers the application in a URI scheme. This way you can use mycustproto: in your HTML code to run the local application. It works with Google Chrome version 51.0.2704.79 m (64-bit).

I mainly used this method to print a document without using the print dialog. The result is pretty good and is a seamless solution for integrating an external application with a browser.

HTML code (simple):

<a href="mycustproto:Hello World">Click Me</a> 

HTML code (alternative):

 <input id="DealerName" /> <button id="PrintBtn"></button> $('#PrintBtn').on('click', function(event){ event.preventDefault(); window.location.href = 'mycustproto:dealer ' + $('#DealerName').val(); }); 

The URI scheme will look like this:

You can create a URI scheme manually in the registry or run the file "mycustproto.reg" (see below).

 HKEY_CURRENT_USER\Software\Classes mycustproto (Default) = "URL:MyCustProto Protocol" URL Protocol = "" DefaultIcon (Default) = "myprogram.exe,1" shell open command (Default) = "C:\Program Files\MyProgram\myprogram.exe" "%1" 

example mycustproto.reg:

 Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Classes\mycustproto] "URL Protocol"="\"\"" @="\"URL:MyCustProto Protocol\"" [HKEY_CURRENT_USER\Software\Classes\mycustproto\DefaultIcon] @="\"mycustproto.exe,1\"" [HKEY_CURRENT_USER\Software\Classes\mycustproto\shell] [HKEY_CURRENT_USER\Software\Classes\mycustproto\shell\open] [HKEY_CURRENT_USER\Software\Classes\mycustproto\shell\open\command] @="\"C:\\Program Files\\MyProgram\\myprogram.exe\" \"%1\"" 

C # console application - myprogram.exe:

 using System; using System.Collections.Generic; using System.Text; namespace myprogram { class Program { static string ProcessInput(string s) { // TODO Verify and validate the input // string as appropriate for your application. return s; } static void Main(string[] args) { Console.WriteLine("Raw command-line: \n\t" + Environment.CommandLine); Console.WriteLine("\n\nArguments:\n"); foreach (string s in args) { Console.WriteLine("\t" + ProcessInput(s)); } Console.WriteLine("\nPress any key to continue..."); Console.ReadKey(); } } } 

Try starting the program first to make sure the program is placed in the correct path:

 cmd> "C:\Program Files\MyProgram\myprogram.exe" "mycustproto:Hello World" 

Click the link on the HTML page:

The first time you see a warning popup.

enter image description here

In reset, configure the external protocol handler in Chrome:

If you have ever accepted the user protocol in Chrome and would like to set reset, do it (there is currently no interface in Chrome for changing the settings):

Change the " Local state " in this file along this path:

 C:\Users\Username\AppData\Local\Google\Chrome\User Data\ 

or just follow the link:

 %USERPROFILE%\AppData\Local\Google\Chrome\User Data\ 

Then search for this line: protocol_handler

You will see the user protocol there.

Note. . Close Google Chrome before editing the file. Otherwise, the change you make will be overwritten by Chrome.

Reference:

https://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx

+55
02 '16 at 20:46 on
source share

Chrome 13 now supports the navigator.registerProtocolHandler API. For example,

 navigator.registerProtocolHandler( 'web+custom', 'http://example.com/rph?q=%s', 'My App'); 

Please note that the name of your protocol must begin with web+ , with some exceptions to the usual ones (for example, mailto , etc.). For more information see http://updates.html5rocks.com/2011/06/Registering-a-custom-protocol-handler

+50
Aug 18 2018-11-11T00:
source share

Now this question is out of date, but a Chrome update has recently appeared (at least where application packages were applied) ...

http://developer.chrome.com/apps/manifest/url_handlers

and

https://github.com/GoogleChrome/chrome-app-samples/tree/master/samples/url-handler

It allows you to register a URL handler (if you own one). Unfortunately there is no myprotocol:// , but at least you can do http://myprotocol.mysite.com and you can create a web page there that points people to the application in the application store.

+24
Mar 25 '14 at 16:40
source share

Here is how I did it. Your application will need to install several registry keys during installation, and then in any browser you can simply refer to the file foo: \ anythingHere.txt, and it will open your application and pass it to that value.

This is not my code, I just found on the Internet when searching for the same question. Just change all the "foo" in the text below to the desired protocol name and change the path to your exe.

(put this in a text file as save, like foo.reg on your desktop, then double-click it to install the keys) ----- Below this line is the .reg file (not including this line) ---- -

 REGEDIT4 [HKEY_CLASSES_ROOT\foo] @="URL:foo Protocol" "URL Protocol"="" [HKEY_CLASSES_ROOT\foo\shell] [HKEY_CLASSES_ROOT\foo\shell\open] [HKEY_CLASSES_ROOT\foo\shell\open\command] @="\"C:\\Program Files (x86)\\Notepad++\\notepad++.exe\" \"%1\"" 
+6
Feb 21 '14 at 17:12
source share

open

 C:\Users\<Username>\AppData\Local\Google\Chrome\User Data\Default 

open “ Preferences then find the excluded_schemes you find in“ protocol_handler. ”Remove that excluded scheme (s) to reset Chrome to open the URL with the default application.

0
Jan 25 '19 at 8:05
source share



All Articles