Browserless only listening to 127.0.0.1?

AnonymousTRIAL

a year ago

Hello,

I'm trying to use browserless for my playwright testing…
But it never connects, I tried adding proxy environment but that didn't change anything…

What can I do?

Project id: 8692a59f-3cb6-4863-a67e-c9864cb63401

0 Replies

AnonymousTRIAL

a year ago

ARG VERSION=latest
FROM browserless/chrome:$VERSION

ENV PROXY_HOST="browserless-production-ae10.up.railway.app"
ENV PROXY_PORT=$PORT
ENV PROXY_SSL=true

This is what I did to try and make it work, but I just hit a wall, please note these ENV are per browserless's documentation


AnonymousTRIAL

a year ago

I took a look on the /sessions page to see what endpoint it was using and it uses:

{
"description": "",
"devtoolsFrontendUrl": "/devtools/inspector.html?ws=0.0.0.0:7690/devtools/page/6787140A97C09B8BF27082D8FB527EF1",
"id": "6787140A97C09B8BF27082D8FB527EF1",
"title": "about:blank",
"type": "page",
"url": "about:blank",
"webSocketDebuggerUrl": "ws://0.0.0.0:7690/devtools/page/6787140A97C09B8BF27082D8FB527EF1",
"port": "44335",
"browserId": "3c935235-a887-4336-9b19-43c9c4f19de0",
"trackingId": null,
"browserWSEndpoint": "ws://0.0.0.0:7690/devtools/browser/3c935235-a887-4336-9b19-43c9c4f19de0"
},

AnonymousTRIAL

a year ago

Plus I am getting this also


AnonymousTRIAL

a year ago

I'm gonna try adding the env vars to the project specifically instead inside of the Dockerfile


a year ago

you would need to get browserless to listen on :: or [::] aka ipv6

then you'd want to use it's private domain to connect to it from other services while on railway


AnonymousTRIAL

a year ago

Would I need to specific that as a HOST env?


a year ago

unfortunately I am uncertain on how you would configure what host browserless runs on


a year ago

for that, you would need to reference their documentation


AnonymousTRIAL

a year ago

Alright


AnonymousTRIAL

a year ago

Seems like it is just HOST as an environment variable


a year ago

I assume you are using the browserless template?


AnonymousTRIAL

a year ago

Uh yes


AnonymousTRIAL

a year ago

Well I had to redeploy, but yes


a year ago

that template is very old and thus made long before railway had private networking


a year ago

you are not the first to have issues using it


AnonymousTRIAL

a year ago

Yes, but it uses the latest docker image


a year ago

yes, but it's missing the correct configurations to use it


a year ago

in fact it's so old, it deploys from a Dockerfile when it should be just a docker image without a github repository


AnonymousTRIAL

a year ago

[ghcr.io/browserless/base:latest](ghcr.io/browserless/base:latest) something like this?


AnonymousTRIAL

a year ago

I'll see if it works now


a year ago

I don't know, did they stop hosting their images on dockerhub?


AnonymousTRIAL

a year ago

They still are


AnonymousTRIAL

a year ago

but they are also hosting on the github reg


a year ago

any reason you decided to switch to the ghcr hosted image?


a year ago

along with going for the base image and not the chrome image


AnonymousTRIAL

a year ago

oh I didn't I just sent what I saw on the ghcr



AnonymousTRIAL

a year ago

still on dockerhub


AnonymousTRIAL

a year ago

okay I switched from the template to the docker image directly


a year ago

looks like you where correct about the HOST variable


AnonymousTRIAL

a year ago

Looks like it is not possible to supply "::" as a host value


AnonymousTRIAL

a year ago

here is the logs


AnonymousTRIAL

a year ago

just so you can see


a year ago

have you tried the other host option I mentioned? [::]


AnonymousTRIAL

a year ago

uhh let me try


AnonymousTRIAL

a year ago


AnonymousTRIAL

a year ago

using [::]


a year ago

interesting, though that is more progress


a year ago

wonder why it's trying to do a DNS lookup on its own host?


AnonymousTRIAL

a year ago

yeah very good question… though it seems like some internal thing?


a year ago

it needs to not do that lol


a year ago

have you tried 0.0.0.0 as the HOST?


AnonymousTRIAL

a year ago

that is the default, but I will try and swap it to that


a year ago

I thought 127.0.0.1 was the default, as your title says


AnonymousTRIAL

a year ago

well it looks like i was using v1 of browserless(which is what the template is using)


AnonymousTRIAL

a year ago

and after swapping to using the docker image directly


AnonymousTRIAL

a year ago

it swapped to v2


a year ago

interesting, does this mean it works now?


AnonymousTRIAL

a year ago

logs now using default


a year ago

okay good sign, no errors


AnonymousTRIAL

a year ago

other thing they also did was make a separate image for chormium


AnonymousTRIAL

a year ago

I was using the chrome image, which could also be why it does not connect


a year ago

why would chrome Vs chromium cause it not to connect?


AnonymousTRIAL

a year ago

idk just reading the docs on the service said to swap it to use [ghcr.io/browserless/chromium](ghcr.io/browserless/chromium)


AnonymousTRIAL

a year ago

instead of [ghcr.io/browserless/chrome](ghcr.io/browserless/chrome)


AnonymousTRIAL

a year ago

idk what difference it makes


a year ago

have you tried to connect to it yet?


AnonymousTRIAL

a year ago

yes


AnonymousTRIAL

a year ago

when I used the chrome specific image


AnonymousTRIAL

a year ago

and it still didn't work


a year ago

what is the url you are trying to connect to it with?


AnonymousTRIAL

a year ago

so swapped to chromium image to see if that was the cause


AnonymousTRIAL

a year ago

ws://[browserless-production-9cdd.up.railway.app/playwright/chromium](browserless-production-9cdd.up.railway.app/playwright/chromium) as an external right now


a year ago

you need to use wss


AnonymousTRIAL

a year ago

ah yeah


a year ago

railway is ssl only


AnonymousTRIAL

a year ago

With connection tries


a year ago

what is the url you are trying to connect to it with?


AnonymousTRIAL

a year ago

wss://[browserless-production-9cdd.up.railway.app/chromium/playwright](browserless-production-9cdd.up.railway.app/chromium/playwright)


AnonymousTRIAL

a year ago

please note


AnonymousTRIAL

a year ago


AnonymousTRIAL

a year ago

docs says it can take either way of that URL


AnonymousTRIAL

a year ago

could "PORT" be the issue here?


AnonymousTRIAL

a year ago

as I had it set to 3000


a year ago

is that not the port browserless runs on?


AnonymousTRIAL

a year ago

uhh you can change it


AnonymousTRIAL

a year ago

with a env var


a year ago

right but what's the default port browserless runs on


AnonymousTRIAL

a year ago

default is 3000


AnonymousTRIAL

a year ago

since I have set a external URL I can simply just try and connect to it with the generated URL


a year ago

your url is incorrect, it was changed in v2 according to their migration guide

it should be /playwright/chromium


AnonymousTRIAL

a year ago


AnonymousTRIAL

a year ago

still says it can't see it


AnonymousTRIAL

a year ago

I'm gonna try with connectOverCDP


a year ago

what's cdp?


AnonymousTRIAL

a year ago

no


a year ago

sorry, typo


AnonymousTRIAL

a year ago

const browser = await pw.chromium.connect('ws://localhost:3000/playwright/chromium');

// OR
const browser = await pw.chromium.connectOverCDP('ws://localhost:3000');

AnonymousTRIAL

a year ago

what the docs gives


AnonymousTRIAL

a year ago

ignoring ws as that should be wss


a year ago

can't hurt to try


AnonymousTRIAL

a year ago

well that did nothing


AnonymousTRIAL

a year ago

as in no logs or anything


a year ago

was worth a try


AnonymousTRIAL

a year ago

yeah idk why it keep saying it couldn't get that URL…


a year ago

are you specifying a token?


AnonymousTRIAL

a year ago

nope


a year ago

try doing so


AnonymousTRIAL

a year ago


AnonymousTRIAL

a year ago

with token


AnonymousTRIAL

a year ago

I'm at a loss of how to fix this


a year ago

im trying some things, but i am going to leave the house soon so im not sure how much i will be able to get done


AnonymousTRIAL

a year ago

yeah that is alright, no rush on this


a year ago

im not seeing how this is a limitation of railway, very likely just have some minor config wrong


AnonymousTRIAL

a year ago

yeah, its just odd


a year ago

indeed


AnonymousTRIAL

a year ago

Funny.

I just tried running a websocket connect in Insomnium and it gets a 400…


a year ago

what happens when you just open the /docs endpoint in your browser


AnonymousTRIAL

a year ago

This


AnonymousTRIAL

a year ago

I've been on it for a good while now


a year ago

okay that at least works


AnonymousTRIAL

a year ago

I tried not having any proxy/external set as a env var as I had before


AnonymousTRIAL

a year ago

and I can still access this site without any issues


AnonymousTRIAL

a year ago

It's just so odd playwright wants to try and use some HTTP request?


AnonymousTRIAL

a year ago

and not just go straight to using websocket..


a year ago

works fine for me


AnonymousTRIAL

a year ago

hmm……..


a year ago

show me all your variables as shown in the raw editor


AnonymousTRIAL

a year ago


a year ago

here are mine

HOST=0.0.0.0
PORT=3000
PROXY_HOST=${{RAILWAY_PUBLIC_DOMAIN}}
PROXY_PORT=443
PROXY_SSL=true
TOKEN=ShMC4aK5RjYQtWdpTBU9bDeX3g2xE6sf

and my url used in my code looks like wss:///playwright/chromium?token=


AnonymousTRIAL

a year ago

Okay let me try that out


AnonymousTRIAL

a year ago

are you using the docker image directly?


AnonymousTRIAL

a year ago

or the template


a year ago

and remind me again, what is the current image you are using? im using [ghcr.io/browserless/chromium:latest](ghcr.io/browserless/chromium:latest)


AnonymousTRIAL

a year ago

that is the same as mine


a year ago

i deployed all this from scratch


AnonymousTRIAL

a year ago


a year ago

not that it would technically matter since at this point you are using the same image as me


AnonymousTRIAL

a year ago


AnonymousTRIAL

a year ago

I can do a full redeploy


AnonymousTRIAL

a year ago

and see what that does


a year ago

show me your raw variables?


AnonymousTRIAL

a year ago


AnonymousTRIAL

a year ago

I did a redeploy with using the ghcr image link you sent


AnonymousTRIAL

a year ago

Just wondering if there would be a difference between these 2


a year ago

for all intensive purposes, not specifying the :latest tag should be the same as specifying the :latest tag, but can't hurt to try


AnonymousTRIAL

a year ago

no difference


AnonymousTRIAL

a year ago

HOST=0.0.0.0
PORT=3000
PROXY_HOST=${{RAILWAY_PUBLIC_DOMAIN}}
PROXY_PORT=443
PROXY_SSL=true
TOKEN=test123

a year ago

show me your code?


AnonymousTRIAL

a year ago

I'm using bun, but I don't think that should make an awful lot of a difference


a year ago

oh bun, who knows, i've seen bun do some funky stuff


a year ago

its still javascript so lets see the code anyway


AnonymousTRIAL

a year ago

import { type ModalSubmitInteraction } from "discord.js";
import { type Browser, chromium, type Page } from "playwright";
const pw = require("playwright");
import { addArt } from "./utils/directus";

export const submitArt = async (
  interaction: ModalSubmitInteraction,
  link: string,
) => {
  await interaction.reply({
    ephemeral: true,
    content: "Submitting art...",
  });

  const browser = await pw.chromium.connect(
    "wss://browserless-production-9cdd.up.railway.app/playwright/chromium?token=test123",
  );

  try {
    const page = await browser.newPage();

    await page.goto(link);
    await page.waitForSelector("section");

    if (!submitted) {
      await interaction.editReply({
        content: "Couldn't submit art to website, please ask for help.",
      });

      await browser.close();
      return;
    }

    await browser.close();

    await interaction.editReply({
      content: "Art successfully submitted!",
    });
  } catch (error) {
    console.error(error);
    await browser.close();

    await interaction.editReply({
      content:
        "Failed to submit art. Please try again, and if it fails again then report the issue.",
    });
  }
};

AnonymousTRIAL

a year ago

Pretty much how it stands right now


AnonymousTRIAL

a year ago

Don't mind the top require one, I was just seeing if import and require had some quirky difference


AnonymousTRIAL

a year ago

but still same behaviour


a year ago

would you be interested in trying their example code with node instead of bun?


a year ago

always good to first get a minimal example working!


AnonymousTRIAL

a year ago

yeah let me spin up a minimal project then


AnonymousTRIAL

a year ago

huh…


AnonymousTRIAL

a year ago

that worked?


a year ago

okay now run the same example code on bun?


AnonymousTRIAL

a year ago

ahaaa


AnonymousTRIAL

a year ago

<:ICANT:1010977143771111434>


AnonymousTRIAL

a year ago

so Bun just hangs when it tries to connect


AnonymousTRIAL

a year ago

while node does not


AnonymousTRIAL

a year ago

interesting…


AnonymousTRIAL

a year ago


a year ago

thats running the same example code with bun?


AnonymousTRIAL

a year ago

guess that is a bun thing then


AnonymousTRIAL

a year ago

yes


AnonymousTRIAL

a year ago

and its just hanging


AnonymousTRIAL

a year ago

so this is a bun quirk


a year ago

alrightly bun issue then


a year ago

how fun


AnonymousTRIAL

a year ago

Just really pain for me


AnonymousTRIAL

a year ago

as I don't want to rewrite my whole project


a year ago

you use bun apis?


AnonymousTRIAL

a year ago

Nope


AnonymousTRIAL

a year ago

None


AnonymousTRIAL

a year ago

besides bun run --watch


AnonymousTRIAL

a year ago

which is only locally


a year ago

so then why would a rewrite be needed? just switch to node?


AnonymousTRIAL

a year ago

the production code is just running node dist/index.js


AnonymousTRIAL

a year ago

as I'm using tsup to compile(transpile) to js


AnonymousTRIAL

a year ago

right okay then its just something for local


AnonymousTRIAL

a year ago

good to know


AnonymousTRIAL

a year ago

  if (process.env.NODE_ENV === "production") {
    browser = await chromium.connect(
      "wss://browserless-production-9cdd.up.railway.app/playwright/chromium?token=test123",
    );
  } else {
    browser = await chromium.launch();
  }

AnonymousTRIAL

a year ago

I had it like this before


AnonymousTRIAL

a year ago

and I wanted to test browserless locally with bun


AnonymousTRIAL

a year ago

which then caused this mess


AnonymousTRIAL

a year ago

oh well


a year ago

well problem solved though!


AnonymousTRIAL

a year ago

yes!


AnonymousTRIAL

a year ago

thank you for sticking with me 😂


AnonymousTRIAL

a year ago

and spending so much time on this


a year ago

happy to help!


a year ago

problem solved, and now you also have a v2 browserless deploy that can be used with node


AnonymousTRIAL

a year ago

Yes


AnonymousTRIAL

a year ago

the production command is node dist/index.js


AnonymousTRIAL

a year ago

so it doesn't rely on bun


a year ago

time to change that token too!


AnonymousTRIAL

a year ago

ah yes true


AnonymousTRIAL

a year ago

feel free to close this issue now


AnonymousTRIAL

a year ago

I can't mark it as solved somehow


a year ago

that seems like a good message to mark as solved haha


Browserless only listening to 127.0.0.1? - Railway Help Station