For reasons I am not able to explain here in a short manner, I want to use a pac
file for a firefox
test (python-selenium
) to coordinate the used proxy for various types of requests.
Here is the pac
file I am using:
function FindProxyForURL(url, host)
{
console.log("test proxy");
lsjkd fhafh fasdfhsdjkl fhs
if (url.substring(0, 3) === "ws:" || url.substring(0, 4) === "wss:")
{
return "DIRECT";
} else {
return "PROXY 0.0.0.0:8080";
}
}
and here is the complete script for the test:
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
selenium_proxy = webdriver.Proxy()
selenium_proxy.proxy_type = webdriver.common.proxy.ProxyType.PAC
selenium_proxy.proxyAutoconfigUrl = "/path/to/proxy.pac"
profile = webdriver.FirefoxProfile()
profile.set_proxy(selenium_proxy)
driver = webdriver.Firefox(firefox_profile=profile)
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
time.sleep(10)
driver.close()
Because the pac
file contains an obvious syntax error I expect the test to fail (like UnknownError
). However, the page loads without problems and the test succeeds.
Why is the pac
file not use inside the firefox driver? Or is it loaded but ignored? Is it possible to log some text from inside the pac
file?
I tried to do that like above but (even without the syntax error) I cannot see the console.log
anywhere (neither in the browser itself, for which I added the sleep of 10 seconds, so I can press F12 to check the browser's console).
How to be able to use the pac
file for firefox?
Addendum:
You can even use the following pac
file to see it is not being used at all:
//
// Define the network paths (direct, proxy and deny)
//
// Default connection
var direct = "DIRECT";
// Alternate Proxy Server
var proxy = "PROXY 0.0.0.0:8095";
// Default localhost for denied connections
var deny = "PROXY 0.0.0.0:65535";
//
// Proxy Logic
//
function FindProxyForURL(url, host)
{
return deny;
}
EACH request should be denied - but the test still works and the webpage is correctly requested...