Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
675 views
in Technique[技术] by (71.8m points)

Can I control a Chrome Extension externally from C or C++?

would it be possible to control a Chrome Extension externally using a C/C++ script? So, for example, when my C script receives an

if

trigger, it would send the command to an open Chrome Extension; e.g. to click a certain part of a page. This must be done using C, as my program is going to be heavily C based when completed.

Many thanks in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Quick solution that came to my mind:

A chrome extension can read files within its own directory.

So I would suggest to create a function in background.js that periodically (adjust the granularity as per your needs), reads some file within the extensions directory using chrome.extension.getURL, XMLHttpRequest and "GET" command.

Then execute the command stated in the file.

From your C/C++/Bash controlling program, you can send the commands.

Here is an example of the function:

function read_control_file() {
    var url = chrome.extension.getURL("control_cmd.txt");
    var request = new XMLHttpRequest();
    // false so that request is processed immediately and we need not pass callback                                                
    request.open("GET", url, false);
    request.send();

    return request.responseText;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...