Docker Quick Start
The docker image that powers the core of Browserless is available for free for open-source projects. Using it is about as simple as using the Browserless service itself with the only difference being that you'll have to launch and manage the infrastructure.
At a high-level, we'll do the following:
- Run the docker image
- Update our app to connect to this image.
1. Run it with some sensible defaults
Running the docker image is similar to other docker run
commands, and all options are passed in via environment variables. In the example below, we're starting with the image with a maximum concurrency of 10
, further requests will remain open and ran when a slot opens up. We're also setting the token to 6R0W53R135510
.
Browserless is designed to always require a token. This means that, if you don't pass a TOKEN
env variable, a randomly generated token will be set.
After the image is pulled (one time only), then you'll see the first of our logs, which will print the final configuration.
$ docker run \
--rm \
-p 3000:3000 \
-e "CONCURRENT=10" \
-e "TOKEN=6R0W53R135510" \
ghcr.io/browserless/chromium
Feel free to visit http://localhost:3000/docs to see if the image is running properly. You can also read more about the different variables on our docker section.
2. Update your app to use Browserless
Once we have Browserless running we can simply use it inside of our application instead of launching it locally. There's more details in our docs about using Puppeteer or Playwright, but here is an example:
const express = require('express');
const puppeteer = require('puppeteer-core');
const app = express();
app.get('/image', async (req, res) => {
// This was puppeteer.launch()
const browser = await puppeteer.connect({
browserWSEndpoint: 'ws://localhost:3000?token=6R0W53R135510'
});
const page = await browser.newPage();
await page.goto('http://www.example.com/');
const data = await page.screenshot();
browser.close();
return res.end(data, 'binary');
});
app.listen(8080);
What's next?
There's a lot more that you can configure and tune in Browserless to handle the needs of your application. Be sure to read about all the options it exposes and how to get the most out of the Browserless image!
We also have docs for extra features for licensed users such as: