0

I was trying to make an extension that sets the proxy on startup, but I always get the error "TypeError: Invalid invocation", I have tried all the solutions i found in google, and also here in stackoverflow.

Here's my code.

background.js

chrome.runtime.onStartup.addListener(() => {
 // config, i also tried using just 'singleProxy'
 const value = {
  mode: 'fixed_servers',
  rules: {
    proxyForHttp: {
      scheme: 'http',
      host: 'some.proxyhost.com',
      port: 44444,
    },
    proxyForHttps: {
      scheme: 'http',
      host: 'some.proxyhost.com',
      port: 44444,
    },
    proxyForFtp: {
      scheme: 'http',
      host: 'some.proxyhost.com',
      port: 44444,
    },
    bypassList: [],
  },
};


chrome.proxy.settings.set({
  value,
  function() {
  },
});

});

and also I tried adding that code on popup. and activating it by triggering a button and still no luck. I also tried using another proxy extension and it works. Also tried it in manifest v2, but still I get the same error.

manifest.json

{
  "manifest_version": 3,
  "name": "Proxy Setter Extension",
  "version": "1.0.0",
  "background": { "service_worker": "background.bundle.js" },
  "permissions": ["proxy", "scripting", "tabs"],
  "action": {
    "default_popup": "popup.html",
    "default_icon": "icon-34.png"
  },
  "icons": {
    "128": "icon-128.png"
  },
  "content_scripts": [
    {
      "matches": ["http://*/*", "https://*/*", "<all_urls>"],
      "js": ["contentScript.bundle.js"],
      "css": ["content.styles.css"]
    }
  ],
  "devtools_page": "devtools.html",
  "web_accessible_resources": [
    {
      "resources": ["content.styles.css", "icon-128.png", "icon-34.png"],
      "matches": []
    }
  ]
}
Marcus Jason
  • 250
  • 4
  • 11
  • Your callback of chrome.proxy.settings.set is in the wrong place. Either remove it entirely or move it outside so it becomes a second parameter of the call. – wOxxOm Jul 22 '21 at 05:33
  • @wOxxOm oh crap I miss that. thanks, but now I have a problem, the webRequest.onAuthRequired implementation for setting authcredentials, does not work anymore because 'blocking' or 'asyncblocking' is not supported on mv3, how would I do that? here's the answer I want to try but this is for v2 https://stackoverflow.com/questions/16612968/chrome-webrequest-onauthrequired-listener – Marcus Jason Jul 22 '21 at 05:51
  • See https://crbug.com/1135492. You'll have to use MV2 for now. – wOxxOm Jul 22 '21 at 07:08
  • @wOxxOm I just saw your comment there earlier btw :D , yah I just switched to v2 for now. sucks :( . thanks btw, – Marcus Jason Jul 22 '21 at 07:11

0 Answers0