add extension with option headless selenium python

Question:

Hi i’d like to add the extension i don't care about cookies on selenium but i have this error :
selenium.common.exceptions.WebDriverException: Message: unknown error: failed to wait for extension background page to load: chrome-extension://fihnjjcciajhdojfnbdddfaoknhalnja/_generated_background_page.html

someone can help me?
Thanks

        self.service = Service(self.path)
        self.chrome_options = webdriver.ChromeOptions()
        self.chrome_options.add_extension("tools/I-don-t-care-about-cookies.crx")
        self.chrome_options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
        self.chrome_options.add_argument('--headless')
        self.chrome_options.add_argument('--disable-gpu')
        self.chrome_options.add_argument('--no-sandbox')
        self.driver = webdriver.Chrome(service=self.service,options=self.chrome_options)```
Asked By: Luca ZH

||

Answers:

First, install the extension in your Chrome browser, and check if it works. Then chek the correct extension location. Then you can install it when launching the chromedriver like so:

chrome_options = Options()
[...]
chrome_options.add_argument('--load-extension=/home/user/.config/chromium/Default/Extensions/cjpalhdlnbpafiamejdnhcphjbkeiagm/1.43.0_0')

Selenium documentation can be found at https://www.selenium.dev/documentation/

Answered By: platipus_on_fire