Does browslerless support headful mode?
ash
FREEOP

2 years 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

135 Replies

ash
FREEOP

2 years ago

d2a990ba-9a9a-40aa-9414-f3d1ae9e016f


ash
FREEOP

2 years ago

Note: the above is an example from the docs and not my code (links not configured etc)


2 years ago

railway is a headless environment, so I'd say no its not going to be supported


ash
FREEOP

2 years ago

Oh I see, thanks


ash
FREEOP

2 years ago

Any idea if I can load a stream from a wss in headless mode?


2 years ago

I don't see why not, I also don't see how headless or not would come into play here


ash
FREEOP

2 years ago

The stream I'm trying to load is from my own app - and can change the page I'm visiting with puppeteer


ash
FREEOP

2 years ago

Hm I see, I can't get the wss to load for some reason


ash
FREEOP

2 years ago

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;

2 years ago

hmmm, I don't really know what to tell you here


ash
FREEOP

2 years ago

Any args for me to run that you think might help maybe?


2 years ago

sorry, I don't have any real experience with puppeteer


ash
FREEOP

2 years ago

Okie, thanks anyways :)


ash
FREEOP

2 years ago

@Brody is there any other way you know of to run Browserless in headful mode?


2 years ago

well does something error out when you tell it to run with a head?


ash
FREEOP

2 years ago

It works fine in headful, only issue is with headless


ash
FREEOP

2 years ago

Which it turns out WebRTC streams aren't supported in headless mode


2 years ago

right but can you not run it in headfull mode?


ash
FREEOP

2 years ago

Correct


2 years ago

then there you have it


2 years ago

I also noticed you are using browserless.io, instead of self hosting browserless on railway? not that it would fix anything


ash
FREEOP

2 years ago

Oh I'm using the Railway instance - I just copied that off their docs


2 years ago

ah okay cool


ash
FREEOP

2 years ago

Out of curiosity, why doesn't Railway support headful mode?


2 years ago

it's a docker environment, there are no heads, nothing specific to railway


ash
FREEOP

2 years ago

Oh I see, so if I added something like x11 into the container it would work?


2 years ago

yeah, you'd need to emulate something like that


2 years ago

if you give me several hours, i may be able to implement that for you


ash
FREEOP

2 years ago

Oh!!


ash
FREEOP

2 years ago

I would super super appreciate that


2 years 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?


ash
FREEOP

2 years ago

Sure let me work on that


2 years ago

i say several hours because im just about to head out, so ill work on it when im back


2 years ago

but that gives you time to work on the example!


ash
FREEOP

2 years ago

Works perfectly, thanks a bunch :)


2 years ago

no problem!


ash
FREEOP

2 years ago

"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));
  }
};

2 years ago

mind throwing that in a repo so I can simply run it in a service?


ash
FREEOP

2 years ago

Sure!


2 years ago

full repo that has everything I'd need to trigger that code to run and do it's thing


ash
FREEOP

2 years ago

What's your github?


2 years ago

brody192


ash
FREEOP

2 years ago

Done, just sent over the repo to you


2 years ago

it doesn't look very minimal


ash
FREEOP

2 years ago

I guess it does crash when headful is unsupported while requesting it in the .connect


ash
FREEOP

2 years ago

Will update


ash
FREEOP

2 years ago

Done, just pushed the simplified version


2 years ago

haha I think you are missing the point of minimal


ash
FREEOP

2 years ago

Ok I might be 😭


ash
FREEOP

2 years ago

What do you mean by it?


2 years ago

not a full project, just like a single script that proves the issue / proves it's fixed


ash
FREEOP

2 years ago

Oh, I thought of doing that but wasn't sure how it would be trigerred on Railway easily


ash
FREEOP

2 years ago

so I resorted to the existing


2 years ago

you'd have your package.json setup properly, right now you have a full app


ash
FREEOP

2 years ago

Sorry about that, want me to rewrite it?


2 years ago

I'd just like a minimal reproducible example, emphasis on minimal


ash
FREEOP

2 years ago

Done, just pushed it


2 years ago

okay perfect, now that's minimal


2 years ago

one question, how have you been able to verify that this code works? run it with your local chrome install instead of browserless?


ash
FREEOP

2 years ago

Yes, I wrote it with normal puppeteer initially and then modified it for browserless


ash
FREEOP

2 years ago

Will test it out again with the minimal version


2 years ago

okay perfect


ash
FREEOP

2 years ago

Seems like there's an issue with some newer updates I made to it, let me fix and push


ash
FREEOP

2 years ago

Okay fixed - when you run local.ts it uses normal puppeteer, when you run index.ts it uses browserless


ash
FREEOP

2 years ago

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)


ash
FREEOP

2 years ago

(Headless always returns a blank screen)


2 years ago

okay cool, what version is going to run by default when deployed to railway?


ash
FREEOP

2 years ago

The browserless version


2 years ago

perf


2 years ago

i dont have bun locally (windows without WSL) so how can i verify that this is not working?

1282505180394426400


2 years ago

how fast could you add in a web server to serve that image?


ash
FREEOP

2 years ago

I can start the stream, and if the file size increases we'll know it's working


2 years ago

Uint8Array(4190) would increase?


ash
FREEOP

2 years ago

Just a rough guess - let me get back to you on this


ash
FREEOP

2 years ago

Yes it would


2 years ago

might help to have a web server to serve that image?


ash
FREEOP

2 years ago

Okay let me see


2 years ago

i know i said minimal but id still need a way to verify my findings since i cant run this locally


ash
FREEOP

2 years ago

Ofcourse - working on a webserver to serve the image


2 years ago

web server or convert to plain old node, whatever is easier


ash
FREEOP

2 years ago

Pushed


2 years ago

sweet


ash
FREEOP

2 years ago

http://{domain}/thumbnail/the_winzy


2 years ago

this was such a good feature

1282508306556125200


ash
FREEOP

2 years ago

Oh I didn't even know that was a feature


ash
FREEOP

2 years ago

W feature


2 years ago

yeah i mean in this scenario i trust what you are pushing but its a good security feature to have


ash
FREEOP

2 years ago

Yeah 100%


2 years ago

and you said if the image is black its not working?


ash
FREEOP

2 years ago

Correct


ash
FREEOP

2 years ago

If it's just all black and no text/icons


2 years ago

gotcha


ash
FREEOP

2 years ago

Uint8Array(4190) should mean it's working as far as I can tell


ash
FREEOP

2 years ago

But that's just a terrible way to check lol


2 years ago

thats funny since i didnt implement the virtual display server yet


ash
FREEOP

2 years ago

Oh??


2 years ago

are you using browserless v1 or v2


ash
FREEOP

2 years ago

v2


2 years ago

same


ash
FREEOP

2 years ago

Ok we should probs see the result from the endpoint


2 years ago

waiting for dns to update so i can see the image


ash
FREEOP

2 years ago

Nvm, I got mixed up - I have the stream running now so it should be easier to see if it works or not


2 years ago

dns still isnt updated yet lol


ash
FREEOP

2 years ago

You'll see my screen if it's working or a black screen


ash
FREEOP

2 years ago

Oh xD


2 years ago

it is indeed black


2 years ago


ash
FREEOP

2 years ago

I rlly hope X11 fixes this


2 years ago

me too


ash
FREEOP

2 years ago

<:prayge:1231933593924927560>


ash
FREEOP

2 years ago

Thanks again for all the effort, super appreciate it


2 years ago

of course!


2 years ago

you are running it in headless mode? i thought you wanted headless false?


2 years ago


ash
FREEOP

2 years ago

Ooops I forgot to change that back


ash
FREEOP

2 years ago

Pushed


2 years ago

awsome


2 years ago

is the stream running?


ash
FREEOP

2 years ago

Yep


2 years ago

still black even with xvfb running


ash
FREEOP

2 years ago

:(


ash
FREEOP

2 years ago

The browserless instance doesn't crash though while connecting with headless: false?


2 years ago

correct


ash
FREEOP

2 years ago

sighs will have to dig in further tomorrow when I get up, almost 9 am for me


2 years ago

great sleep schedule lol


2 years ago

can you leave the stream running?


ash
FREEOP

2 years ago

Could you share an easy way for me to replicate the instance with headful mode on?


ash
FREEOP

2 years ago

For sure


2 years ago

this is what ive done so far


2 years ago


2 years ago

it works now, and all i did was switch to browserless v1.

stock template, no xvfb.


ash
FREEOP

2 years ago

Interesting - no idea why that works but, thank you so so much


ash
FREEOP

2 years ago

<:patrikdab:901282271087185951>


ash
FREEOP

2 years ago

Literally saved me from another few days of debugging :)


2 years ago

no problem!


Loading...