Implementing the Chrome extension to start the local process-supplemental

Source: Internet
Author: User

implementing the Chrome extension to start the local process-supplementalTags: Chrome extension launches local program Access local disk2014-10-17 11:42 6753 people read review (+) collection report Classification:Chrome Plugin

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.


Examples mainly include the following sections Com.google.chrome.demo-win.jsonnative_cmd.batmanifest.jsonpopup.htmlpopup.js Feature Description:Implementation of an extension, the user click on a button will start the local Notepad program (also can write for their own program, where the example starts Notepad, similar to the function of thunder extension) Implementation Overview:Call start Notepad.exe by starting a local batch process Expansion:You can change the batch to a program you write, and then implement access to local disk data or something else in that program.

Program source code in the network disk (Chrome plugin directory of Demo.rar):

Http://pan.baidu.com/s/1hcVuQ

Part of the code:

Manifest.json

[JavaScript]View PlainCopy  
  1. {
  2. //Extension ID:NDNIGONBFJHPJLCABMADMKPDCFOMENLP
  3. "Manifest_version": 2,
  4. "name": "Invoke Native application",
  5. " description": "Example",
  6. "version": "1.0",
  7. "Browser_action": {
  8. " Default_icon": "Icon.png",
  9. "Default_popup": "popup.html" //defines the page that appears after clicking Expand
  10. },
  11. "Permissions": [
  12. "nativemessaging" //define permissions and need to communicate with local applications
  13. ]
  14. }

Popup.js [JavaScript]View PlainCopy 
  1. function Updateresult (obj, state) {
  2. document.getElementById (obj). InnerHTML = State;
  3. }
  4. function Invoke () {
  5. //hostname The name of the item on the registry
  6. var hostName = "Com.google.chrome.demo";
  7. //Start the local application
  8. var port = chrome.runtime.connectNative (HostName);
  9. Updateresult ("Result1", "invoke..");
  10. }
  11. Adding Listener events for Button1
  12. Document.addeventlistener (' domcontentloaded ', function () {
  13. Document.queryselector (' #button1 '). AddEventListener (
  14. ' click ', Invoke);
  15. });
  16. Com.google.chrome.demo-win.json
  17. {
  18. "name": "Com.google.chrome.demo",
  19. " description": "Chrome Native Messaging API Example Host",
  20. //path must be an absolute path, pointing to the program to start
  21. " path": "d:\\work\\chrome plugin\\native Messaging example\\demo\\native_cmd.bat",
  22. "type": "Stdio",
  23. "Allowed_origins": [
  24. "chrome-extension://niekdnkneilndiimkikogmplndpcfknp/"
  25. ]
  26. }
Com.google.chrome.demo-win.json [JavaScript]View PlainCopy 
  1. {
  2. "name": "Com.google.chrome.demo",
  3. " description": "Chrome Native Messaging API Example Host",
  4. //path must be an absolute path, pointing to the program to start
  5. " path": "d:\\work\\chrome plugin\\native Messaging example\\demo\\native_cmd.bat",
  6. "type": "Stdio",
  7. "Allowed_origins": [
  8. "chrome-extension://niekdnkneilndiimkikogmplndpcfknp/"
  9. ]
  10. }


Native_cmd.bat notepad.exe The value of my registry export (the location to be noted under Heky: ):Windows Registry Editor Version 5.00

[Hkey_current_user\software\google\chrome\nativemessaginghosts\com.google.chrome.demo]
@= "D:\\work\\chrome plugin\\native Messaging Example\\demo\\com.google.chrome.demo-win.json"

======================2016.2.15 Supplement =============================================

Before I have a private information about the problem can not be started, here is my negligence of a very important step, is the authority problem.

The chrome-extension under Allowed_origins represents the allowed plugins. This string of letters is important to match the ID you installed. as follows, this plugin is Hnaekmhaniojodkaageacnjfldljhiek, then the ID must be consistent with respect to the installation.

[JavaScript]View PlainCopy 
    1. "Allowed_origins": [
    2. "chrome-extension://hnaekmhaniojodkaageacnjfldljhiek/"
    3. ]

This involves the problem of plugin packaging, and incidentally.

as follows, select Package Extender, where the root directory is the plug-in location, which will generate two files, one PEM key file, and the other for the CRX installer. After installation can see the plug-in ID, and then copy down to fill in, and then remove the CRX installer, re-packaged once, but this time the following private key file to choose just generated. This will correspond to the ID.

The origin of complementary implementations:

Here for the time when I was asked to write a Chrome plugin task, when the first time to contact the plug-in, the solution is to collect data first, and then determine the use of native messaging way to achieve, to see the relevant documents and the official demo, and then study the Thunderbolt plug-ins, See how the Thunder is called (not research source, is to see how related, such as the registry), this process does not take much time, a week or so time.

Implementing the Chrome extension to start the local process-supplemental

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.