a year ago
I followed the docs, implemented this and still struggling:
```import puppeteer from "puppeteer-core";
const launchArgs = JSON.stringify({
args: [--window-size=1920,1080
, --user-data-dir=/tmp/chrome/data-dir
],
headless: false,
stealth: true,
timeout: 5000,
});
const browser = await puppeteer.connect({
browserWSEndpoint: wss://production-sfo.browserless.io/?token=GOES-HERE&launch=${launchArgs}
,
});```
I'm getting: Error: Unexpected server response: 500
0 Replies
Note: the above is an example from the docs and not my code (links not configured etc)
a year ago
railway is a headless environment, so I'd say no its not going to be supported
a year ago
I don't see why not, I also don't see how headless or not would come into play here
The stream I'm trying to load is from my own app - and can change the page I'm visiting with puppeteer
How I know the stream isn't loading
const targetWsUrl = "wss://url/rtc";
let wsConnected = false;
page.on("request", (request) => {
console.log("Request:", request.url());
const url = request.url();
if (url.startsWith(targetWsUrl)) {
wsConnected = true;
a year ago
hmmm, I don't really know what to tell you here
a year ago
sorry, I don't have any real experience with puppeteer
a year ago
well does something error out when you tell it to run with a head?
a year ago
right but can you not run it in headfull mode?
a year ago
then there you have it
a year ago
I also noticed you are using browserless.io, instead of self hosting browserless on railway? not that it would fix anything
a year ago
ah okay cool
a year ago
it's a docker environment, there are no heads, nothing specific to railway
a year ago
yeah, you'd need to emulate something like that
a year ago
if you give me several hours, i may be able to implement that for you
a year ago
id just need you to provide me with a minimal reducible example that i can run so that tells me / shows me that ive started chrome in headfull mode, of course this example should also provide some indictor or error if i try to start chrome in headfull mode and browserless isnt supporting that, know what i mean?
a year ago
i say several hours because im just about to head out, so ill work on it when im back
a year ago
but that gives you time to work on the example!
a year ago
no problem!
"use server";
import puppeteer from "puppeteer-core";
export const captureThumbnail = async (username: string) => {
const launchArgs = JSON.stringify({
stealth: true,
args: [
`--use-fake-device-for-media-stream`,
`--use-fake-ui-for-media-stream`,
`--no-sandbox`,
],
});
console.log("Capturing thumbnail for:", username);
const browser = await puppeteer.connect({
browserWSEndpoint: `${process.env.BROWSER_WS_ENDPOINT}&launch=${launchArgs}`,
});
const page = (await browser.pages())[0];
await page.setViewport({ width: 640, height: 360 });
const targetWsUrl = "wss://";
let wsConnected = false;
page.on("request", (request) => {
console.log("Request:", request.url());
const url = request.url();
if (url.startsWith(targetWsUrl)) {
wsConnected = true;
console.log("WebSocket connection established:", url);
const screenshot = async () => {
const screenshot = await page.screenshot({
type: "png",
fullPage: true,
});
console.log("Screenshot succesful")
};
procedure();
}
});
await page.goto(`${page_url}`);
while (!wsConnected) {
console.log("Waiting for WebSocket connection...");
await new Promise((resolve) => setTimeout(resolve, 1000));
}
};
a year ago
mind throwing that in a repo so I can simply run it in a service?
a year ago
full repo that has everything I'd need to trigger that code to run and do it's thing
a year ago
brody192
a year ago
it doesn't look very minimal
I guess it does crash when headful is unsupported while requesting it in the .connect
a year ago
haha I think you are missing the point of minimal
a year ago
not a full project, just like a single script that proves the issue / proves it's fixed
Oh, I thought of doing that but wasn't sure how it would be trigerred on Railway easily
a year ago
you'd have your package.json setup properly, right now you have a full app
a year ago
I'd just like a minimal reproducible example, emphasis on minimal
a year ago
okay perfect, now that's minimal
a year ago
one question, how have you been able to verify that this code works? run it with your local chrome install instead of browserless?
Yes, I wrote it with normal puppeteer initially and then modified it for browserless
a year ago
okay perfect
Seems like there's an issue with some newer updates I made to it, let me fix and push
Okay fixed - when you run local.ts it uses normal puppeteer, when you run index.ts it uses browserless
You'll be able to see the difference it output between the two (and sorry for the hassle - I should have tested the newest version with all the new stuff I added on while debugging)
a year ago
okay cool, what version is going to run by default when deployed to railway?
a year ago
perf
a year ago
i dont have bun locally (windows without WSL) so how can i verify that this is not working?
a year ago
how fast could you add in a web server to serve that image?
a year ago
Uint8Array(4190)
would increase?
a year ago
might help to have a web server to serve that image?
a year ago
i know i said minimal but id still need a way to verify my findings since i cant run this locally
a year ago
web server or convert to plain old node, whatever is easier
a year ago
sweet
a year ago
this was such a good feature
a year ago
yeah i mean in this scenario i trust what you are pushing but its a good security feature to have
a year ago
and you said if the image is black its not working?
a year ago
gotcha
a year ago
thats funny since i didnt implement the virtual display server yet
a year ago
are you using browserless v1 or v2
a year ago
same
a year ago
waiting for dns to update so i can see the image
Nvm, I got mixed up - I have the stream running now so it should be easier to see if it works or not
a year ago
dns still isnt updated yet lol
a year ago
it is indeed black
a year ago
a year ago
me too
a year ago
of course!
a year ago
you are running it in headless mode? i thought you wanted headless false?
a year ago
a year ago
awsome
a year ago
is the stream running?
a year ago
still black even with xvfb running
The browserless instance doesn't crash though while connecting with headless: false?
a year ago
correct
a year ago
great sleep schedule lol
a year ago
can you leave the stream running?
a year ago
this is what ive done so far
a year ago
a year ago
it works now, and all i did was switch to browserless v1.
stock template, no xvfb.
a year ago
no problem!