Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome proxy api - Uncaught TypeError: Invalid invocation

I want to use the chrome proxy API. I have this code in my background script but it will not work

const proxyData = []

const fetchProxyData = () => {
  axios({
    method: "GET",
    baseURL: "https://api.getproxylist.com/proxy",
    params: {
      protocol: "http",
      allowsPost: 1,
      allowsHttps: 1,
      anonimity: "high anonymity"
    }
  }).then( (response) => {
    console.log(response.data)
    proxyData.push(response.data)
  })
}

fetchProxyData();

var config = {
  mode: "fixed_servers",
  rules: {
    singleProxy: {
      host: proxyData.ip,
      port: proxyData.port
    }
  }
}

chrome.proxy.settings.set({
   value: config,
   scope: "regular"
 }, () => {
   console.log(`proxy configured with data: ${proxyData}`)
})

I get this error in background page console: background.js:55 Uncaught TypeError: Invalid invocation

I've tried with the example provided with the proxy api documentation and the error will not occur. Maybe it's caused by the config object? To set the proxy as you can see in the code, I'm using an ajax call, maybe is this the problem?

is there any fix?

like image 363
nukiko12 Avatar asked Dec 15 '25 04:12

nukiko12


1 Answers

I have also faced the same problem when I find the solution, it was silly mistake.

I had passed string value to port.

Please make sure you are passing integer value to port

like image 170
Satender K Avatar answered Dec 16 '25 22:12

Satender K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!