From 6e27c106309cd5324ca6b67b5f15900b11e9ec59 Mon Sep 17 00:00:00 2001 From: Samuele Pilleri Date: Mon, 26 Sep 2022 11:10:11 +0200 Subject: [PATCH] Automatically fallback to DIRECT when PAC unavailable When the configured PAC file is unavailable Windows automatically reverts to DIRECT connections, which is useful for example when connecting the work laptop to home Wi-Fi. This commit mimics said behaviour. --- px/pac.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/px/pac.py b/px/pac.py index 9ce4be6..5210590 100644 --- a/px/pac.py +++ b/px/pac.py @@ -57,7 +57,11 @@ def find_proxy_for_url(self, url, host): Return comma-separated list of proxy servers to use for this url DIRECT can be returned as one of the options in the response """ - proxies = self.ctxt.eval("FindProxyForURL")(url, host) + try: + proxies = self.ctxt.eval("FindProxyForURL")(url, host) + except quickjs.JSException: + dprint("Could not evaluate PAC file, falling back to DIRECT...") + return "DIRECT" # Fix #160 - convert PAC return values into CURLOPT_PROXY schemes for ptype in ["PROXY", "HTTP"]: