Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save skouny/de799abdae3d7aff0d1ab0a1b0d88163 to your computer and use it in GitHub Desktop.
Save skouny/de799abdae3d7aff0d1ab0a1b0d88163 to your computer and use it in GitHub Desktop.
Chrome extension to automatically set the credentials.
To build the extension, update the username/password and zip `background.js` and `manifest.json` in a single archive.
Ensure you put the credentials for the corect host.
Without retry will try to login again and again.
var host = "my-host.com";
var username = "my-username";
var password = "my-password";
var retry = 3;
chrome.webRequest.onAuthRequired.addListener(
function handler(details) {
if ('challenger' in details && 'host' in details['challenger'] && details['challenger']['host'].includes(host)) {
if (--retry < 0) return { cancel: true };
return { authCredentials: { username: username, password: password } };
}
},
{urls: ["<all_urls>"]},
['blocking']
);
{
"manifest_version": 2,
"name": "Authentication for ...",
"version": "1.0.0",
"permissions": ["<all_urls>", "webRequest", "webRequestBlocking"],
"background": {
"scripts": ["background.js"]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment