puppeteer-extra: [Bug] Using puppeteer-extra-plugin-stealth doesn't compile when using React and Electron

Describe the bug I get an error when I include puppeteer-extra-plugin-stealth in the build I’m using the following boilerplate and none of the workarounds reported so far solve the problem https://github.com/sprout2000/electron-react-ts

ERROR in ./node_modules/merge-deep/node_modules/clone-deep/utils.js 11:0-38
Cannot statically analyse 'require(…, …)' in line 11
 @ ./node_modules/merge-deep/node_modules/clone-deep/index.js 7:12-30
 @ ./node_modules/merge-deep/index.js 11:12-33
 @ ./node_modules/puppeteer-extra-plugin/dist/index.esm.js 9:14-35
 @ ./node_modules/puppeteer-extra-plugin-stealth/index.js 3:33-66
 @ ./src/main.ts 5:0-53 36:13-20

ERROR in ./node_modules/merge-deep/node_modules/clone-deep/utils.js 12:0-33
Cannot statically analyse 'require(…, …)' in line 12
 @ ./node_modules/merge-deep/node_modules/clone-deep/index.js 7:12-30
 @ ./node_modules/merge-deep/index.js 11:12-33
 @ ./node_modules/puppeteer-extra-plugin/dist/index.esm.js 9:14-35
 @ ./node_modules/puppeteer-extra-plugin-stealth/index.js 3:33-66
 @ ./src/main.ts 5:0-53 36:13-20

ERROR in ./node_modules/merge-deep/node_modules/clone-deep/utils.js 13:0-28
Cannot statically analyse 'require(…, …)' in line 13
 @ ./node_modules/merge-deep/node_modules/clone-deep/index.js 7:12-30
 @ ./node_modules/merge-deep/index.js 11:12-33
 @ ./node_modules/puppeteer-extra-plugin/dist/index.esm.js 9:14-35
 @ ./node_modules/puppeteer-extra-plugin-stealth/index.js 3:33-66
 @ ./src/main.ts 5:0-53 36:13-20
<

Code Snippet


import puppeteer from 'puppeteer-extra';
import Stealth from 'puppeteer-extra-plugin-stealth';
  puppeteer
    .use(Stealth())
    .launch({
      headless: false,
      defaultViewport: null,
      executablePath:
        'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
    })
    .then(async (browser) => {
      const page = await browser.newPage();
      await page.goto('https://bot.sannysoft.com');
      await page.waitForTimeout(5000);
      await browser.close();
    });

Versions “puppeteer”: “^12.0.1”, “puppeteer-extra”: “^3.2.3”, “puppeteer-extra-plugin-stealth”: “^2.9.0”, “react”: “^17.0.2”, “electron”: “^16.0.4”, “electron-builder”: “^22.14.5”, “webpack”: “^5.64.4”,

Note The following workarounds did not work https://github.com/berstend/puppeteer-extra/issues/93#issuecomment-712364816 There seems to be a solution for vue, but not for react, so I’m having a hard time.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18

Most upvoted comments

Same here, Next.js 13

fwiw, i have a Next.js 13 app and stuck on this issue. I was able to solve it by using the old /pages/ approach as a workaround, but would love to get this addressed

I found this, and it seems to work for me, add this to the next.config.js:

experimental: { serverComponentsExternalPackages: [ “puppeteer-extra”, “puppeteer-extra-plugin-stealth”, “puppeteer-extra-plugin-recaptcha”, ], },

This lead into an additional issue, but its related to bundling the evasions not NextJS

Finally, I recreated the webpack myself and it worked

Specifically, I added some things related to puppeteer to the external options of webpack.config.js At the same time, I added webpack-node-externals Perhaps one of them alone will work

const nodeExternals = require('webpack-node-externals');

externals: [nodeExternals()]

Do this. Works on build.

/** @type {import('next').NextConfig} */
const nextConfig = {
  // Works, but need to replace with serverExternalPackages later
  webpack: (
    config,
    { buildId, dev, isServer, defaultLoaders, nextRuntime, webpack },
  ) => {
    // add externals
    config.externals = config.externals || [];
    config.externals.push(
      "puppeteer-extra",
      "puppeteer-extra-plugin-stealth",
      "puppeteer-extra-plugin-adblocker",
      "puppeteer-extra-plugin-block-resources",
      "turndown",
    );

    return config;
  },
  // Suppose to work but does not.
  // serverExternalPackages: [
  //   "puppeteer-extra",
  //   "puppeteer-extra-plugin-stealth",
  //   "puppeteer-extra-plugin-adblocker",
  //   "puppeteer-extra-plugin-block-resources",
  //   "turndown",
  // ],

I was using next js and adding the puppeteer extra and stealth plugin as external packages solved it for me. Here’s the modified next.config.js

/** @type {import('next').NextConfig} */
const nextConfig = {
  experimental: {
    serverComponentsExternalPackages: [
      'puppeteer',
      'puppeteer-extra',
      'puppeteer-extra-plugin-stealth',
    ],
    serverMinification: false, // required by DEFER platform
  },
};

module.exports = nextConfig;