const puppeteer = require('puppeteer');
const browser = await puppeteer.launch();
const page = await browser.newPage();
This one works
await page.goto('https://example.com');
This doesn't work (without the protocol i.e http/https)
await page.goto("www.example.com');
It throws error
Protocol error (Page.navigate): Cannot navigate to invalid URL
Why doesn't it append the protocol like it does when we open in Google Chrome?
(However, it is possible to force Puppeteer to use a separately-installed version Chrome instead of Chromium via the executablePath option to puppeteer. launch .
Puppeteer is a Node.js library which provides a high-level API to control Chrome/Chromium over the DevTools Protocol. Puppeteer runs in headless mode by default, but can be configured to run in full (non-headless) Chrome/Chromium.
Puppeteer is a Node library which provides a high-level API to control headless Chrome or Chromium over the DevTools Protocol. It can also be configured to use full (non-headless) Chrome or Chromium.
Puppeteer lets you automate the testing of your web applications. With it, you can run tests in the browser and then see the results in real-time on your terminal. Puppeteer uses the WebDriver protocol to connect with the browser and simulate user interaction with HTML elements or pages.
The Google Chrome Omnibox (Address Bar) has built in functionality to handle multiple complexities, such as: appending protocols, autocomplete, etc.
Puppeteer provides an API to control Chrome or Chromium over the DevTools Protocol, so much of this functionality is currently out of the scope of Puppeteer.
The Puppeteer documentation for the function page.goto()
explicitly states:
The url should include scheme, e.g.
https://
.
This is because page.goto()
utilizes Page.navigate
from the Chrome DevTools Protocol.
The Chromium source code shows that navigation via Page.navigate
is explicitly checked for validity, and if the URL is not valid, it will return the error, "Cannot navigate to invalid URL."
You can easily create a function in Node.js that will append protocols to URLs, and that could be a workaround for your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With