【问题标题】:Chrome extension proxy authenticationChrome extension proxy authentication
【发布时间】:2022-12-19 06:15:29
【问题描述】:

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).

【问题讨论】:

  • Your issue does not seem to be in the authorization, but in the fact that you can't reproduce the behavior of --proxy-insecure (since the certificate is not trusted for IP). Is there a specific reason the proxy runs over HTTPS? If it's a proxy you control, can you set up your own cert for the IP and set up OS trust for it?

标签: javascript google-chrome-extension proxy


【解决方案1】:

Have you solved this problem?

If not try this:

chrome.webRequest.onAuthRequired.addListener(function(details, callbackFn) {
    callbackFn({
        authCredentials: { username: username, password: password }
    });
},{urls: ["<all_urls>"]},['blocking']);

Main change -AsyncBlocking=>Blocking

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-09
    • 1970-01-01
    • 1970-01-01
    • 2016-07-27
    • 1970-01-01
    • 2019-11-10
    • 1970-01-01
    相关资源
    最近更新 更多