Proxy Auth options

533 views
Skip to first unread message

Marek Kiraly

unread,
Mar 1, 2023, 9:30:55 AM3/1/23
to Chromium Extensions
Hello, I have been searching for any information on how to implement a proxy authentication into my extension for a while now. Unfortunately, I haven't had much luck. Is there currently a way to do that ? What does currently happen if my user connects to a proxy that requires credentials ? 

I would be very grateful for any information or example code snippets. 

Oliver Dunk

unread,
Mar 2, 2023, 5:18:32 AM3/2/23
to Marek Kiraly, Chromium Extensions
Hi Marek,

Depending on the exact type of authentication, you may be able to use the onAuthRequired API for this: https://developer.chrome.com/docs/extensions/reference/webRequest/#event-onAuthRequired

In Manifest V3, add the following to your manifest:

```
"permissions": [
  "webRequest",
  "webRequestAuthProvider"
],
"host_permissions": [
  "<all_urls>"
]
```

And code like this in the background:

```
chrome.webRequest.onAuthRequired.addListener(
  (_, callback) => {
    callback({
      authCredentials: {
        username: "username",
        password: "password",
      },
    });
  },
  { urls: ["<all_urls>"] },
  ["asyncBlocking"]
);
```

In Manifest V2, you'd want to replace the `webRequestAuthProvider` permission with `webRequestBlocking`.
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB


On Wed, Mar 1, 2023 at 2:31 PM Marek Kiraly <marek.k...@gmail.com> wrote:
Hello, I have been searching for any information on how to implement a proxy authentication into my extension for a while now. Unfortunately, I haven't had much luck. Is there currently a way to do that ? What does currently happen if my user connects to a proxy that requires credentials ? 

I would be very grateful for any information or example code snippets. 

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/34dfd651-2f7e-4ca6-8848-72409d8b5eeen%40chromium.org.

Marek Kiraly

unread,
Mar 11, 2023, 9:11:05 AM3/11/23
to Chromium Extensions, Oliver Dunk, Chromium Extensions, Marek Kiraly
Hi, thank you for the example!!!


Isn't weRequest API going to be deprecated in MV3 ? I wanted to use the onBeforeSendHeaders listener to edit the Accept-Language header and User-Agent header, but i couldn't make it happen in MV3 :( 

Thank you,
Marek :)

Dne čtvrtek 2. března 2023 v 11:18:32 UTC+1 uživatel Oliver Dunk napsal:

Tom Riley

unread,
Mar 12, 2023, 10:14:08 PM3/12/23
to Chromium Extensions, Marek Kiraly, Oliver Dunk, Chromium Extensions
>Isn't weRequest API going to be deprecated in MV3 ?

It is, but requesting "webRequest" & "webRequestAuthProvider" permissions in the manifest will allow you to still use chrome.webRequest.onAuthRequired only (https://bugs.chromium.org/p/chromium/issues/detail?id=1135492#c93). For changing headers, you probably need to use the new chrome.declarativeNetRequest API, that's what we'll need to do (our extension also handles proxy auth and adding headers) if there isn't a nicer way by the time the next deadline for MV2 deprecation is decided.

David

unread,
Sep 10, 2024, 4:42:20 AMSep 10
to Chromium Extensions, Tom Riley, Marek Kiraly, Oliver Dunk, Chromium Extensions
Hi guys! i have similar issue i am try to add Proxy-Authenticate headers  to CONNECT request by it seems like it doesnt work. May be you have faced this problem before? Really appreciate any suggestion. Thank you!


const rules: chrome.declarativeNetRequest.Rule[] = [
{
id: 1,
priority: 1,
action: {
type: chrome.declarativeNetRequest.RuleActionType.MODIFY_HEADERS,
requestHeaders: [
{
operation: chrome.declarativeNetRequest.HeaderOperation.SET,
header: 'Proxy-Authenticate',
value: 'Basic '+ b,
},
]
},
condition: {
requestMethods: [chrome.declarativeNetRequest.RequestMethod.CONNECT]
}
},

понедельник, 13 марта 2023 г. в 05:14:08 UTC+3, Tom Riley:
Reply all
Reply to author
Forward
0 new messages