R
Railway•9mo ago
Slashiy

Browserless only listening to 127.0.0.1?

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
Solution:
so Bun just hangs when it tries to connect
Jump to solution
129 Replies
Percy
Percy•9mo ago
Project ID: 8692a59f-3cb6-4863-a67e-c9864cb63401
Slashiy
SlashiyOP•9mo 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
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 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"
},
{
"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"
},
Slashiy
SlashiyOP•9mo ago
Plus I am getting this also
No description
Slashiy
SlashiyOP•9mo ago
I'm gonna try adding the env vars to the project specifically instead inside of the Dockerfile
Brody
Brody•9mo 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
Slashiy
SlashiyOP•9mo ago
Would I need to specific that as a HOST env?
Brody
Brody•9mo ago
unfortunately I am uncertain on how you would configure what host browserless runs on for that, you would need to reference their documentation
Slashiy
SlashiyOP•9mo ago
Alright Seems like it is just HOST as an environment variable
Brody
Brody•9mo ago
I assume you are using the browserless template?
Slashiy
SlashiyOP•9mo ago
Uh yes Well I had to redeploy, but yes
Brody
Brody•9mo ago
that template is very old and thus made long before railway had private networking you are not the first to have issues using it
Slashiy
SlashiyOP•9mo ago
Yes, but it uses the latest docker image
Brody
Brody•9mo ago
yes, but it's missing the correct configurations to use it in fact it's so old, it deploys from a Dockerfile when it should be just a docker image without a github repository
Slashiy
SlashiyOP•9mo ago
ghcr.io/browserless/base:latest something like this? I'll see if it works now
Brody
Brody•9mo ago
I don't know, did they stop hosting their images on dockerhub?
Slashiy
SlashiyOP•9mo ago
They still are but they are also hosting on the github reg
Brody
Brody•9mo ago
any reason you decided to switch to the ghcr hosted image? along with going for the base image and not the chrome image
Slashiy
SlashiyOP•9mo ago
oh I didn't I just sent what I saw on the ghcr https://hub.docker.com/r/browserless/chrome still on dockerhub okay I switched from the template to the docker image directly
Brody
Brody•9mo ago
looks like you where correct about the HOST variable https://www.browserless.io/docs/docker#defining-a-host-bind
Slashiy
SlashiyOP•9mo ago
Looks like it is not possible to supply "::" as a host value
Slashiy
SlashiyOP•9mo ago
here is the logs
Slashiy
SlashiyOP•9mo ago
just so you can see
Brody
Brody•9mo ago
have you tried the other host option I mentioned? [::]
Slashiy
SlashiyOP•9mo ago
uhh let me try
Slashiy
SlashiyOP•9mo ago
using [::]
Brody
Brody•9mo ago
interesting, though that is more progress wonder why it's trying to do a DNS lookup on its own host?
Slashiy
SlashiyOP•9mo ago
yeah very good question... though it seems like some internal thing?
Brody
Brody•9mo ago
it needs to not do that lol have you tried 0.0.0.0 as the HOST?
Slashiy
SlashiyOP•9mo ago
that is the default, but I will try and swap it to that
Brody
Brody•9mo ago
I thought 127.0.0.1 was the default, as your title says
Slashiy
SlashiyOP•9mo ago
well it looks like i was using v1 of browserless(which is what the template is using)
Slashiy
SlashiyOP•9mo ago
and after swapping to using the docker image directly
No description
Slashiy
SlashiyOP•9mo ago
it swapped to v2
Brody
Brody•9mo ago
interesting, does this mean it works now?
Slashiy
SlashiyOP•9mo ago
logs now using default
Brody
Brody•9mo ago
okay good sign, no errors
Slashiy
SlashiyOP•9mo ago
other thing they also did was make a separate image for chormium I was using the chrome image, which could also be why it does not connect
Brody
Brody•9mo ago
why would chrome Vs chromium cause it not to connect?
Slashiy
SlashiyOP•9mo ago
idk just reading the docs on the service said to swap it to use ghcr.io/browserless/chromium instead of ghcr.io/browserless/chrome idk what difference it makes
Brody
Brody•9mo ago
have you tried to connect to it yet?
Slashiy
SlashiyOP•9mo ago
yes when I used the chrome specific image and it still didn't work
Brody
Brody•9mo ago
what is the url you are trying to connect to it with?
Slashiy
SlashiyOP•9mo ago
so swapped to chromium image to see if that was the cause ws://browserless-production-9cdd.up.railway.app/playwright/chromium as an external right now
Brody
Brody•9mo ago
you need to use wss
Slashiy
SlashiyOP•9mo ago
ah yeah
Brody
Brody•9mo ago
railway is ssl only
Slashiy
SlashiyOP•9mo ago
With connection tries
Brody
Brody•9mo ago
what is the url you are trying to connect to it with?
Slashiy
SlashiyOP•9mo ago
wss://browserless-production-9cdd.up.railway.app/chromium/playwright please note
Slashiy
SlashiyOP•9mo ago
No description
Slashiy
SlashiyOP•9mo ago
docs says it can take either way of that URL could "PORT" be the issue here? as I had it set to 3000
Brody
Brody•9mo ago
is that not the port browserless runs on?
Slashiy
SlashiyOP•9mo ago
uhh you can change it with a env var
Brody
Brody•9mo ago
right but what's the default port browserless runs on
Slashiy
SlashiyOP•9mo ago
default is 3000 since I have set a external URL I can simply just try and connect to it with the generated URL
Brody
Brody•9mo ago
your url is incorrect, it was changed in v2 according to their migration guide https://github.com/browserless/browserless/blob/main/MIGRATION-2.0.md#browserless-20-migration-guide it should be /playwright/chromium
Slashiy
SlashiyOP•9mo ago
still says it can't see it I'm gonna try with connectOverCDP
Brody
Brody•9mo ago
what's cdp?
Slashiy
SlashiyOP•9mo ago
no
Brody
Brody•9mo ago
sorry, typo
Slashiy
SlashiyOP•9mo ago
const browser = await pw.chromium.connect('ws://localhost:3000/playwright/chromium');

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

// OR
const browser = await pw.chromium.connectOverCDP('ws://localhost:3000');
what the docs gives ignoring ws as that should be wss
Brody
Brody•9mo ago
can't hurt to try
Slashiy
SlashiyOP•9mo ago
well that did nothing as in no logs or anything
Brody
Brody•9mo ago
was worth a try
Slashiy
SlashiyOP•9mo ago
yeah idk why it keep saying it couldn't get that URL...
Brody
Brody•9mo ago
are you specifying a token?
Slashiy
SlashiyOP•9mo ago
nope
Brody
Brody•9mo ago
try doing so
Slashiy
SlashiyOP•9mo ago
with token I'm at a loss of how to fix this
Brody
Brody•9mo 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
Slashiy
SlashiyOP•9mo ago
yeah that is alright, no rush on this
Brody
Brody•9mo ago
im not seeing how this is a limitation of railway, very likely just have some minor config wrong
Slashiy
SlashiyOP•9mo ago
yeah, its just odd
Brody
Brody•9mo ago
indeed
Slashiy
SlashiyOP•9mo ago
Funny. I just tried running a websocket connect in Insomnium and it gets a 400...
Brody
Brody•9mo ago
what happens when you just open the /docs endpoint in your browser
Slashiy
SlashiyOP•9mo ago
This
No description
Slashiy
SlashiyOP•9mo ago
I've been on it for a good while now
Brody
Brody•9mo ago
okay that at least works
Slashiy
SlashiyOP•9mo ago
I tried not having any proxy/external set as a env var as I had before and I can still access this site without any issues It's just so odd playwright wants to try and use some HTTP request? and not just go straight to using websocket..
Brody
Brody•9mo ago
works fine for me
No description
Slashiy
SlashiyOP•9mo ago
hmm........
Brody
Brody•9mo ago
show me all your variables as shown in the raw editor
Slashiy
SlashiyOP•9mo ago
No description
Brody
Brody•9mo ago
here are mine
HOST=0.0.0.0
PORT=3000
PROXY_HOST=${{RAILWAY_PUBLIC_DOMAIN}}
PROXY_PORT=443
PROXY_SSL=true
TOKEN=ShMC4aK5RjYQtWdpTBU9bDeX3g2xE6sf
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://<domain>/playwright/chromium?token=<token>
Slashiy
SlashiyOP•9mo ago
Okay let me try that out are you using the docker image directly? or the template
Brody
Brody•9mo ago
and remind me again, what is the current image you are using? im using ghcr.io/browserless/chromium:latest
Slashiy
SlashiyOP•9mo ago
that is the same as mine
Brody
Brody•9mo ago
i deployed all this from scratch
Slashiy
SlashiyOP•9mo ago
No description
Brody
Brody•9mo ago
not that it would technically matter since at this point you are using the same image as me
Slashiy
SlashiyOP•9mo ago
I can do a full redeploy and see what that does
Brody
Brody•9mo ago
show me your raw variables?
Slashiy
SlashiyOP•9mo ago
No description
Slashiy
SlashiyOP•9mo ago
I did a redeploy with using the ghcr image link you sent
Slashiy
SlashiyOP•9mo ago
Just wondering if there would be a difference between these 2
No description
Brody
Brody•9mo 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
Slashiy
SlashiyOP•9mo ago
Slashiy
SlashiyOP•9mo ago
HOST=0.0.0.0
PORT=3000
PROXY_HOST=${{RAILWAY_PUBLIC_DOMAIN}}
PROXY_PORT=443
PROXY_SSL=true
TOKEN=test123
HOST=0.0.0.0
PORT=3000
PROXY_HOST=${{RAILWAY_PUBLIC_DOMAIN}}
PROXY_PORT=443
PROXY_SSL=true
TOKEN=test123
Brody
Brody•9mo ago
show me your code?
Slashiy
SlashiyOP•9mo ago
I'm using bun, but I don't think that should make an awful lot of a difference
Brody
Brody•9mo ago
oh bun, who knows, i've seen bun do some funky stuff its still javascript so lets see the code anyway
Slashiy
SlashiyOP•9mo 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.",
});
}
};
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.",
});
}
};
Pretty much how it stands right now Don't mind the top require one, I was just seeing if import and require had some quirky difference but still same behaviour
Brody
Brody•9mo ago
would you be interested in trying their example code with node instead of bun? https://www.browserless.io/docs/playwright#javascript-playwright always good to first get a minimal example working!
Slashiy
SlashiyOP•9mo ago
yeah let me spin up a minimal project then huh... that worked?
Brody
Brody•9mo ago
okay now run the same example code on bun?
Slashiy
SlashiyOP•9mo ago
ahaaa :ICANT:
Solution
Slashiy
Slashiy•9mo ago
so Bun just hangs when it tries to connect
Slashiy
SlashiyOP•9mo ago
while node does not interesting...
Slashiy
SlashiyOP•9mo ago
No description
Brody
Brody•9mo ago
thats running the same example code with bun?
Slashiy
SlashiyOP•9mo ago
guess that is a bun thing then yes and its just hanging so this is a bun quirk
Brody
Brody•9mo ago
alrightly bun issue then how fun
Slashiy
SlashiyOP•9mo ago
Just really pain for me as I don't want to rewrite my whole project
Brody
Brody•9mo ago
you use bun apis?
Slashiy
SlashiyOP•9mo ago
Nope None besides bun run --watch <filename here> which is only locally
Brody
Brody•9mo ago
so then why would a rewrite be needed? just switch to node?
Slashiy
SlashiyOP•9mo ago
the production code is just running node dist/index.js as I'm using tsup to compile(transpile) to js right okay then its just something for local good to know
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();
}
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();
}
I had it like this before and I wanted to test browserless locally with bun which then caused this mess oh well
Brody
Brody•9mo ago
well problem solved though!
Slashiy
SlashiyOP•9mo ago
yes! thank you for sticking with me 😂 and spending so much time on this
Brody
Brody•9mo ago
happy to help! problem solved, and now you also have a v2 browserless deploy that can be used with node
Slashiy
SlashiyOP•9mo ago
Yes the production command is node dist/index.js so it doesn't rely on bun
Brody
Brody•9mo ago
time to change that token too!
Slashiy
SlashiyOP•9mo ago
ah yes true feel free to close this issue now I can't mark it as solved somehow
Brody
Brody•9mo ago
that seems like a good message to mark as solved haha
Want results from more Discord servers?
Add your server