2

I am trying to use an adblocker and running my chrome driver headlessly, doing both separately gives me no error but adding both options gives me the following error:

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

From what I could understand, the adblock extension is looking for the background page and isn't finding it as it is in headless mode. (it works fine without the headless mode)

Testable code (gives the error):

from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
# adblocker crx file, downloaded from: https://chrome-extension-downloader.com/
chrome_options.add_extension("Adblocker-for-Chrome-NoAds_v3.2.0.1.crx")
chrome_options.add_argument("headless")

driver = webdriver.Chrome(options=chrome_options)

Things I have tried:

·Different adblocker. (can provide a list)

·Making the code wait at various place. (as the error said it failed to wait for something)

·Going headless but without an adblocker. (was slower than with an adblocker and the window's GUI showing)

·Asking google multiple times the question. (didn't work...)

If anyone knows a solution to run the chrome browser headless using python selenium while having an adblock extension, I would like to know it too, thanks.

Tissuebox
  • 1,016
  • 3
  • 14
  • 36
  • Possible duplicate.Check the following SO link : https://stackoverflow.com/questions/42231604/how-to-activate-adblocker-in-chrome-using-selenium-webdriver – KunduK Apr 19 '19 at 20:13
  • Not a duplicate. I wasn't clear enough, I can run without a problem an adblocker, and I can run without a problem chrome headless, it is running *both* at the same time that gives me an error. – Tissuebox Apr 19 '19 at 20:16
  • Hi, I am also experiencing this problem. Chrome devs say it will take too much work to make headless work with extensions ... which seems untruthful considering firefox can do this. – Rhys Oct 19 '19 at 10:42
  • Yes, you can check out my answer here: https://stackoverflow.com/a/59793651/6903322 ---------- – john Jan 17 '20 at 19:21

1 Answers1

1

Running selenium in headless mode with extensions is currently not possible and as it seems, Google isn't planning on supporting that any time soon. You can find more information here

Rotem Vil
  • 224
  • 1
  • 8