3

I'm trying to set up puppeteer on my system. I've followed many different tutorials and guides but I keep encountering this problem. Chromium doesn't seem to open up correctly. The following is based on a sample test from one of the guides I've followed.

Error I get from chromium:

image of chromium

Error message on the CLI:

(node:17168) UnhandledPromiseRejectionWarning: Error: Page crashed!
    at Page._onTargetCrashed (C:\Users\dgros\Documents\Git\test\pup\node_modules\puppeteer\lib\Page.js:215:24)
    at CDPSession.Page.client.on.event (C:\Users\dgros\Documents\Git\test\pup\node_modules\puppeteer\lib\Page.js:123:56)
    at CDPSession.emit (events.js:198:13)
    at CDPSession._onMessage (C:\Users\dgros\Documents\Git\test\pup\node_modules\puppeteer\lib\Connection.js:200:12)
    at Connection._onMessage (C:\Users\dgros\Documents\Git\test\pup\node_modules\puppeteer\lib\Connection.js:112:17)
    at WebSocketTransport._ws.addEventListener.event (C:\Users\dgros\Documents\Git\test\pup\node_modules\puppeteer\lib\WebSocketTransport.js:44:24)
    at WebSocket.onMessage (C:\Users\dgros\Documents\Git\test\pup\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:198:13)
    at Receiver.receiverOnMessage (C:\Users\dgros\Documents\Git\test\pup\node_modules\ws\lib\websocket.js:789:20)
    at Receiver.emit (events.js:198:13)
(node:17168) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function wit
hout a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:17168) [DEP0018] DeprecationWarning: Unhandled promise 

The guide I followed comes from: https://www.youtube.com/watch?v=IvaJ5n5xFqU

I have installed version 10.16.0 of node.js and version 1.19.0 of puppeteer

I installed puppeteer with:

npm i puppeteer

Sample test which I ran from Git Bash with the command: "node index.js":

const puppeteer = require('puppeteer');

(async function main() {
    try {

        const browser = await puppeteer.launch({ headless: false, ignoreDefaultArgs: ['--disable-extensions'], devtools: true});
        const page = await browser.newPage();

        page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36')

        await page.goto('https://experts.shopify.com');

        await page.waitForNavigation();

        console.log('its showing');

    } catch (e) {
        console.log('our error', e);
    }
})();

The same error is produced with:

const puppeteer = require('puppeteer');

(async function main() {
    try {
        const browser = await puppeteer.launch({ headless: false, ignoreDefaultArgs: ['--disable-extensions'], devtools: true});
        const page = await browser.newPage();

    } catch (e) {
        console.log('our error', e);
    }
})();

When I omit the line with "browser.newPage()" the chromium "Aw, Snap!" error remains, but the UnhandledPromiseRejectionWarning error message goes away.

Expected: chromium opens, navigates to 'https://experts.shopify.com', waits for it to load, and then prints 'its showing' to the Git Bash CLI.

Actual: chromium opens with error and an error message outputs to the Git Bash CLI, nothing else happens.

Why is chromium opening with an error? How do I have the script run and act as expected?

Daniel Gros
  • 43
  • 1
  • 5
  • A few things. Did you install puppeteer the way it was done in in the video (the recommended way is to install using either `npm i puppeteer` or `yarn add puppeteer`)? Which version of Node are you using (`node -v`) and could you also set the `devtools` option to true when opening puppeteer? – Nick Clark Aug 23 '19 at 21:58
  • @NickClark I've edited the post and included the information. Setting the devtools option to true didn't change the behavior. – Daniel Gros Aug 23 '19 at 22:11
  • Review the error itself (_puppeteer protocol error (page.enable) target closed_), for instance: https://stackoverflow.com/a/51989560/451969 – Jared Farrish Aug 24 '19 at 13:50
  • @JaredFarrish the error occurs because I close the tab in the middle of the script because it shows an error. From what I understand, the error message above doesn't describe the error that I'm having with chromium, it's a result of me halting the script because it's not working. – Daniel Gros Aug 26 '19 at 17:54
  • @DanielGros, which version of puppeteer got installed? What's the error you see when chromium opens (as far as I can see you only added the error you get when you close chromium)? – mgarcia Aug 26 '19 at 21:14
  • @mgarcia sorry about that, not sure why I didn't include that. Perhaps the error message wasn't previously displayed, but now is for some reason. Not sure, regardless I've edited the post to include the error message and the version of puppeteer. (1.19.0 and an UnhandledPromiseRejectionWarning) – Daniel Gros Aug 26 '19 at 22:59

1 Answers1

0

It seems that your problem may be caused by an async orchestration problem (see issue and issue).

In order to solve this problem you can try using one of these two solutions:

Solution 1

await Promise.all([
    page.goto('https://experts.shopify.com'),
    page.waitForNavigation()
]);

Solution 2

const waitForNavigation = page.waitForNavigation();
await page.goto('https://experts.shopify.com');
await waitForNavigation;

Hope it helps!

mgarcia
  • 5,669
  • 3
  • 16
  • 35
  • 1
    Thanks for the response! The problem seems to be with "browser.newPage()" as commenting everything after that line still produces the same error. And commenting everything including "browser.newPage()" removes the error. I tried both solutions you recommended and neither seemed to change the behavior. – Daniel Gros Aug 27 '19 at 21:41
  • If the problem is with the `browser.newPage()` statement, maybe it is worth a try to delete the `node_modules` folder and install the project dependencies again, just in case something went wrong with the installation. – mgarcia Aug 28 '19 at 13:45
  • I've done that but it doesn't seem to work. I got it work within a vm. Went through the exact same setup process within the VM and it worked. Not sure what's wrong with my main system. So I'm just working with puppeteer from a vm. – Daniel Gros Aug 28 '19 at 20:07
  • I'm currently experiencing this problem on Ubuntu 22. The solution provided above didn't work for me. If anyone have found a better solution, I will really appreciate it. Thanks. – Martin Oputa Jan 26 '23 at 14:39