SeleniumHQ/selenium · error · Error::WebDriverError
could not find extension at #{path.inspect}
Error message
could not find extension at #{path.inspect} What it means
Chromium Options#add_extension validates the path before queuing it for Base64 encoding on session creation. It raises Error::WebDriverError if no regular file exists at the given path (File.file? is false). A separate check then requires the .crx extension. Only real .crx files are accepted.
Source
Thrown at rb/lib/selenium/webdriver/chromium/options.rb:253
options['args'] ||= []
options['args'] << "--user-data-dir=#{@profile.directory}"
end
return if (@encoded_extensions + @extensions).empty?
options['extensions'] = @encoded_extensions + @extensions.map { |ext| encode_extension(ext) }
end
def binary_path
Chrome.path
end
def encode_extension(path)
File.open(path, 'rb') { |crx_file| Base64.strict_encode64 crx_file.read }
end
def validate_extension(path)
raise Error::WebDriverError, "could not find extension at #{path.inspect}" unless File.file?(path)
raise Error::WebDriverError, "file was not an extension #{path.inspect}" unless File.extname(path) == '.crx'
@extensions << path
end
def camelize?(key)
!%w[localState prefs].include?(key)
end
end # Options
end # Chromium
end # WebDriver
end # Selenium
View on GitHub (pinned to aa36b38e69)
Solutions
- Use an absolute path to the .crx file: options.add_extension(File.expand_path('ext.crx', __dir__)).
- Verify File.file?(path) before calling, and that the extension is .crx.
- Ensure the .crx is packaged with your app/gem and deployed to the runtime environment.
- Prefer add_encoded_extension with a pre-encoded Base64 string if the file location varies.
Example fix
// before
options.add_extension('vendor/ext.crx')
// after
options.add_extension(File.expand_path('vendor/ext.crx', __dir__)) Defensive patterns
Strategy: validation
Validate before calling
def crx_file?(path) File.file?(path) && File.extname(path) == '.crx' end raise 'not a .crx file' unless crx_file?(path) options.add_extension(path)
Type guard
def valid_extension_path?(path)
File.file?(path) && File.extname(path).casecmp?('.crx')
end Try / catch
begin
options.add_extension(path)
rescue Selenium::WebDriver::Error::WebDriverError => e
raise unless e.message =~ /could not find extension/
options.add_extension(File.expand_path('ext.crx', __dir__))
end Prevention
- Always use absolute paths for extension files.
- Bundle the .crx with your gem/app and verify it exists at runtime.
- Prefer add_encoded_extension when the file location is unstable.
When it happens
Trigger: Calling options.add_extension('/path/to/ext') where the path does not exist, points to a directory, or is otherwise not a regular file.
Common situations: Relative path resolved against the wrong working directory, packaging the gem without bundling the .crx, typo in the path, file deleted between runs, CI running from a different cwd than local.
Related errors
- Path to the extension doesn't exist
- could not find extension at #{path.inspect}
- argument can not be null
- Binary Location Must be a String
- :options must be an instance of #{default_options.class}
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/6ca0199af7cde25d.
Report an issue: GitHub.