我怎么知道chrome.proxy.settings.set是否正确设置了我的代理

How can I tell whether chrome.proxy.settings.set is correctly setting my proxies

本文关键字:设置 我的 代理 是否 chrome proxy settings set 我怎么知道      更新时间:2023-09-26

在我的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写入控制台。如何检查我正在使用的代理主机?

默认代理值是一个字符串"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);
    }); 
});