Search code examples
javascriptauthenticationgoogle-chromegoogle-chrome-extensionproxy

Api chrome.webRequest.onAuthRequired. Window in browser when authorizing proxy on some web pages via api chrome.webRequest.onAuthRequired


Appears in the browser when authorizing certain proxy servers on web pages via the chrome.webRequest.onAuthRequired API.

I have developed a chromium extension that relies on a proxy via the chrome.proxy.settings API and authorizes the server with chrome.webRequest.onAuthRequired. I'm using Manifesto 3 version.

ESSENCE OF THE PROBLEM IS THIS: After connecting to the extended server, when reloading the page in the browser, the server is authorized, but on some pages, especially in Google services (for example, https://chrome.google.com/webstore/category/extensions), the server does not is authorized. This is expressed as a result of the chrome system authorization window, with fields for entering USER NAME, PASSWORD with completion and confirmation buttons. To solve problems, you need to go to the next chapter, where you reload the page and go back to the page where the chrome authorization window appears, but disappears and the server will be authorized.

enter image description here

In different Chrome browsers, the behavior is different, but specifically in Chrome this behavior. Also, if I close the browser and then open it again, but do not disable its extension, then the authorization window may appear again, but it will already disappear by pressing the "Cancel" button.

Also, sometimes it happens that the authorization window appears on any random page, but just click "Cancel" and the server is authorized.

`    function authRequired() {
        chrome.webRequest.onAuthRequired.addListener(
          async function (details, callback) {
            const credentials = await new Promise(resolve => {
              chrome.storage.local.get(['selectedIPAddress'], function (result) {
                resolve(JSON.parse(result.selectedIPAddress));
              });
            });
            callback({
              authCredentials: {
                 username: credentials.username,
                password: credentials.password
              }
            });
          },
          { urls: ['<all_urls>'] },
          ['asyncBlocking']
        )
    }
    authRequired()`

I tried to rewrite auth function with blocking and asyncBlocking


Solution

  • I'm having the same exact issue, not sure why the credentials dialog box keeps appearing in certain cases even though a proper listener is defined for chrome.webRequest.onAuthRequired.

    The below seems to provide a clue for a potential solution: https://adguard-vpn.com/en/blog/mv3-browser-extension.html

    "...We’ve also fixed an issue with a browser popup requesting proxy authorization. This used to happen when the session storage wasn't able to load the credentials before the onAuthRequired event handler fired at the service worker wakeup."

    Need to dig into the code on Github and see if this is relevant.