Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set proxy using google chrome extension

I am trying to build a chrome extension which can change proxy settings when the fire up the browser. I have followed the chrome extension documentation but still no success.

manifest.json

   {

      "manifest_version": 2,

      "name": "Proxy",
      "description": "Proxy on 127.0.0.1:8080",
      "version": "1.1",
      "background": {
      "scripts":["background.js"]
      },
      "browser_action": {
            "default_icon": "icon.png",
            "popup":"popup.html"
        },
    "permissions": [
        "tabs",
        "http://*/*",
        "https://*/*",
        "notifications",
        "contextMenus",
        "history",
        "background",
        "proxy"
    ],
    "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
    }

backround.js

chrome.windows.onCreated.addListener(function() {

var config = {
  mode: "fixed_servers",
  rules: {
    proxyForHttp: {
      scheme: "http",
      host: "127.0.0.1",
      port:"8080"
    },
    bypassList: ["foobar.com"]
  }
};
chrome.proxy.settings.set(
    {value: config, scope: 'regular'},
    function() {});

});

The above code doesn't works...

like image 332
user2098016 Avatar asked Feb 22 '13 09:02

user2098016


People also ask

How do I manually set a proxy in Chrome?

Step1: To set proxy in Google Chrome Go to Option (Top-Right Side) > Click on Under the Hood Tab > Click on Change Proxy Settings and you can change Proxy from there.

How do I use a proxy switcher extension?

Simply open toolbar popup and click on the desired category. There are five categories available to choose from. Moreover, badge icon color changes according to the chosen category. Once the proxy is set, a notification popup shows you the current state.


3 Answers

Change the line port:"8080" to port:8080 and it'll work.


Nicety

You can check effective settings at chrome://net-internals/#proxy.

Nicety

If via PAC script, on script code error, chrome.proxy.settings.set handler still runs even as the proxy fails silently. This can be detected at chrome://net-internals/#events.


Nicety

This page claims that console.log messages in your PAC script can be found in net log, but it doesn't seem to work.

like image 113
Pacerier Avatar answered Sep 20 '22 00:09

Pacerier


I've been trying everything since yesterday, finally found my issue; I had to change

proxyForHttp: --> singleProxy:

and

port:'8080' --> port: 8080

like image 33
arif Avatar answered Sep 21 '22 00:09

arif


It shouldn't be a problem with the background page. Your code is in the onCreated event on the window object. You are not guaranteed to have the extension loaded by the time the first window is created.

Simply remvove the event and have the code run, you should then have it run once when the extension is initialised.

like image 40
Kinlan Avatar answered Sep 20 '22 00:09

Kinlan