#How do I use npm's puppeteer with new npm syntax (also Steatlh plugin)
79 messages · Page 1 of 1 (latest)
I'm supposed to install puppeteer alongside puppeteer extra, but how do I install npm modules with deno?
Error: Could not find expected browser (chrome) locally. Run `npm install` to download the correct Chromium revision (1022525).
at ChromeLauncher.launch (file:///home/ubuntu/.cache/deno/npm/registry.npmjs.org/puppeteer/16.2.0/lib/cjs/puppeteer/node/ChromeLauncher.js:70:23)
at PuppeteerNode.launch (file:///home/ubuntu/.cache/deno/npm/registry.npmjs.org/puppeteer/16.2.0/lib/cjs/puppeteer/node/Puppeteer.js:145:31)
at PuppeteerExtra.launch (file:///home/ubuntu/.cache/deno/npm/registry.npmjs.org/puppeteer-extra/3.3.4/dist/index.cjs.js:128:41)
at async file:///home/ubuntu/www/briskreader.com/app/app.ts:298:22
at async dispatch (https://deno.land/x/oak@v11.1.0/middleware.ts:41:7)
at async dispatch (https://deno.land/x/oak@v11.1.0/middleware.ts:41:7)
at async dispatch (https://deno.land/x/oak@v11.1.0/middleware.ts:41:7)
at async dispatch (https://deno.land/x/oak@v11.1.0/middleware.ts:41:7)
at async file:///home/ubuntu/www/briskreader.com/app/app.ts:526:2
I believe deno doesn't run post-install hooks by design (that decision may have changed)
In puppeteer's case that hook downloads an arch/os specific binary
The deno version of puppeteer works fine but the stealth plug-in doesn’t work on deno
const browser = await puppeteer.launch({executablePath: '/path/to/Chrome'});
You can explicitly provide a path to your own chrome binary
Yeah I have chromium for that
It’s the stealth plug-in which I need
I tried esm.sh but that didn’t work
The stacktrace your shared above doesn't fail on the stealth plugin
It gripes about a kind-of plug-in not able to load
If someone can get stealth plug-in running with deno that would be appreciated
And share how
Could you share the stacktrace/error-message you're seeing ?
(the one you shared above appears unrelated to the stealth plugin you're talking about)
error: Uncaught Error: Dynamic require of "kind-of" is not supported
at https://cdn.esm.sh/v55/clone-deep@0.2.4/es2021/clone-deep.js:2:583
at Function.o [as typeOf] (https://cdn.esm.sh/v55/lazy-cache@1.0.4/es2021/lazy-cache.js:2:968)
at s (https://cdn.esm.sh/v55/clone-deep@0.2.4/es2021/clone-deep.js:2:1251)
at m.exports (https://cdn.esm.sh/v55/merge-deep@3.0.3/es2021/merge-deep.js:2:1229)
at new h (https://cdn.esm.sh/v55/puppeteer-extra-plugin@3.2.0/es2021/puppeteer-extra-plugin.js:2:635)
at new r (https://cdn.esm.sh/v55/puppeteer-extra-plugin-stealth@2.9.0/es2021/puppeteer-extra-plugin-stealth.js:2:1115)
at w (https://cdn.esm.sh/v55/puppeteer-extra-plugin-stealth@2.9.0/es2021/puppeteer-extra-plugin-stealth.js:2:1893)
at file:///home/ettinger/www/briskreader.com/app/app.ts:32:15
I'm loading with import StealthPlugin from "https://cdn.esm.sh/v55/puppeteer-extra-plugin-stealth@2.9.0/es2021/puppeteer-extra-plugin-stealth.js";
With npm:... instead of esm ?
if i do that it requires i use puppeteer-extra and puppeteer
It depends on them anyway, no ?
npm install puppeteer puppeteer-extra puppeteer-extra-plugin-stealth
Or just use npm:... imports
if i do that i get this:
import puppeteer from 'npm:puppeteer-extra';
import StealthPlugin from 'npm:puppeteer-extra-plugin-stealth';
i still need to do npm:puppeteer somewhere
or at least load it somehow
it needs that base module loaded
You can import it too
but its the same name as the extra plugin
like this?
import puppeteer from 'npm:puppeteer';
import puppeteer from 'npm:puppeteer-extra';
import StealthPlugin from 'npm:puppeteer-extra-plugin-stealth';
i get a 101 http response error
Where ?
Keep in mind that it's hard for others to assist without the context of stacktraces, error-messages or code (without running and implementing it themselves)
yeah i know
import 'npm:puppeteer';
import puppeteer from 'npm:puppeteer-extra';
import StealthPlugin from 'npm:puppeteer-extra-plugin-stealth';
it can't do the websocket upgrade i guess
Yeah, looks like the node-compat layer isn't fully correct/compatible wrt to ws clients
Should be fixable
But I don't personally have time to dive into that
fixable where in deno or in puppeteer
i'm going to rewrite this backend in node anyway.
so don't worry about it
unless you can do it in the next few months
From a quick glance at the code (https://github.com/websockets/ws/blob/master/lib/websocket.js#L894)
It seems like the bug would originate from deno's node-compat not emitting/supporting the upgrade event on client requests
I think there's all the fundamental infra to support it
So it might be a quick fix, taking a few minutes or hours
Sure, or take a look yourself
The relevant code is roughly here: https://github.com/denoland/deno_std/blob/main/node/http.ts#L130
From a quick glance we aren't emitting the 'upgrade' event and the underlying client might be h2 whereas the logic here assumes h1
probably above my paygrade. i don't know much about internal modules
i'm just a user
Yeah, open a ticket and maybe someone from the core team might get around to it
is h2 related to the sesrver?
h2 => HTTP/2
i see
Node's http/https is http/1
Websockets over http/1 and http/2 broadly follow the same core ideas but have slightly different mechanisms and semantics
file it here? https://github.com/denoland/deno
Or deno_std since that's where the node-compat code is
Either works, I believe the admit team can transfer the issue over if necessary
It's probably best to recap the context rather than just pointing to a discord thread
The issue is that npm's ws lib (and thus all consumers) doesn't work client-side, because deno's node-compat impl of http/https clients don't handle upgrades / emit upgrade-events
With the sub-issue that http/https uses fetch, which might use h2 for https whereas node's https module only supports/assumes h1
Though in your specific case, you probably only need http/h1 so that h2 mixup isn't an issue per se, since puppeteer should handshake over http locally