google-chrome - Chrome extensions proxy API not working
问题描述
My code:
function setproxy() {
var config = {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: "http",
host: "67.205.148.246",
port: 53
},
bypassList: ["*site1.com", "*site2.com", "*ifconfig.co"]
}
};
alert(JSON.stringify(config));
chrome.proxy.settings.set(
{value: config, scope: 'regular'},
function() {});
}
document.getElementById('setproxy').addEventListener('click', setproxy);
When I click on setproxy button proxy does not work.
In chrome://net-internals/#proxy I see this:
Effective proxy settings
Proxy server: 67.205.148.246:53
Bypass list:
*site1.com
*site2.com
*ifconfig.co
But when I check IP with ifconfig.co it is still mine.
In manifest.json I set permissioms:
"permissions": ["proxy", "tabs", "http:///","https:///"]
But it does not work yet. Why?
67.205.148.246:53 is example proxy, founded in internet. It works (I try it in Firefox)
解决方案
var proxyConfig = function (proxyAddress) {
if (proxyAddress === null || proxyAddress === "") {
return {
mode: "direct"
};
}
return {
mode: "fixed_servers",
rules: {
proxyForHttp: {
host: proxyAddress.split(":")[0],
port: parseInt(proxyAddress.split(":")[1])
},
proxyForHttps: {
host: proxyAddress.split(":")[0],
port: parseInt(proxyAddress.split(":")[1])
},
bypassList: ["www.google.com"]
}
}
};
试试看:
- 替换 singleProxy -> proxyForHttp || proxyForHttps
- 并删除 {scheme: "https"...}
推荐阅读
- java - 使用联接表获取数据时在 JPA 中出现错误“无效列”
- cypress - 赛普拉斯在尝试将表格的一列复制到另一列时无法找到“textarea”来输入文本
- safari - 使用 nuxt 时如何解决 safari 上的渲染问题?
- php - 错误“找不到文件”。在 wordpress 中使用 nginx
- reactjs - Material Ui 自动完成 - 过滤选项未按预期工作
- oracle-apex - 如何在 oracle apex sql 命令查询结果中添加自定义标题
- c - 使用电缆环回在 C 中进行串行通信
- javascript - 如何匹配两个数组并更改元素ID与打字稿中的另一个ID匹配的颜色
- python - 根据 if 条件创建一个新列,但在 python 中出现错误
- kubernetes - 在没有相关运算符的情况下创建 crd 会发生什么?