0

I am making a selenium based project to do something but while I was doing it I encountered a error in which if I use headless mode it shows the error but when i dont it doesn't.

I tried not using headless mode and it seemed to be working but when I tried it didnt I want to use headless mode so give fix.

My code:

def new_driver():
    options = Options()
    options.add_extension("proxy.zip")
    options.add_argument("--headless")
    options.add_experimental_option("excludeSwitches", ["enable-logging"])
    options.add_argument('--disable-gpu')
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')
    driver = webdriver.Chrome(options=options)
    return driver

This is my driver code which makes the driver i think the driver launchs tho the error im getting is:

    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: failed to wait for extension background page to load: chrome-extension://lgknfaobibciggbigdkldiecibigdfgm/_generated_background_page.html
from unknown error: page could not be found: chrome-extension://lgknfaobibciggbigdkldiecibigdfgm/_generated_background_page.html

I tried using the disable extension option but it still didnt work

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

3 Answers3

0

This error message...

selenium.common.exceptions.WebDriverException: Message: unknown error: failed to wait for extension background page to load: chrome-extension://jcolbbihfiphppdfbkbhmiabgaomajdf/_generated_background_page.html
from unknown error: page could not be found: chrome-extension://jcolbbihfiphppdfbkbhmiabgaomajdf/_generated_background_page.html

...implies that Headless mode didn't previously supported extensions which was actively tracked through the discussion Issue 604324: Selenium support for headless.


Current status

Based on the recent development and implementation to add an extension to you can use either of the following approaches:

  • Using the argument --headless=new as follows:

    options = Options()
    options.add_argument("--headless=new")
    
  • Using the argument --headless=chrome as follows:

    options = Options()
    options.add_argument("--headless=chrome")
    

tl; dr

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

The error message you are seeing suggests that there may be an issue with loading the extension you are trying to use. Here are some potential solutions you can try:

Make sure the extension file exists and is accessible. Double-check that the file path is correct and that the file has the correct permissions.

Try using a different extension. It's possible that the extension you are using is causing the issue. Try using a different extension and see if the error goes away.

Disable extensions altogether. If you don't need to use an extension for your project, try running the code without any extensions enabled.

Update your ChromeDriver and Chrome browser to the latest version. This can help ensure that there are no compatibility issues between the browser, the driver, and the extension.

Try using a different browser. If none of the above solutions work, try using a different browser with Selenium, such as Firefox or Safari, to see if the issue persists. from selenium.webdriver.chrome.service import Service

  def new_driver():
    options = Options()
    options.add_argument("--headless")
    options.add_argument('--disable-gpu')
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')
    options.add_experimental_option("excludeSwitches", ["enable-logging", 
         "enable-automation"])
    service = Service('/usr/local/bin/chromedriver') # replace with your 
    own ChromeDriver path
    driver = webdriver.Chrome(service=service, options=options)
    return driver
Raziye
  • 33
  • 1
  • 1
  • 8
  • lmfao bro used chat gpt – Idk Jun 07 '23 at 21:10
  • @Idk How can you be so sure ;) – undetected Selenium Jun 07 '23 at 21:12
  • Welcome to Stack Overflow! Your answer appears likely to have been written (entirely or partially) by AI (e.g., ChatGPT). Please be aware that [posting of AI-generated content is banned here](//meta.stackoverflow.com/q/421831). If you used an AI tool to assist with any answer, I would encourage you to delete it. – NotTheDr01ds Jun 11 '23 at 15:15
  • **Readers should review this answer carefully and critically, as AI-generated information often contains fundamental errors and misinformation.** If you observe quality issues and/or have reason to believe that this answer was generated by AI, please leave feedback accordingly. The moderation team can use your help to identify quality issues. – NotTheDr01ds Jun 11 '23 at 15:15
0

As the answer in https://stackoverflow.com/a/73840130/7058266 already says, you'll need to use the new Chrome headless mode if you want to use extensions in headless mode.

Usage: (Chrome 109 and above):

options.add_argument("--headless=new")

If something works in regular Chrome, it should now work with the newer headless mode too.

Michael Mintz
  • 9,007
  • 6
  • 31
  • 48