question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[🐛 Bug]: "Error: Invalid URL: http:/" with Node.js v18

See original GitHub issue

What happened?

Using selenium-webdriver with Node.js v18 is not possible, as an error is thrown.

Error: Invalid URL: http:/
    at getRequestOptions (/Users/werner/Desktop/selenium-node-test/node_modules/selenium-webdriver/http/index.js:51:11)

To reproduce, install Node.js v18 or higher (e.g. via nvm install node).

Given the following package.json:

{
  "dependencies": {
    "selenium-webdriver": "^4.1.2"
  }
}

Run the sample code in index.js with node index.js:

const { Builder, By, Key, until } = require("selenium-webdriver");
(async function example() {
  let driver = await new Builder().forBrowser("chrome").build();
  try {
    await driver.get("http://www.google.com/ncr");
    await driver.findElement(By.name("q")).sendKeys("webdriver", Key.RETURN);
    await driver.wait(until.titleIs("webdriver - Google Search"), 1000);
  } finally {
    await driver.quit();
  }
})();

With Node.js v18, I get:

➜ node index.js  
/Users/werner/Desktop/selenium-node-test/node_modules/selenium-webdriver/http/index.js:51
    throw new Error('Invalid URL: ' + aUrl)
          ^

Error: Invalid URL: http:/
    at getRequestOptions (/Users/werner/Desktop/selenium-node-test/node_modules/selenium-webdriver/http/index.js:51:11)
    at new HttpClient (/Users/werner/Desktop/selenium-node-test/node_modules/selenium-webdriver/http/index.js:90:21)
    at getStatus (/Users/werner/Desktop/selenium-node-test/node_modules/selenium-webdriver/http/util.js:38:18)
    at checkServerStatus (/Users/werner/Desktop/selenium-node-test/node_modules/selenium-webdriver/http/util.js:76:14)
    at /Users/werner/Desktop/selenium-node-test/node_modules/selenium-webdriver/http/util.js:74:5
    at new Promise (<anonymous>)
    at Object.waitForServer (/Users/werner/Desktop/selenium-node-test/node_modules/selenium-webdriver/http/util.js:57:10)
    at /Users/werner/Desktop/selenium-node-test/node_modules/selenium-webdriver/remote/index.js:251:24
    at new Promise (<anonymous>)
    at /Users/werner/Desktop/selenium-node-test/node_modules/selenium-webdriver/remote/index.js:246:20

Node.js v18.1.0

With Node.js v16 (the current LTS release), it works fine. It should be noted though that with v18, the variables for the .format call are:

serverUrl: http:/, hostname: undefined, port: 52511, self.path_: /

Whereas for v16, the variables are:

serverUrl: http://127.0.0.1:52535/, hostname: 127.0.0.1, port: 52535, self.path_: /

Notably, the hostname is undefined in Node.js v18. This leads me to the function os.networkInterfaces() whose output is different in v18 compared to v16.

Here is v16:

> os.networkInterfaces()
{
  lo0: [
    {
      address: '127.0.0.1',
      netmask: '255.0.0.0',
      family: 'IPv4',
      mac: '00:00:00:00:00:00',
      internal: true,
      cidr: '127.0.0.1/8'
    }
   ...

And here is v18:

> os.networkInterfaces()
{
  lo0: [
    {
      address: '127.0.0.1',
      netmask: '255.0.0.0',
      family: 4,
      mac: '00:00:00:00:00:00',
      internal: true,
      cidr: '127.0.0.1/8'
    },
    ...

See that the family property now reads 4 and not IPv4.

How can we reproduce the issue?

Shown above.

Relevant log output

Log already shown in reproducible example above.

Operating System

Any

Selenium version

4.1.2

What are the browser(s) and version(s) where you see this issue?

Irrelevant

What are the browser driver(s) and version(s) where you see this issue?

Irrelevant

Are you using Selenium Grid?

No

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
titusfortnercommented, May 20, 2022

Hoping to have one next week, but no promises, it’ll happen when we can make it happen.

1reaction
simonkurtz-MSFTcommented, May 27, 2022

I am now successfully running my tests with Node 18.2 with 4.2.0. Very awesome, @titusfortner! Thank you very much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Errors | Node.js v19.2.0 Documentation
Unless an application is dynamically generating and running code, ReferenceError instances indicate a bug in the code or its dependencies. Class: SyntaxError #....
Read more >
Node.js Client TypeError [ERR_INVALID_URL]: Invalid URL
Hello, I am trying to deploy a 1Password Connect Server via Docker as per your instructions but, I am getting the following error...
Read more >
Error with my server file - Invalid URL: index.js - Stack Overflow
You're running your code in Node.js. It doesn't run inside a document. There is no base URL. You need to provide an absolute...
Read more >
Error handling in Node.js - LogRocket Blog
Deliver reliable software by learning how to handle errors in Node.js using callbacks, promises, and event emitters.
Read more >
How to resolve NPM proxy issue whilel running node JS ...
is a problem related to network connectivity. npm ERR! network In most cases you are behind a proxy or have bad network settings....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found