SeleniumHQ/selenium · error · ArgumentError
incompatible proxy type #{type.inspect} (already set to #{@t
Error message
incompatible proxy type #{type.inspect} (already set to #{@type.inspect}) What it means
Raised by Selenium::WebDriver::Proxy#type= when a proxy attribute setter implicitly forces a proxy type that conflicts with the type already established by a previous setter. The Proxy object enforces a single proxyType across all attributes: :direct, :manual, :pac, :auto_detect, :system. Each attribute setter (http=, ssl=, socks=, socks_version=, etc.) calls self.type = :manual, while pac= sets :pac and auto_detect= sets :auto_detect. Once one type is set, mixing attributes from a different type family triggers this ArgumentError.
Source
Thrown at rb/lib/selenium/webdriver/common/proxy.rb:130
def socks_password=(value)
self.type = :manual
@socks_password = value
end
def socks_version=(value)
self.type = :manual
@socks_version = value
end
def type=(type)
unless TYPES.key? type
raise ArgumentError,
"invalid proxy type: #{type.inspect}, expected one of #{TYPES.keys.inspect}"
end
if defined?(@type) && type != @type
raise ArgumentError, "incompatible proxy type #{type.inspect} (already set to #{@type.inspect})"
end
@type = type
end
def as_json(*)
json_result = {
'proxyType' => TYPES[type].downcase,
'httpProxy' => http,
'noProxy' => no_proxy.is_a?(String) ? no_proxy.split(',').map(&:strip).reject(&:empty?) : no_proxy,
'proxyAutoconfigUrl' => pac,
'sslProxy' => ssl,
'autodetect' => auto_detect,
'socksProxy' => socks,
'socksUsername' => socks_username,
'socksPassword' => socks_password,
'socksVersion' => socks_version
}.compactView on GitHub (pinned to aa36b38e69)
Solutions
- Use only one proxy type family: either manual settings (http, ssl, socks, no_proxy, socks_username, socks_password, socks_version) OR pac URL OR auto_detect OR direct OR system.
- If switching proxy modes at runtime, create a new Proxy instance instead of reusing the same one.
- Inspect your options Hash before passing it to Proxy.new and remove keys belonging to a different type family.
- Set the type explicitly via proxy.type = :manual (or :pac) once, then only set attributes consistent with that type.
Example fix
// before proxy = Selenium::WebDriver::Proxy.new( pac: 'http://internal.corp/proxy.pac', http: 'proxy.corp:8080' # conflicts: forces :manual, but :pac already set ) // after proxy = Selenium::WebDriver::Proxy.new( pac: 'http://internal.corp/proxy.pac' ) # or, for manual: proxy = Selenium::WebDriver::Proxy.new( http: 'proxy.corp:8080', ssl: 'proxy.corp:8080' )
Defensive patterns
Strategy: validation
Validate before calling
# Validate proxy options before constructing Proxy
VALID_PROXY_KEYS = {
manual: %i[http no_proxy ssl socks socks_username socks_password socks_version],
pac: %i[pac],
auto_detect: %i[auto_detect]
}.freeze
def safe_proxy(opts)
detected_types = VALID_PROXY_KEYS.select { |_type, keys| (opts.keys & keys).any? }.keys
if detected_types.size > 1
raise ArgumentError, "Conflicting proxy types detected: #{detected_types}. Use only one type family."
end
Selenium::WebDriver::Proxy.new(opts)
end Try / catch
begin
proxy = Selenium::WebDriver::Proxy.new(proxy_opts)
rescue ArgumentError => e
raise if e.message !~ /incompatible proxy type/
# log and fall back to a single-type proxy
puts "Proxy config conflict: #{e.message}. Using manual proxy only."
proxy = Selenium::WebDriver::Proxy.new(http: proxy_opts[:http], ssl: proxy_opts[:ssl])
end Prevention
- Decide on a single proxy mode (manual, pac, auto_detect, system, direct) before building the options hash.
- Document the allowed key sets per proxy type in your config schema.
- Use a config validation layer (e.g., dry-validation, dry-schema) to catch conflicting keys before passing to Selenium.
When it happens
Trigger: Calling proxy.pac = 'http://...' (sets :pac) followed by proxy.http = 'host:8080' (sets :manual) raises this. Or passing a Hash to Proxy.new that includes both :pac and :http keys (each setter fires during initialize, so the second conflicting one fails). Setting socks_version= after pac= also conflicts (:manual vs :pac).
Common situations: Migrating from a manual proxy config to a PAC URL but leaving http/ssl keys in the options hash. Copying proxy examples from different blog posts that use different proxy modes. Building a Proxy from user-supplied config where the user mixes PAC and manual settings.
Related errors
- Can't set the server URL for #{self.class}; the service prov
- Cannot use both :http_client and :client_config
- unknown option#{'s' if not_allowed.size != 1}: #{not_allowed
- invalid proxy type: #{type.inspect}, expected one of #{TYPES
- cannot find element by #{how.inspect}
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/31ba2f801f18e0bd.
Report an issue: GitHub.