I'm testing Headless Chrome with Puppeteer, so I've reading docs and running this code*:
const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://www.github.com', {waitUntil: 'networkidle2'});
await page.screenshot({ path: 'screenshot.png' });
await browser.close();
})();
(*Snippet from Docs-Usage).
I changed "example.com" because works fine and trying with other sites, but with "github.com" script returns an timeout exception in the await page.goto() line:
(node:7840) UnhandledPromiseRejectionWarning: TimeoutError: Navigation Timeout Exceeded: 30000ms exceeded
at Promise.then (C:\_test\headless\node_modules\puppeteer\lib\LifecycleWatcher.js:142:21)
at <anonymous>
-- ASYNC --
at Frame.<anonymous> (C:\_test\headless\node_modules\puppeteer\lib\helper.js:111:15)
at Page.goto (C:\_test\headless\node_modules\puppeteer\lib\Page.js:629:49)
at Page.<anonymous> (C:\_test\headless\node_modules\puppeteer\lib\helper.js:112:23)
at C:\_test\headless\index.js:7:16
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:7840) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:7840) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
If I go to github.com with my regular browser, connects in normal timing, so my internet connection is not an issue.
I've added the next line and code runs fine after two minutes:
page.setDefaultNavigationTimeout(0);
But if I set puppeteer.launch({headless:false}) the code runs perfect in just a few seconds
I'm runing my test under:
- Windows 7 Professional SP1
- Node 8.11.1
- Puppeteer 1.18.0
- Puppeteer Core 1.18.0