1

I am working on proxy extension for chrome browser. My extension sets proxy config of the browser using:

chrome.proxy.settings.set({
    value: config,
    scope: 'regular',
});

Where config uses fixed_servers mode.

Proxy servers require authentication, therefore I have:

chrome.webRequest.onAuthRequired.addListener(details => {
    // Some logic
    return {
        authCredentials: {
            username: usernameValue,
            password: passwordValue,
        },
    };
});

Up until latest 71st Chrome version this logic was working as expected:
Browser boots > extensions initialized > all traffic goes through proxy and auth requests from proxy server are handled by listener.
Since 71st version it seems that browser doesn't wait for extensions to be initialized(issue appears after Hard Quit, i.e. using command + Q) and starts sending requests. Since proxy config is already set:
Requests go through proxy > proxy server requests authentication > extension is still not initialized by browser, therefore auth request listener is not added in the background as well - since there is nothing to intercept auth requests - native auth prompt is sown for the user.

This ends up in a very bad UX + moments later when extension gets initialized, listener is already in place, so user either can fill the prompt and submit, or simply cancel - anyway proxy and its auth works.

I am looking for solution for this situation. Maybe there is a way to set some config for the browser that prevents it from doing requests until certain extension is initialized, or some way to suspend/reset/clear proxy config before browser quit(then I could manually set proxy again on init). Or any other fix for a given situation.

I've already tried to us chrome.windows methods to monitor when browser windows are created and removed and on last one being removed tried calling chrome.proxy.settings.clear({ scope: 'regular' }, function() {...});, but as I figured out, only sync manage to happen before quit, while async do not, hence chrome.proxy.settings.clear() is of no use.

I am thankful in advance for any tips, suggestions, solutions/hacks and etc.

Mindaugas
  • 1,173
  • 5
  • 15
  • 31
  • I don't know why it was working for you previously, but Chrome always delayed extension background page initialization *by design*. You can try finding what's changed for your use case via [bisecting](https://www.chromium.org/developers/bisect-builds-py). – wOxxOm Jan 04 '19 at 11:55
  • 2
    [Content scripts aren't delayed](https://crbug.com/60185) so one possible hack would be to block every page using a content script that runs at `document_start` by opening a synchronous XHR with a 100ms timeout to any internal URL like your manifest, and repeat the loop until chrome.runtime.connect() succeeds. – wOxxOm Jan 04 '19 at 12:06
  • I assumed previous versions were not firing network requests on browser initialization until extension is initialized, because multiple proxy extensions use this pattern and it was all good until recent release, and as I tested now - not only mine, but basically all major proxy extensions that use auth are affected and started having the issue. Also, I find it odd that this happens only after "hard quit" with command + Q. Anyway, thanks a lot for the suggested solution, I'll dig into this and see what can be done. – Mindaugas Jan 04 '19 at 13:36
  • 2
    @MindaugasJačionis You should see if a bug for this was already filed at https://crbug.com/ and file it if it wasn't. This definitely sounds like a regression. – Xan Jan 04 '19 at 14:17

0 Answers0