How to listen to http requests in a Chrome extension and how to set the permissions for it in manifest.json
I'm trying to realise the idea of waldalla to build a proxy server in a Google Chrome extension.
I understand how to code in a Chrome extension the server-facing side of the problem, i.e. sending HTTP requests and receiving responses, but I don't know how to do the client-facing side, i.e. listening on a defined port for HTTP requests from outside the browser.
I have read up on Chrome's Native Messaging API. However, from what I can see it is used for communication via stdin/stdout, not via HTTP.
So, how can I listen to HTTP requests in a Google Chrome extension? And how do I set the permissions for this in the extension's manifest.json
file?
google-chrome google-chrome-extension chrome-native-messaging
add a comment |
I'm trying to realise the idea of waldalla to build a proxy server in a Google Chrome extension.
I understand how to code in a Chrome extension the server-facing side of the problem, i.e. sending HTTP requests and receiving responses, but I don't know how to do the client-facing side, i.e. listening on a defined port for HTTP requests from outside the browser.
I have read up on Chrome's Native Messaging API. However, from what I can see it is used for communication via stdin/stdout, not via HTTP.
So, how can I listen to HTTP requests in a Google Chrome extension? And how do I set the permissions for this in the extension's manifest.json
file?
google-chrome google-chrome-extension chrome-native-messaging
@wOxxOm A local proxy server app is ok, but the HTTP request to the outside world has to be done by Chrome. So the proxy app would need to communicate requests and resposnes with Chrome via Native Messaging, right?
– halloleo
Nov 21 '18 at 6:11
Now that I've actually read the thread you've linked, I can say you need to write a native OS app (e.g. using node.js) that acts as a local proxy server for other apps. This app will route the requests to your extension via nativeMesaging API (which is stdio-based as described in the documentation), the extension will make the request using XMLHttpRequest or fetch in the background script and send the response back via nativeMessaging API. BTW, add a monotonically increasing numeric request ID to each message to identify its response.
– wOxxOm
Nov 21 '18 at 6:28
@wOxxOm Thanks for the detailed outline of a possible solution. Makes sense to me!
– halloleo
Nov 21 '18 at 6:40
add a comment |
I'm trying to realise the idea of waldalla to build a proxy server in a Google Chrome extension.
I understand how to code in a Chrome extension the server-facing side of the problem, i.e. sending HTTP requests and receiving responses, but I don't know how to do the client-facing side, i.e. listening on a defined port for HTTP requests from outside the browser.
I have read up on Chrome's Native Messaging API. However, from what I can see it is used for communication via stdin/stdout, not via HTTP.
So, how can I listen to HTTP requests in a Google Chrome extension? And how do I set the permissions for this in the extension's manifest.json
file?
google-chrome google-chrome-extension chrome-native-messaging
I'm trying to realise the idea of waldalla to build a proxy server in a Google Chrome extension.
I understand how to code in a Chrome extension the server-facing side of the problem, i.e. sending HTTP requests and receiving responses, but I don't know how to do the client-facing side, i.e. listening on a defined port for HTTP requests from outside the browser.
I have read up on Chrome's Native Messaging API. However, from what I can see it is used for communication via stdin/stdout, not via HTTP.
So, how can I listen to HTTP requests in a Google Chrome extension? And how do I set the permissions for this in the extension's manifest.json
file?
google-chrome google-chrome-extension chrome-native-messaging
google-chrome google-chrome-extension chrome-native-messaging
edited Nov 22 '18 at 13:06
Xan
53.9k10105133
53.9k10105133
asked Nov 21 '18 at 5:49
halloleohalloleo
2,40752258
2,40752258
@wOxxOm A local proxy server app is ok, but the HTTP request to the outside world has to be done by Chrome. So the proxy app would need to communicate requests and resposnes with Chrome via Native Messaging, right?
– halloleo
Nov 21 '18 at 6:11
Now that I've actually read the thread you've linked, I can say you need to write a native OS app (e.g. using node.js) that acts as a local proxy server for other apps. This app will route the requests to your extension via nativeMesaging API (which is stdio-based as described in the documentation), the extension will make the request using XMLHttpRequest or fetch in the background script and send the response back via nativeMessaging API. BTW, add a monotonically increasing numeric request ID to each message to identify its response.
– wOxxOm
Nov 21 '18 at 6:28
@wOxxOm Thanks for the detailed outline of a possible solution. Makes sense to me!
– halloleo
Nov 21 '18 at 6:40
add a comment |
@wOxxOm A local proxy server app is ok, but the HTTP request to the outside world has to be done by Chrome. So the proxy app would need to communicate requests and resposnes with Chrome via Native Messaging, right?
– halloleo
Nov 21 '18 at 6:11
Now that I've actually read the thread you've linked, I can say you need to write a native OS app (e.g. using node.js) that acts as a local proxy server for other apps. This app will route the requests to your extension via nativeMesaging API (which is stdio-based as described in the documentation), the extension will make the request using XMLHttpRequest or fetch in the background script and send the response back via nativeMessaging API. BTW, add a monotonically increasing numeric request ID to each message to identify its response.
– wOxxOm
Nov 21 '18 at 6:28
@wOxxOm Thanks for the detailed outline of a possible solution. Makes sense to me!
– halloleo
Nov 21 '18 at 6:40
@wOxxOm A local proxy server app is ok, but the HTTP request to the outside world has to be done by Chrome. So the proxy app would need to communicate requests and resposnes with Chrome via Native Messaging, right?
– halloleo
Nov 21 '18 at 6:11
@wOxxOm A local proxy server app is ok, but the HTTP request to the outside world has to be done by Chrome. So the proxy app would need to communicate requests and resposnes with Chrome via Native Messaging, right?
– halloleo
Nov 21 '18 at 6:11
Now that I've actually read the thread you've linked, I can say you need to write a native OS app (e.g. using node.js) that acts as a local proxy server for other apps. This app will route the requests to your extension via nativeMesaging API (which is stdio-based as described in the documentation), the extension will make the request using XMLHttpRequest or fetch in the background script and send the response back via nativeMessaging API. BTW, add a monotonically increasing numeric request ID to each message to identify its response.
– wOxxOm
Nov 21 '18 at 6:28
Now that I've actually read the thread you've linked, I can say you need to write a native OS app (e.g. using node.js) that acts as a local proxy server for other apps. This app will route the requests to your extension via nativeMesaging API (which is stdio-based as described in the documentation), the extension will make the request using XMLHttpRequest or fetch in the background script and send the response back via nativeMessaging API. BTW, add a monotonically increasing numeric request ID to each message to identify its response.
– wOxxOm
Nov 21 '18 at 6:28
@wOxxOm Thanks for the detailed outline of a possible solution. Makes sense to me!
– halloleo
Nov 21 '18 at 6:40
@wOxxOm Thanks for the detailed outline of a possible solution. Makes sense to me!
– halloleo
Nov 21 '18 at 6:40
add a comment |
1 Answer
1
active
oldest
votes
A Chrome extension has no way* to listen to network connections, at least arbitrary ones.
* Possible exception here being WebRTC, but that's not very useful for proxying standard HTTP.
Native Messaging is, indeed, a way to escape the API limitations by doing whatever you want in a native companion application that talks to the extension via STDIO.
[Extension] <-- STDIO --> [Native host] <-- anything, eg. HTTP --> [Client]
Note that it's not arbitrary STDIO, but a specific JSON-based native host protocol.
Also note that the extension will need to spawn a new copy of the native host application; it can't connect to an already running one.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405962%2fhow-to-listen-to-http-requests-in-a-chrome-extension-and-how-to-set-the-permissi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
A Chrome extension has no way* to listen to network connections, at least arbitrary ones.
* Possible exception here being WebRTC, but that's not very useful for proxying standard HTTP.
Native Messaging is, indeed, a way to escape the API limitations by doing whatever you want in a native companion application that talks to the extension via STDIO.
[Extension] <-- STDIO --> [Native host] <-- anything, eg. HTTP --> [Client]
Note that it's not arbitrary STDIO, but a specific JSON-based native host protocol.
Also note that the extension will need to spawn a new copy of the native host application; it can't connect to an already running one.
add a comment |
A Chrome extension has no way* to listen to network connections, at least arbitrary ones.
* Possible exception here being WebRTC, but that's not very useful for proxying standard HTTP.
Native Messaging is, indeed, a way to escape the API limitations by doing whatever you want in a native companion application that talks to the extension via STDIO.
[Extension] <-- STDIO --> [Native host] <-- anything, eg. HTTP --> [Client]
Note that it's not arbitrary STDIO, but a specific JSON-based native host protocol.
Also note that the extension will need to spawn a new copy of the native host application; it can't connect to an already running one.
add a comment |
A Chrome extension has no way* to listen to network connections, at least arbitrary ones.
* Possible exception here being WebRTC, but that's not very useful for proxying standard HTTP.
Native Messaging is, indeed, a way to escape the API limitations by doing whatever you want in a native companion application that talks to the extension via STDIO.
[Extension] <-- STDIO --> [Native host] <-- anything, eg. HTTP --> [Client]
Note that it's not arbitrary STDIO, but a specific JSON-based native host protocol.
Also note that the extension will need to spawn a new copy of the native host application; it can't connect to an already running one.
A Chrome extension has no way* to listen to network connections, at least arbitrary ones.
* Possible exception here being WebRTC, but that's not very useful for proxying standard HTTP.
Native Messaging is, indeed, a way to escape the API limitations by doing whatever you want in a native companion application that talks to the extension via STDIO.
[Extension] <-- STDIO --> [Native host] <-- anything, eg. HTTP --> [Client]
Note that it's not arbitrary STDIO, but a specific JSON-based native host protocol.
Also note that the extension will need to spawn a new copy of the native host application; it can't connect to an already running one.
answered Nov 22 '18 at 13:19
XanXan
53.9k10105133
53.9k10105133
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405962%2fhow-to-listen-to-http-requests-in-a-chrome-extension-and-how-to-set-the-permissi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
@wOxxOm A local proxy server app is ok, but the HTTP request to the outside world has to be done by Chrome. So the proxy app would need to communicate requests and resposnes with Chrome via Native Messaging, right?
– halloleo
Nov 21 '18 at 6:11
Now that I've actually read the thread you've linked, I can say you need to write a native OS app (e.g. using node.js) that acts as a local proxy server for other apps. This app will route the requests to your extension via nativeMesaging API (which is stdio-based as described in the documentation), the extension will make the request using XMLHttpRequest or fetch in the background script and send the response back via nativeMessaging API. BTW, add a monotonically increasing numeric request ID to each message to identify its response.
– wOxxOm
Nov 21 '18 at 6:28
@wOxxOm Thanks for the detailed outline of a possible solution. Makes sense to me!
– halloleo
Nov 21 '18 at 6:40