Chrome nativeclient Create

Source: Internet
Author: User

Chrome nativeclient Create

The demo goal is to have the Chrome extension launch the local exe

1 Creating a console program called Nativemsgdemo

#include <Windows.h>

#include <iostream>

#include <string>

#include <fstream>

using namespace Std;

BOOL Recievemsgfromchrome ();

int main (int argc, char* argv[])

{

while (1)

{

Sleep (300);

if (! Recievemsgfromchrome ())

Break

}

return 1;

}

The generated exe is nativeMsgDemo.exe

2. Extending the content to be written

Write content in the extended background.js so that the Chrome extension supports nativeclient message response

var port = chrome.runtime.connectNative (' Com.wudi.chrome.namsg.yunzhou ');

Port.onMessage.addListener (function (msg) {

Console.log ("Received" + msg);

});

Port.onDisconnect.addListener (function () {

Console.log ("Disconnected");

});

Port.postmessage ({text: "Hello, My_application"});

3. Chrome nativemessaginghosts Registry File

Com.wudi.chrome.namsg.yunzhou writing to the registry

Hkey_local_machine\software\google\chrome\nativemessaginghosts\com.wudi.chrome.namsg.yunzhou

Find the path to the. json file through this registry

D:\projects\NativeMsgDEmo\output\com.wudi.chrome.namsg.yz-win.json,

In this file , the EXE that chrome.runtime.connectNative True Association communication is saved , the file content is as follows:

{

"Name": "Com.wudi.chrome.namsg.yunzhou",

"description": "Chrome Native Messaging for Yuzhou",

"Path": "NativeMsgDemo.exe",

"Type": "Stdio",

"Allowed_origins": [

"Chrome-extension://hohonaplgfolmdaaafoddgbiakognoal/"

]

}

The . json file and the. EXE file are typically placed in the same directory for easy locating, such as:

Then let chrome load our extension,backgroud.html will load backgroud.js,background.js in the Chrome.runtime.connectNative will get the EXE that communicates with Chrome , which is the standard input/output.

4. nativeclient. exe search process

1. Via var in background.js port =

Chrome.runtime.connectNative (' Com.wudi.chrome.namsg.yunzhou ');

Locate the registry key in the hkey_local_machine\software\google\chrome\nativemessaginghosts

Com.wudi.chrome.namsg.yunzhou

2. Locate the Com.wudi.chrome.namsg.yz-win.json file by using the above registry key

3. exe with connection input and output specified in the Com.wudi.chrome.namsg.yz-win.json file

Chrome nativeclient Create (GO)

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.