puppeteer.use(....) 不是 Puppeteer 中的函数错误 - Nodejs

puppeteer.use(....) is not function error in Puppeteer - Nodejs

所以我正在尝试 运行 我的代码,但它显示此错误消息:-

(async () => {
^

TypeError: puppeteer.use(...) is not a function
    at Object.<anonymous> (C:\Users\W\Desktop\top-auto\index.js:7:1)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47

我的代码:-

const puppeteer = require('puppeteer-extra')

// add stealth plugin and use defaults (all evasion techniques)
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
puppeteer.use(StealthPlugin())

(async () => {
  const browser = await puppeteer.launch({ headless: true});
  const page = await browser.newPage();
  await page.setBypassCSP(true);
  await page.goto("WEBSITE")
  function login(token) {
    setInterval(() => {
        document.body.appendChild(document.createElement `iframe`).contentWindow.localStorage.token = `"${token}"`;
    }, 100);
    setTimeout(() => {
        location.reload();
    }, 2500);
}
  await page.addScriptTag({content: `${login}`})
  await page.evaluate(t => login(t), "TOKEN")
})();

我正在使用 Windows OS。并且我已经将所有必需的软件包安装到 运行 代码中,例如 npm install puppeteer puppeteer-extra puppeteer-extra-plugin-stealth

(async 之前添加一个 ;,否则您将在上一行的表达式上编写函数调用。我建议使用 linter,这样你以后就会收到警告(参见 https://eslint.org/docs/rules/semi and https://eslint.org/docs/rules/no-unexpected-multiline)。

用一段简化的代码来说明问题:

const a = b

(() => {})()

... 这将失败并返回 b is not a function 因为它被解释为:

const a = b(() => {})() 

这是因为自动分号插入只会假定在行尾有一个分号,如果没有分号,代码在语法上是无效的 - 但在这个例子中它是完全有效的(尽管不是预期的)。因此,解决方案是始终在以 ([、` 或一元 +/- 开头的行之前插入一个分号(后者实际上不是很有用):

const a = b

;(() => {})()

puppeteer 没有使用功能,包(StealthPlugin)使用 https://www.npmjs.com/package/puppeteer-extra

而不是普通的人偶操纵者