在我的Google Chrome扩展程序中,我的popup.js
包括:
function setProxyToUse() {
var enable = {
mode: "fixed_servers",
rules: {
proxyForHttps: {host: localStorage["surveyHTTPS"]},
proxyForHttp: {host: localStorage["surveyHTTP"]}
}
};
var disable = {mode: "system"}
if (localStorage["proxyOn"] == true) {var config = enable} else {var config = disable}
chrome.proxy.settings.set({value: config, scope: 'regular'},function() {});
chrome.proxy.settings.get({}, function(config) {console.log(config.value.host);} );
}
最后一行只是将undefined
写入控制台。如何查看我正在使用的代理主机?
答案 0 :(得分:0)
默认代理值是一个字符串"system"
,它没有您尝试显示的属性(.host
)。
如果您想要阅读刚刚设置的值,请在.set
的回调中执行此操作,因为chrome API是异步的:
chrome.proxy.settings.set({value: config, scope: 'regular'}, function() {
chrome.proxy.settings.get({}, function(config) {
console.log(config.value, config.value.host);
});
});