Last active
May 27, 2022 22:58
-
-
Save gavinhungry/5373f7de495a820f4a49eea202354840 to your computer and use it in GitHub Desktop.
Auto Basic Auth
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
(() => { | |
/* | |
chrome.storage.local.set({ | |
credentials: { | |
'example.com': { | |
username: 'foo', | |
password: '***' | |
} | |
} | |
}); | |
*/ | |
chrome.storage.local.get(['credentials'], ({ credentials = {} }) => { | |
const REQS = new Set(); | |
setInterval(() => { | |
REQS.clear(); | |
}, 60000); | |
let onAuthRequired = ({ challenger, requestId }) => { | |
let hostKey = Object.keys(credentials).find(hostKey => { | |
return ( | |
challenger.host === hostKey || | |
challenger.host.endsWith(`.${hostKey}`) | |
); | |
}); | |
if (!hostKey) { | |
return; | |
} | |
if (REQS.has(requestId)) { | |
return { | |
cancel: true | |
}; | |
}; | |
REQS.add(requestId); | |
return { | |
authCredentials: credentials[hostKey] | |
}; | |
}; | |
chrome.webRequest.onAuthRequired.addListener(onAuthRequired, { | |
urls: ['https://*/*'] | |
}, ['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
{ | |
"name": "Auto Basic Auth", | |
"description": "Auto-login with basic auth", | |
"author": "Gavin Lloyd <[email protected]>", | |
"manifest_version": 2, | |
"version": "1.2.0", | |
"permissions": ["webRequest", "webRequestBlocking", "storage", "https://*/*"], | |
"background": { | |
"persistent": true, | |
"scripts": ["auto-basic-auth.js"] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment