Last active
July 31, 2024 20:57
-
-
Save florentbr/25246cd9337cebc07e2bbb0b9bf0de46 to your computer and use it in GitHub Desktop.
Chrome extension to automatically set the credentials.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To build the extension, update the username/password and zip `background.js` and `manifest.json` in a single archive. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var username = "my-username"; | |
var password = "my-password"; | |
var retry = 3; | |
chrome.webRequest.onAuthRequired.addListener( | |
function handler(details) { | |
if (--retry < 0) | |
return {cancel: true}; | |
return {authCredentials: {username: username, password: password}}; | |
}, | |
{urls: ["<all_urls>"]}, | |
['blocking'] | |
); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"manifest_version": 2, | |
"name": "Authentication for ...", | |
"version": "1.0.0", | |
"permissions": ["<all_urls>", "webRequest", "webRequestBlocking"], | |
"background": { | |
"scripts": ["background.js"] | |
} | |
} |
Thank you, this extension works perfectly.
Is it possible if I can use the same solution for chrome android?
it is amazing
Thanks @florentbr , how can we handle if we have more than 1 url need to authenticate with different user name and password?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An existing project I am working on has this solution working fine in JavaScript but I am now migrating that project over to Java - can you provide some more details on how to get this work (OSX)
especially as AddListener has now been deprecated:
chrome.webRequest.onAuthRequired.addListener(