Puppeteer: "BadResource: Bad resource ID" on Ubuntu
Hello, i just switched my server os over to ubuntu server 23.10. When executing my script, it immediately throws an error an exits. Before, on my windows machine, the script worked completely fine.
Error:
Relevant code:
Troubleshooting steps taken:
- Re-ran installation script
- Cleared cache
- Rebooted machine
uname -a
:
Linux dnarpi 6.5.0-1011-raspi #14-Ubuntu SMP PREEMPT_DYNAMIC Fri Feb 9 14:06:28 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux
deno --version
:
deno 1.41.1 (release, aarch64-unknown-linux-gnu) v8 12.1.285.27 typescript 5.3.3
36 Replies
This doesn't answer your question I'm afraid, but if you're not deeply invested in Puppeteer, you could consider using the excellent and Deno native Astral https://astral.deno.dev/
Introduction | Astral
A simple introduction to Astral
I'll take a look at that real quick, give me a few minutes
But my best guess as to your problem is the really old version of std being imported (like 120 versions or so old) which I'm guessing is not compatible with the latest Deno.
The problem is just, that puppeteer for deno hasnt been updated in 2 years
Maybe i'd try the node version?
That was going to be my next suggestion.
@lino-levan any thoughts?
Yeah, I mean, Astral will work for arm64, but you'd need to supply a browser binary yourself
Everything after that will work just fine
I have no idea why chrome for testing doesn't ship linux arm64 binaries
In the medium term I'm adding support for Firefox but FF is even more undocumented than Chromium is when it comes to browser automation.
I just installed/downloaded chrome using
npx @puppeteer/browsers install chrome@stable
, but that returned me the same errorThat was pretty much the only source of the chrome binary i found online
chrome doesn't ship an arm linux binary
chromium does iirc
I believe you should be able to
sudo apt-get install chromium-browser
or somethingThat worked! Thank you so much
Using Astral, how can i use request interception?
what are you trying to do? I'd recommend looking at the celestial bindings
you can get them on a page using https://deno.land/x/astral@0.3.5/mod.ts?s=Page&p=prototype.unsafelyGetCelestialBindings.
that opens up access to the raw chrome devtools protocol
which gives you a ton of control
it's fully typed too which is quite nice
the docs for the chrome devtools protocol can be found https://chromedevtools.github.io/devtools-protocol/
Chrome DevTools Protocol
Chrome DevTools Protocol - version tot
depending on what you're trying to do, you should look at https://chromedevtools.github.io/devtools-protocol/tot/Fetch/
Chrome DevTools Protocol
Chrome DevTools Protocol - version tot - Fetch domain
something like
might be a good start
Code:
Error:
perhaps
unsafelyGetCelestialBindings
should wait for the websocket to be open
hmI cant use
await
on page.unsafelyGetCelestialBindings()
howeverokay, try adding
and then doing
this will be fixed in the next release of astral
I did implement this a bit differently than you did, but the result should be the same anyway. However, for some reason, its stuck after "done 0", basically at the Promise
Code:
you have to do somethign with the request
basically you "caught" the request, and you have to decide what to do with it
But wouldnt the promise get resolved anyway, even if the request isnt handled yet? Im not getting "deno 1", which is right after the promise
well
by default goto waits for network activity to stop
you can change that behavior by using the waitUntil option
or something
oh wait
hold on
I misread your message
okay well the issue is
the socket opened by the time you set up the promise
so it's hanging
ws.onopen
is never calledsomething like
should fix it?
if not I have another guess
Yeah that worked
Thank you so much for helping me with my problems
No worries, that's what I'm here for.
I still got a small question? How do i pass the request?
If you always want to pass it, you can simply call
where
requestId
is somewhere in the event, I'd look at the console.log to see where
maybe event.data.requestId?
not sureThanks once again, this worked
👍
So i just ran into the next problem. When intercepting the requests, on windows, the request for
master.m3u8
comes in and is also console.log
ged, but on my linux machine, the request never shows up. Does anyone have an idea, why it is like that? Also, the screenshot taken right before the while loop looks just the same on both machines
Code:
Hey, sorry for getting back to you so late. I suspect this is site-to-site variance. This site might avoid loading videos for someone on linux.
Is it possible to manually set the useragent?
Yes, it is
it's just
Celestial.Emulation.setUserAgentOverride