I’ve got problem in proxy authentication using chrome extension (due to problems with v3 my code is based on manifest v2). The connection works using the following curl
command:
curl -v -x https://11.111.11.111:222 https://www.google.com/ --proxy-header "proxy-authorization: Basic abc" --proxy-insecure
And I tried to implement it in extension. Here’s what I have in background.js
file:
chrome.runtime.onStartup.addListener(() => {
const config = {
mode: 'fixed_servers',
rules: {
singleProxy: {
host: '11.111.11.111',
port: 222,
scheme: 'https',
},
},
}
chrome.proxy.settings.set({ value: config, scope: 'regular' })
})
chrome.webRequest.onBeforeSendHeaders.addListener(
(details) => {
const requestHeaders = details.requestHeaders || []
requestHeaders.push({
name: 'proxy-authorization',
value: 'Basic abc',
})
return { requestHeaders }
},
{ urls: ['<all_urls>'] },
['blocking', 'requestHeaders', 'extraHeaders']
)
chrome.webRequest.onSendHeaders.addListener(
(details) => {
console.log('sending', details)
return details
},
{ urls: ['<all_urls>'] },
['requestHeaders', 'extraHeaders']
)
I have the following permissions in manifest.json
:
"permissions": [
"cookies",
"storage",
"tabs",
"activeTab",
"proxy",
"webRequest",
"webRequestBlocking",
"<all_urls>"
]
And these are the headers that are printed in onSendHeaders
function:
You see that proxy-authorization
header is present. But I get ERR_PROXY_CERTIFICATE_INVALID
while trying to browse any page. Proxy headers should be set in a different way? Because I use --proxy-header
flag in the curl command, not --header
.
PS. I tried using the method that is mentioned many times:
chrome.webRequest.onAuthRequired.addListener(function(details, callbackFn) {
callbackFn({
authCredentials: { username: username, password: password }
});
},{urls: ["<all_urls>"]},['asyncBlocking']);
too, but this function is never called (I put console.log inside).