Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Running headless selenium with proxy
So I've created this code wich allows me to run selenium with a proxy (IP:PORT:AUTH:PASS)
import os
import zipfile
import time
from selenium import webdriver

PROXY_HOST = 'My host is here(dont show it because it is private)' 
PROXY_USER = 'my username(dont show it because it is private)'
PROXY_PASS = 'the password(dont show it because it is private)'

manifest_json = """
    "version": "1.0.0",
    "manifest_version": 2,
    "name": "Chrome Proxy",
    "permissions": [
    "background": {
        "scripts": ["background.js"]

background_js = """
var config = {
        mode: "fixed_servers",
        rules: {
          singleProxy: {
            scheme: "http",
            host: "%s",
            port: parseInt(%s)
          bypassList: ["localhost"]

chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});

function callbackFn(details) {
    return {
        authCredentials: {
            username: "%s",
            password: "%s"

            {urls: ["<all_urls>"]},

def get_chromedriver(use_proxy=False, user_agent=None):
    path = os.path.dirname(os.path.abspath(__file__))
    chrome_options = webdriver.ChromeOptions()
    if use_proxy:
        pluginfile = ''

        with zipfile.ZipFile(pluginfile, 'w') as zp:
            zp.writestr("manifest.json", manifest_json)
            zp.writestr("background.js", background_js)
    if user_agent:
        chrome_options.add_argument('--user-agent=%s' % user_agent)
    driver = webdriver.Chrome(
        os.path.join(path, 'chromedriver'),
    return driver

def main():
    driver = get_chromedriver(use_proxy=True)

if __name__ == '__main__':
So when I run this, everything works fine and the proxy works. But as soon as I run this headless (wich is my goal) it gives the following error:
C:/Users/Julius/PycharmProjects/Fenix/venv/ DeprecationWarning: use options instead of chrome_options driver = webdriver.Chrome( Traceback (most recent call last): File "C:/Users/Julius/PycharmProjects/Fenix/venv/", line 108, in <module> main() File "C:/Users/Julius/PycharmProjects/Fenix/venv/", line 102, in main driver = get_chromedriver(use_proxy=True) File "C:/Users/Julius/PycharmProjects/Fenix/venv/", line 96, in get_chromedriver driver = webdriver.Chrome( File "C:\Users\Julius\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\", line 76, in __init__ RemoteWebDriver.__init__( File "C:\Users\Julius\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\", line 157, in __init__ self.start_session(capabilities, browser_profile) File "C:\Users\Julius\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "C:\Users\Julius\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\", line 321, in execute self.error_handler.check_response(response) File "C:\Users\Julius\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: failed to wait for extension background page to load: chrome-extension://hppjijlamkeconblfhjmcjlopacliakh/_generated_background_page.html from unknown error: page could not be found: chrome-extension://hppjijlamkeconblfhjmcjlopacliakh/_generated_background_page.html
does someone know the fix for this? Or a different method to run selenium headless with a proxy?
please let me know!!
line 96 didn't allow enough time for process to finish. However, line numbers don't match code.
I suspect line 77 is the error item.
try adding a delat of a couple of seconds after line 79
you can shorten delay by experimenting

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)