{"record":{"id":"dffc1f9594c35200","repo":"SeleniumHQ/selenium","slug":"path-to-the-extension-doesn-t-exist","errorCode":null,"errorMessage":"Path to the extension doesn't exist","messagePattern":"Path to the extension doesn't exist","errorType":"validation","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/chromium/options.py","lineNumber":99,"sourceCode":"        encoded_extensions = []\n        for extension in self._extension_files:\n            with open(extension, \"rb\") as f:\n                encoded_extensions.append(_decode(f))\n\n        return encoded_extensions + self._extensions\n\n    def add_extension(self, extension: str) -> None:\n        \"\"\"Add the path to an extension to be extracted to ChromeDriver.\n\n        Args:\n            extension: Path to the *.crx file.\n        \"\"\"\n        if extension:\n            extension_to_add = os.path.abspath(os.path.expanduser(extension))\n            if os.path.exists(extension_to_add):\n                self._extension_files.append(extension_to_add)\n            else:\n                raise OSError(\"Path to the extension doesn't exist\")\n        else:\n            raise ValueError(\"argument can not be null\")\n\n    def add_encoded_extension(self, extension: str) -> None:\n        \"\"\"Add Base64-encoded string with extension data to be extracted to ChromeDriver.\n\n        Args:\n            extension: Base64 encoded string with extension data.\n        \"\"\"\n        if extension:\n            self._extensions.append(extension)\n        else:\n            raise ValueError(\"argument can not be null\")\n\n    @property\n    def experimental_options(self) -> dict:\n        \"\"\"Returns a dictionary of experimental options for chromium.\"\"\"\n        return self._experimental_options","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/chromium/options.py#L81-L117","documentation":"`add_extension` checks that the given path resolves to an existing file on disk (after `abspath`/`expanduser` expansion) before queuing it as a `.crx` extension to load. If the file does not exist it raises `OSError`. This guards chromedriver from receiving a missing-file path.","triggerScenarios":"`options.add_extension(\"/wrong/path/ext.crx\")`, `options.add_extension(\"~/notthere.crx\")`, relative paths that resolve outside the CWD, or a path to a directory instead of a `.crx` file.","commonSituations":"Bundling extensions in a CI artifact whose path changed. Relative paths breaking when the script runs from a different working directory. Typos in the path. Downloading a `.crx` that failed.","solutions":["Verify the path exists: `if not os.path.exists(path): raise ...` before calling.","Use an absolute path resolved against the script location: `pathlib.Path(__file__).parent / \"ext.crx\"`.","If you only have the encoded extension data, use `add_encoded_extension` instead.","Check `os.path.isfile(path)` (not just exists) to also catch directory paths."],"exampleFix":"// before\noptions.add_extension(\"ext.crx\")  # fails if CWD differs\n// after\nimport pathlib\next = pathlib.Path(__file__).parent / \"ext.crx\"\noptions.add_extension(str(ext))","handlingStrategy":"validation","validationCode":"import os\next = \"ext.crx\"\nif not os.path.isfile(os.path.abspath(os.path.expanduser(ext))):\n    raise FileNotFoundError(ext)\noptions.add_extension(ext)","typeGuard":"import os\ndef is_existing_extension_file(path: str) -> bool:\n    return bool(path) and os.path.isfile(os.path.abspath(os.path.expanduser(path)))","tryCatchPattern":"try:\n    options.add_extension(ext_path)\nexcept OSError:\n    # log and either locate the file or use add_encoded_extension\n    ...","preventionTips":["Anchor extension paths to the script directory with pathlib.","Prefer add_encoded_extension when shipping the payload in code.","Use os.path.isfile (not just exists) to reject directories."],"tags":["options","extension","filesystem","chromium"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}