puppeteer-extra: [Bug] Example typescript code doesn't work - Argument of type '{ headless: boolean; }' is not assignable to parameter of type 'LaunchOptions'. Object literal may only specify known properties, and 'headless' does not exist in type 'LaunchOptions'.
I am successfully using puppeteer-extra in my typescript project. I wanted to set headless: false in my launch according to the sample code. I looked and something appears wrong with my types. I have stripped the problem down to a trivial sample project.
Sample Code
import puppeteer from 'puppeteer-extra';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
puppeteer.use(StealthPlugin());
(async (): Promise<void> => {
const browser = await puppeteer.launch({ headless: false });
await browser.close();
})();
Transpile Error
❯ tsc -p .
src/index.ts:7:46 - error TS2345: Argument of type '{ headless: boolean; }' is not assignable to parameter of type 'LaunchOptions'.
Object literal may only specify known properties, and 'headless' does not exist in type 'LaunchOptions'.
7 const browser = await puppeteer.launch({ headless: false });
~~~~~~~~~~~~~~~
Found 1 error.
Versions
❯ npx envinfo@latest --system --binaries --npmPackages '*(puppeteer*|playwright*|automation-extra*|@extra*)'
Need to install the following packages:
envinfo@latest
Ok to proceed? (y)
System:
OS: macOS 11.2
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 54.80 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 15.8.0 - /usr/local/bin/node
npm: 7.5.0 - /usr/local/bin/npm
npmPackages:
puppeteer-extra-plugin-stealth: ^2.7.4 => 2.7.4
Package.json
{
"name": "pex",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Andrew Janian <andrew@janian.net>",
"license": "ISC",
"dependencies": {
"puppeteer-extra-plugin-stealth": "^2.7.4"
}
}
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 27 (5 by maintainers)
I think I found a way to support typings for all puppeteer versions out of the box 😍
I don’t think this issue should be closed. I have both puppeteer and puppeteer-extra in my dependencies. I think this problem comes from missing types in puppeteer-extra launch function. My workaround is using
@ts-ignore
@ajanian your dependencies don’t list
puppeteer
orpuppeteer-extra
? 🤔In any case, please read this: https://github.com/berstend/puppeteer-extra/issues/428#issuecomment-778679665
This should now be fixed through #555:
It is happening to me too, and it does sound like a bug. I belive the problem is that puppeter-extra’s launch function receives the
options
asPuppeteer.LaunchOptions
, while puppeteer’s launch function options is typed asLaunchOptions & BrowserLaunchArgumentOptions & BrowserConnectOptions &
. Theheadless
property comes fromBrowserLaunchArgumentOptions
.