Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stealth plugins not found when making .exe with pkg #22

Closed
AsianPotato opened this issue Feb 12, 2019 · 25 comments
Closed

Stealth plugins not found when making .exe with pkg #22

AsianPotato opened this issue Feb 12, 2019 · 25 comments

Comments

@AsianPotato
Copy link

AsianPotato commented Feb 12, 2019

// 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

@berstend
Copy link
Owner

Whoops, I have an idea why that might be - I rewrote the base plugin in typescript and changed the exports to be named. Let me check!

@berstend
Copy link
Owner

@AsianPotato could you run yarn list puppeteer-extra-* real quick and paste the output here? thanks!

@berstend
Copy link
Owner

Nevermind I found the issue - fixing it now 😄

@AsianPotato
Copy link
Author

Thanks a lot for the quick reply!

@berstend
Copy link
Owner

@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. 😄

@berstend
Copy link
Owner

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.

@berstend
Copy link
Owner

@AsianPotato thanks a lot for the issue, I've improved the main example to be much clearer for the next person. :-)

@Dam998
Copy link

Dam998 commented Jun 2, 2020

Hi
I have this problem with puppeteer-extra-plugin-stealth version 2.4.9
If I execute my software in cli with npm start, all work fine but if I create an exe with pkg I will receive this error:

      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.

How can I fix this?

thank you @berstend

@eduardoewgo
Copy link

Getting the same issue as @Dam998...

"puppeteer": "^8.0.0",
"puppeteer-extra": "^3.1.16",
"puppeteer-extra-plugin-stealth": "^2.7.5"

@berstend
Copy link
Owner

@eduardoewgo could you check with the latest versions?

(at the time of writing):

 - puppeteer-extra-plugin-stealth@2.7.6
 - puppeteer-extra@3.1.18

@Dam998
Copy link

Dam998 commented Mar 31, 2021

@eduardoewgo I fixed it using nexe instead of pkg

@berstend berstend changed the title Stealth example not working Stealth plugins not found when making .exe with pkg Mar 31, 2021
@eduardoewgo
Copy link

@Dam998 kinda hard to move away from pkg at this point and I've tried nexe in the past; just can't remember what was the issue back then.. anyway, I'll try a bit more on this and last resource nexe.

@berstend I've installed the newest version and the error persists 😞

Just to give some context

This is the module loading up puppeteer.

const chromeExecutablePath = path.join(execPath, 'chromium/win64-856583/chrome-win/chrome.exe')
const puppeteer = require(`puppeteer-extra`)
const StealthPlugin = require(`puppeteer-extra-plugin-stealth`)

puppeteer.use(StealthPlugin())

This is the message I got

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

          yarn add puppeteer-extra-plugin-stealth

Any other suggestion, @berstend ?

@berstend
Copy link
Owner

berstend commented Mar 31, 2021

@eduardoewgo well, the issue is that their bundler trips over the dynamic imports: vercel/pkg#343

so what you might want to try is hardcoding the evasion imports somewhere in your code like this (to make the bundler aware of them):

require('puppeteer-extra-plugin-stealth/evasions/chrome.app')
// ...

@berstend
Copy link
Owner

There's also stuff like this you might want to look into:

"pkg": {
    "scripts": "node_modules/puppeteer/lib/*.js"
  }

(using that for the stealth evasions)

@eduardoewgo
Copy link

@berstend only solution was to manually install both puppeteer-extra-plugin-stealth and puppeteer-extra to the output dir 😞

It's the only packag that is not being properly compiled by pkg/nexe. Well, not sure how viable this is gonna be once this is finished, but it's the only way I could get a working .exe now.

@eduardoewgo
Copy link

btw, I am using typescript - shouldn't matter, but just in case.

@gantonioid
Copy link

@eduardoewgo what do you mean by

@berstend only solution was to manually install both puppeteer-extra-plugin-stealth and puppeteer-extra to the output dir 😞

@eduardoewgo
Copy link

@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.

@taytanqbpass
Copy link

@eduardoewgo I fixed it using nexe instead of pkg
i
Hi, im also encountering this issue in pkg, how do I workaround using nexe? thanks.

@Dam998
Copy link

Dam998 commented Apr 3, 2021

@eduardoewgo I fixed it using nexe instead of pkg
i
Hi, im also encountering this issue in pkg, how do I workaround using nexe? thanks.

Wdym?
just go to github page of nexe and follow their istruction to build an exe file : 3

@lockHrt
Copy link

lockHrt commented Jun 2, 2021

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.

@rabbit-yashow
Copy link

Did anybody get it working?

@TheJizel
Copy link

TheJizel commented Nov 8, 2021

@rabbit-yashow I updated my global pkg to the latest version (5.4.1) and am no longer having this issue.

@gantonioid
Copy link

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.

@yadegenn
Copy link

in which package package.json you write this json so that it would work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants