Puppeteer-extra: TypeError: Cannot convert undefined or null to object

Created on 10 Jun 2020  路  5Comments  路  Source: berstend/puppeteer-extra

When I write const browser = await puppeteer.launch(); it appears that puppeteer is undefined or null, because it returns the error in the title. I think this because after commenting out the rest of my code (in my async function) even when logging to the console it returns the error. Here is the config:

const puppeteer = require('puppeteer-extra');

const StealthPlugin = require('puppeteer-extra-plugin-stealth');
puppeteer.use(StealthPlugin());

Anyone know what's happening?

Most helpful comment

Had the same issue and solved it by changing this line:

const browser = await puppeteer.launch()

To this:

const browser = await puppeteer.launch({})

As ref for the devs to see the source of the issue:

async launch(options) {
// Ensure there are certain properties (e.g. the `options.args` array)
  const defaultLaunchOptions = { args: [] };
  options = merge(defaultLaunchOptions, options);  // THIS LINE IS THE ISSUE

All 5 comments

I am also facing this issue.
NodeJs version: 13.11.0

Puppeteer versions:

"puppeteer": "^3.1.0",
"puppeteer-extra": "^3.1.9",
"puppeteer-extra-plugin-user-preferences": "^2.2.4"

Had the same issue and solved it by changing this line:

const browser = await puppeteer.launch()

To this:

const browser = await puppeteer.launch({})

As ref for the devs to see the source of the issue:

async launch(options) {
// Ensure there are certain properties (e.g. the `options.args` array)
  const defaultLaunchOptions = { args: [] };
  options = merge(defaultLaunchOptions, options);  // THIS LINE IS THE ISSUE

any updates on this one?

Had the same issue and solved it by changing this line:

const browser = await puppeteer.launch()

To this:

const browser = await puppeteer.launch({})

As ref for the devs to see the source of the issue:

async launch(options) {
// Ensure there are certain properties (e.g. the `options.args` array)
  const defaultLaunchOptions = { args: [] };
  options = merge(defaultLaunchOptions, options);  // THIS LINE IS THE ISSUE

Thanks for response! When I do that, I get a more complicated error:

(node:1772) UnhandledPromiseRejectionWarning: TypeError: browser.setMaxListeners is not a function
    at StealthPlugin.onBrowser (c:\Users\akash\Coding\project\node_modules\puppeteer-extra-plugin-stealth\index.js:155:13)
    at StealthPlugin._bindBrowserEvents (c:\Users\akash\Coding\project\node_modules\puppeteer-extra-plugin\dist\index.cjs.js:479:24)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async PuppeteerExtra.callPlugins (c:\Users\akash\Coding\project\node_modules\puppeteer-extra\dist\index.cjs.js:376:13)
    at async PuppeteerExtra.launch (c:\Users\akash\Coding\project\node_modules\puppeteer-extra\dist\index.cjs.js:131:9)
    at async scrapeNum (c:\Users\akash\Coding\project\scrape.js:7:21)
(node:1772) 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: 2)
(node:1772) [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.

I actually had to add a valid config setting to get this to work:

const browser = await puppeteer.launch(
{
defaultViewport: {
width: 1020,
height: 1020,
deviceScaleFactor: 1
}
}
);

Using:

"puppeteer": "^5.2.1",
"puppeteer-extra": "^3.1.13",
"puppeteer-extra-plugin-angular": "^3.2.3",
Was this page helpful?
0 / 5 - 0 ratings

Related issues

brooklyn097 picture brooklyn097  路  10Comments

methyl picture methyl  路  8Comments

svenadlung picture svenadlung  路  8Comments

qo4on picture qo4on  路  8Comments

AdityaAnand1 picture AdityaAnand1  路  9Comments