I'm trying to make Chrome extension which turns on-off proxy in browser. I wrote some code in javascript using documentation about chrome extensions, and what is interesting, some times extension works right.
Here is some code in Golang, which iterates through list of https proxy addresses, makes http requests to www.stackoverflow using this proxy addresses and if response status code is 2xx (because some of addresses are invalid, deprecated, unavailable, banned and etc), it marks proxy address correct and prints it.
The second block of the code sets chrome.proxy.settings
property with found 'good' proxy address. By now I'm just copy-pasting it by hands.
The question is: Why is Golang sorts out "bad" proxy address, gives me list of "good" proxies, but Chrome, when I trying to set any of this "good" proxies gives me ERR_PROXY_CONNECTION_FAILED
?
EDIT: in Go
add User-Agent
header, in JavaScript
add scheme : https
field to config
object for proxy.
Still not working.
// checkProxy returns true if proxy adress a is valid and
// response by http request with this proxy is ok (2xx)
//185.132.179.108:1080
//185.132.179.107:1080
func checkProxy(a string) (string, bool) {
proxyUrl, err := url.Parse("http://" + a)
httpClient := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(proxyUrl),
},
}
req, err := http.NewRequest("GET", "http://stackoverflow.com", nil)
if err != nil {
return "", false
}
req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36")
response, err := httpClient.Do(req)
if err != nil {
return "", false
}
if response.StatusCode <= 200 && response.StatusCode >= 299 {
return "", false
} else {
return a, true
}
}
function setProxySettings(iip, pport) {
var config = {
mode: "fixed_servers",
rules: {
//https://www.proxy-list.download/HTTPS
// host: "107.191.63.8",
// port: 32482
singleProxy: {
scheme: "https",
host: iip,
port: parseInt(pport)
},
}
};
chrome.proxy.settings.set({
value: config,
scope: 'regular'
},
function () {});
}