pythongoogle-chromeselenium-webdriverselenium-chromedriver

Loading unpacked Chrome extension with Selenium 4.34.2


I am trying to load an unpacked Chrome extension that is stored (as an unpacked folder) in the same folder where my script is running. This is the extension.

import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

unpacked_extension_path = 'Pano-fetch'

chrome_options = Options()
service = Service("/usr/bin/chromedriver")

chrome_options.add_argument('--load-extension={}'.format(unpacked_extension_path))
chrome_options.add_experimental_option("detach", True)

driver = webdriver.Chrome(service=service, options=chrome_options)

driver.get("https://www.google.com/maps")

time.sleep(10)

So far, the code opens Chrome, I click Accept Terms & Conditions and Google Maps is loaded. However, I can't see the extension in the upper bar, where it usually should be.

I am running Chrome version 138.0.7204.100 on Ubuntu 24.04


Solution

  • You have two separate issues blocking that extension from being loaded:

    1. The --load-extension option was disabled in Chrome 137, unless you add a special option to allow it: --disable-features=DisableLoadExtensionCommandLineSwitch.
    2. Chrome dropped support for Manifest V2 extensions during a Chrome 138 update.

    The first one is an easy fix: Add --disable-features=DisableLoadExtensionCommandLineSwitch.

    The second one requires you to use a Manifest V3 compatible Chrome extension. The extension from the link you had was last updated in 2018, which probably means it's still using the older Manifest V2 format, which is no longer supported by Chrome. You'll need to find a newer extension that supports V3. (Or you can download your Chrome version, which is what chrome-for-testing is useful for.)