puppeteer-extra: Stealth plugins not found when making .exe with pkg

// puppeteer-extra is a drop-in replacement for puppeteer,
// it augments the installed puppeteer with plugin functionality
const puppeteer = require("puppeteer-extra")
// register plugins through `.use()`
puppeteer.use(
  require("puppeteer-extra-plugin-anonymize-ua")({ makeWindows: true })
)
puppeteer.use(require("puppeteer-extra-plugin-stealth")())

// usage as normal
puppeteer.launch().then(async browser => {
  const page = await browser.newPage()
  await page.goto("https://httpbin.org/headers", {
    waitUntil: "domcontentloaded"
  })
  const content = await page.content()
  console.log("content:", content) // => (..) User-Agent: (..) Windows NT 10.0
  await browser.close()
})

When I use that piece of code it doesn’t work, giving me this error

C:\Users\Dan\Desktop\nodetests>node index

          A plugin listed 'puppeteer-extra-plugin-stealth/evasions/chrome.runtime' as dependency,
          which is currently missing. Please install it:

          yarn add puppeteer-extra-plugin-stealth

          Note: You don't need to require the plugin yourself,
          unless you want to modify it's default settings.

(node:38324) UnhandledPromiseRejectionWarning: TypeError: Class extends value #<Object> is not a constructor or null
    at Object.<anonymous> (C:\Users\Dan\node_modules\puppeteer-extra-plugin-stealth\evasions\chrome.runtime\index.js:10:22)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at PuppeteerExtra.resolvePluginDependencies (C:\Users\Dan\node_modules\puppeteer-extra\index.js:264:15)
    at PuppeteerExtra.launch (C:\Users\Dan\node_modules\puppeteer-extra\index.js:96:10)
(node:38324) 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:38324) [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.

When I remove puppeteer.use(require("puppeteer-extra-plugin-stealth")()) it works fine

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 25 (9 by maintainers)

Most upvoted comments

I got it working with the pkg. I included the whole stealth module in the package.json file:

"pkg": {
    "scripts": ["node_modules/puppeteer/lib/*.js", "node_modules/puppeteer-extra-plugin-stealth/**/*.js"]
  }

While compiling with pkg you will get bunch of warnings that ‘ava’ module not found. You can ignore them. That module is used in an example .js file which is included with the plugin. You won’t be needing that.

After giving up, a new requirement brought me again to this issue and I finally got it to work using @lockHrt 's suggestion THANKS A LOT… in my case I added node_modules/puppeteer-extra-plugin-stealth/**/*.js to the scripts array (I already had the other one)

I got it working with the pkg. I included the whole stealth module in the package.json file:

"pkg": {
    "scripts": ["node_modules/puppeteer/lib/*.js", "node_modules/puppeteer-extra-plugin-stealth/**/*.js"]
  }

While compiling with pkg you will get bunch of warnings that ‘ava’ module not found. You can ignore them. That module is used in an example .js file which is included with the plugin. You won’t be needing that.

@gantonioid

In the output dir, simply run npm install for both packages - it will create the node_modules within all dependencies of this package. This is ugly and defeats the purpose of having a .exec, but it’s my only working version atm.

@eduardoewgo I fixed it using nexe instead of pkg

Keep in mind that the example script you’re using is making use of two plugins that need to be installed.

So next to yarn add puppeteer puppeteer-extra you also need to run yarn add puppeteer-extra-plugin-stealth puppeteer-extra-plugin-anonymize-ua for the example script to work.

Maybe I should make that clearer in the readme.

@AsianPotato I just published puppeteer-extra-plugin-stealth@2.2.2 with a fix, everything should work now.

Rerunning yarn add puppeteer-extra-plugin-stealth in your project should be enough to fetch the new version.

Apologies for that bug, I rewrote parts in typescript just yesterday and for some mysterious reasons the CI tests didn’t complain about this issue. 😄

Thanks a lot for the quick reply!