Skip to content

Instantly share code, notes, and snippets.

@jxpx777
Created May 17, 2012 19:00
Show Gist options
  • Select an option

  • Save jxpx777/2720920 to your computer and use it in GitHub Desktop.

Select an option

Save jxpx777/2720920 to your computer and use it in GitHub Desktop.
JSE: Chrome HTTP auth callback
var gPendingCallbacks = [];
var bkg = chrome.extension.getBackgroundPage();
bkg.console.log("Listening")
chrome.webRequest.onAuthRequired.addListener(handleAuthRequest,
{urls: ["<all_urls>"]}, ["asyncBlocking"]);
function processPendingCallbacks() {
bkg.console.log("Calling back with credentials");
var callback = gPendingCallbacks.pop();
callback({authCredentials: {username: <your username>,
password: <your password>}});
}
function handleAuthRequest(details, callback) {
gPendingCallbacks.push(callback);
processPendingCallbacks();
}
{
"name": "Basic HTTP Auth Extension",
"version": "1.0",
"description": "Send credentials to basic HTTP auth pages.",
"browser_action": {
"default_icon": "icon.png"
},
"background": {
"scripts": ["background.js"]
},
"permissions": [
"webRequest",
"webRequestBlocking",
"tabs",
"https://*/*
"http://*/*
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment