SeleniumHQ/selenium · error · Error

Invalid URL: ${aUrl}

Error message

Invalid URL: ${aUrl}

What it means

Thrown by getRequestOptions() in http/index.js when url.parse(aUrl) yields no hostname. The HttpClient constructor calls this to validate the server URL. Any URL lacking a host (relative path, empty string, missing scheme) fails this check.

Source

Thrown at javascript/selenium-webdriver/http/index.js:51

 *            auth: (?string|undefined),
 *            hostname: (?string|undefined),
 *            host: (?string|undefined),
 *            port: (?string|undefined),
 *            path: (?string|undefined),
 *            pathname: (?string|undefined)}}
 */
let RequestOptions // eslint-disable-line

/**
 * @param {string} aUrl The request URL to parse.
 * @return {RequestOptions} The request options.
 * @throws {Error} if the URL does not include a hostname.
 */
function getRequestOptions(aUrl) {
  // eslint-disable-next-line n/no-deprecated-api
  let options = url.parse(aUrl)
  if (!options.hostname) {
    throw new Error('Invalid URL: ' + aUrl)
  }
  // Delete the search and has portions as they are not used.
  options.search = null
  options.hash = null
  options.path = options.pathname
  options.hostname = options.hostname === 'localhost' ? '127.0.0.1' : options.hostname // To support Node 17 and above. Refer https://github.com/nodejs/node/issues/40702 for details.
  return options
}

/** @const {string} */
const USER_AGENT = (function () {
  const version = require('../package.json').version
  const platform = { darwin: 'mac', win32: 'windows' }[process.platform] || 'linux'
  return `selenium/${version} (js ${platform})`
})()

/**
 * A basic HTTP client used to send messages to a remote end.

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Include the scheme and host: 'http://localhost:4444'.
  2. Verify the SELENIUM_REMOTE_URL environment variable value.
  3. Validate the URL with new URL(urlString) before passing it.
  4. Ensure Builder.usingServer() receives a fully-qualified URL.

Example fix

// before
new Builder().usingServer('localhost:4444').build()
// after
new Builder().usingServer('http://localhost:4444').build()
Defensive patterns

Strategy: validation

Validate before calling

function assertValidServerUrl(urlString) {
  let parsed
  try {
    parsed = new URL(urlString)
  } catch {
    throw new Error(`Invalid server URL (unparseable): ${urlString}`)
  }
  if (!parsed.hostname) {
    throw new Error(`Invalid server URL (no hostname): ${urlString}`)
  }
  return urlString
}

Prevention

When it happens

Trigger: Passing 'localhost:4444' without the http:// scheme to new HttpClient() or Builder.usingServer(). SELENIUM_REMOTE_URL set to a malformed value. Passing an empty string, a bare path, or undefined coerced to string.

Common situations: Forgetting the http:// or https:// scheme; reading a server URL from config that omits the scheme; SELENIUM_REMOTE_URL typo; passing a Grid URL constructed by string concatenation that drops the scheme.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/f9b4778110cfbb9a. Report an issue: GitHub.