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
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"
},
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
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
a year ago
I assume you are using the browserless template?
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
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
[ghcr.io/browserless/base:latest](ghcr.io/browserless/base:latest)
something like this?
a year ago
I don't know, did they stop hosting their images on dockerhub?
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
a year ago
looks like you where correct about the HOST
variable
a year ago
have you tried the other host option I mentioned? [::]
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?
a year ago
it needs to not do that lol
a year ago
have you tried 0.0.0.0 as the HOST?
a year ago
I thought 127.0.0.1 was the default, as your title says
well it looks like i was using v1 of browserless(which is what the template is using)
a year ago
interesting, does this mean it works now?
a year ago
okay good sign, no errors
a year ago
why would chrome Vs chromium cause it not to connect?
idk just reading the docs on the service said to swap it to use [ghcr.io/browserless/chromium](ghcr.io/browserless/chromium)
a year ago
have you tried to connect to it yet?
a year ago
what is the url you are trying to connect to it with?
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
a year ago
railway is ssl only
a year ago
what is the url you are trying to connect to it with?
wss://[browserless-production-9cdd.up.railway.app/chromium/playwright](browserless-production-9cdd.up.railway.app/chromium/playwright)
a year ago
is that not the port browserless runs on?
a year ago
right but what's the default port browserless runs on
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
a year ago
what's cdp?
a year ago
sorry, typo
const browser = await pw.chromium.connect('ws://localhost:3000/playwright/chromium');
// OR
const browser = await pw.chromium.connectOverCDP('ws://localhost:3000');
a year ago
can't hurt to try
a year ago
was worth a try
a year ago
are you specifying a token?
a year ago
try doing so
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
a year ago
im not seeing how this is a limitation of railway, very likely just have some minor config wrong
a year ago
indeed
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
a year ago
okay that at least works
a year ago
works fine for me
a year ago
show me all your variables as shown in the raw editor
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=
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)
a year ago
i deployed all this from scratch
a year ago
not that it would technically matter since at this point you are using the same image as me
a year ago
show me your raw variables?
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
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?
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
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.",
});
}
};
Don't mind the top require one, I was just seeing if import and require had some quirky difference
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!
a year ago
okay now run the same example code on bun?
a year ago
thats running the same example code with bun?
a year ago
alrightly bun issue then
a year ago
how fun
a year ago
you use bun apis?
a year ago
so then why would a rewrite be needed? just switch to node?
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();
}
a year ago
well problem solved though!
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
a year ago
time to change that token too!
a year ago
that seems like a good message to mark as solved haha