berstend / puppeteer-extra

💯 Teach puppeteer new tricks through plugins.
https://extra.community
MIT License
6.23k stars 732 forks source link

[Bug] #836

Open teddis opened 9 months ago

teddis commented 9 months ago

I'm attempting to test puppeteer-extra with my NextJS/Typescript ^5.2.2 server and accompanying scraper. I'm using PyCharm IDE which has been fine for my Node projects. When I import the following, the IDE marks them with problems:

image

  1. I get TS2339: Property use does not exist on type in the first use of puppeteer.use(StealthPlugin()).
  2. I get TS2349: This expression is not callable on second use(AdblockerPlugin()) reference.

Suppressing these with // @ts-ignore covers over the IDE problem (red gone) and runtime appears to work. I'm still rather new to dealing with these kinds of problems, didn't expect this and not sure if there's a simple fix.

Versions

System: OS: macOS 13.5.1 CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz Memory: 940.78 MB / 32.00 GB Shell: 3.2.57 - /bin/bash

Binaries: Node: 18.17.0 - ~/.nvm/versions/node/v18.17.0/bin/node Yarn: 1.22.19 - ~/.nvm/versions/node/v18.17.0/bin/yarn npm: 9.6.7 - ~/.nvm/versions/node/v18.17.0/bin/npm

npmPackages: puppeteer-core: ^21.1.0 => 21.1.0 puppeteer-extra: ^3.3.6 => 3.3.6 puppeteer-extra-plugin-adblocker: ^2.13.6 => 2.13.6 puppeteer-extra-plugin-stealth: ^2.11.2 => 2.11.2

hdodov commented 7 months ago

Yep, I'm having the same. I used this workaround:

import _AdblockerPlugin from "puppeteer-extra-plugin-adblocker";
const AdblockerPlugin = _AdblockerPlugin.default;
puppeteer.use(AdblockerPlugin());

For what it's worth, I also bumped into #748.


package.json:

{
    "type": "module",
    "dependencies": {
        "puppeteer": "^21.5.1",
        "puppeteer-extra": "^3.3.6",
        "puppeteer-extra-plugin-adblocker": "^2.13.6",
        "typescript": "^5.2.2"
    },
    "volta": {
        "node": "18.17.0"
    }
}

tsconfig.json:

{
    "compilerOptions": {
        "strict": true,
        "target": "es6",
        "lib": ["es6", "DOM"],
        "module": "NodeNext",
        "moduleResolution": "NodeNext"
    }
}
hdodov commented 7 months ago

I just found out that if I remove "type": "module" from my package.json, I no longer experience the issue.