Skip to content

Instantly share code, notes, and snippets.

@JasonCrowe
Created May 8, 2020 19:04
Show Gist options
  • Save JasonCrowe/e38024da18987d434e366fa1783b13ae to your computer and use it in GitHub Desktop.
Save JasonCrowe/e38024da18987d434e366fa1783b13ae to your computer and use it in GitHub Desktop.
proxy_via_extention
manifest_json = """
{
"version": "1.0.0",
"manifest_version": 2,
"name": "Chrome Proxy",
"permissions": [
"proxy",
"tabs",
"unlimitedStorage",
"storage",
"<all_urls>",
"webRequest",
"webRequestBlocking"
],
"background": {
"scripts": ["background.js"]
},
"minimum_chrome_version":"22.0.0"
}
"""
background_js = """
var config = {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: "http",
host: "%s",
port: parseInt(%s)
}
}
};
chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
function callbackFn(details) {
return {
authCredentials: {
username: "%s",
password: "%s"
}
};
}
chrome.webRequest.onAuthRequired.addListener(
callbackFn,
{urls: ["<all_urls>"]},
['blocking']
);
""" % self.current_proxy
pluginfile = f'proxy_auth_plugin_{self.thread}.zip'
with zipfile.ZipFile(pluginfile, 'w') as zp:
zp.writestr("manifest.json", manifest_json)
zp.writestr("background.js", background_js)
co = Options()
co.add_extension(pluginfile)
driver = webdriver.Chrome('./chromedriver', chrome_options=co)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment