我需要更新这个代码,以便它在Manifest v3.On搜索我发现“Chrome.webRequest”现在在Manifest v3中不支持。在文档中,它说要使用“Chrome”,但是如何将它与“onAuthRequired”和“onBeforeSendHeaders.addListener”一起使用
Proxy.prototype.setProxy = function (
proxyAddress,
proxyUsername,
proxyPassword
) {
if (proxyAddress === undefined || proxyAddress.trim() === "") {
setProxySettings(config())
.then(() => {
debugProxySettings();
})
.catch((error) => {
console.error("Error setting proxy:", error);
});
} else {
setProxySettings(config(proxyAddress))
.then(() => {
if (proxyAddress !== "" && proxyUsername !== "") {
if (chrome.webRequest.onAuthRequired) {
chrome.webRequest.onAuthRequired.addListener(
function (details) {
return {
authCredentials: {
username: proxyUsername.trim(),
password: proxyPassword.trim(),
},
};
},
{ urls: ["<all_urls>"] },
["blocking"]
);
} else {
chrome.webRequest.onBeforeSendHeaders.addListener(
function (details) {
return credentialsToHeader(
details,
proxyUsername.trim(),
proxyPassword.trim()
);
},
{ urls: ["<all_urls>"] },
["blocking", "requestHeaders"]
);
}
}
debugProxySettings(proxyUsername, proxyPassword);
})
.catch((error) => {
console.error("Error setting proxy:", error);
});
}
};
1条答案
按热度按时间mlnl4t2r1#
将此权限添加到清单文件
manifest.json
backgroung.js
这个对我很有效