Skip to content

Instantly share code, notes, and snippets.

@TBG-FR
Last active January 26, 2022 16:20
Show Gist options
  • Save TBG-FR/c9c48d68741766602e1a2469d328c3e9 to your computer and use it in GitHub Desktop.
Save TBG-FR/c9c48d68741766602e1a2469d328c3e9 to your computer and use it in GitHub Desktop.
This Powershell script allows you to apply a Proxy PAC configuration to Chrome, without needing to modify Windows Proxy Settings (or even restarting Windows)
##################################################################################
##
## Description : This Powershell script allows you to apply a Proxy PAC configuration to Chrome, without needing to modify Windows Proxy Settings (or even restarting Windows)
##
## Tips : If Chrome Proxy configuration isn't working after launching this script, go to chrome://net-internals/#proxy and "Clear bad proxies"
##
## Usage : Edit $proxyPacURL and launch the script (or make a shortcut with "powershell.exe -noexit -ExecutionPolicy Bypass -File C:\path\to\the\script\LaunchChromeProxyPac.ps1")
##
## Author : Tom-Brian GARCIA ( https://github.com/TBG-FR )
##
##################################################################################
$proxyPacURL = "http://YOUR_URL/proxy.pac";
try
{
## Download the Proxy PAC and put its content in a variable
$proxyPacBytes = (Invoke-webrequest -URI $proxyPacURL).Content;
Write-Host "Using Proxy PAC from $proxyPacURL.";
## Convert Proxy PAC content to Base64
$proxyPacBase64 = [Convert]::ToBase64String($proxyPacBytes)
Write-Host "Converted Proxy PAC to a Base64 string of $($proxyPacBase64.Length) characters.";
## Launch Chrome with our params
## No CORS -> --disable-web-security
## Separated session/files -> --user-data-dir="C:/Temp/ChromeDev"
& 'C:\Program Files\Google\Chrome\Application\chrome.exe' --proxy-pac-url='data:application/x-javascript-config;base64,'$proxyPacBase64;
Write-Host "Starting Chrome with the Proxy PAC !";
## Close terminal
stop-process -Id $PID;
exit 0
}
catch
{
Write-Host "Error: $($_.Exception.Message)";
exit 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment