简体   繁体   中英

Node JS Puppeteer headful Browser doesnt launch

I'm playing around with puppeteer to learn a bit about automation in the browser. I wanted to open the chromium browser visable so not in headless. I set the launch option to false , but it's still not opening Chromium.

I tried to use no sandbox args, i did even deflag the --disable-extensions in the args, but nothing helped..

There are no errors in the terminal, it just doesn't launch.

Here is my code:

const puppeteer = require ("puppeteer");

async () => {
  const browser = await puppeteer.launch({ headless: false });
  const page = browser.newPage();
  await page.goto("https://google.de");

  await browser.close();
};

Any idea why chromium is not opening? Also there are no logs about errors...

Problem

You are not calling the function, you are just defining it via async () => {... } . This is why you are not getting any errors, as the function is not executed. In addition, as the other answer already said, you are missing an await .

Solution

Your code should look like this:

(async () => {
  const browser = await puppeteer.launch({ headless: false });
  const page = await browser.newPage(); // missing await
  await page.goto("https://google.de");

  await browser.close();
})(); // Here, we actually call the function

newPage() returns a promise so you should await it

const puppeteer = require ("puppeteer");

async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto("https://google.de");

await browser.close();
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM