You can use a service that provides a headless browser, such as Browserless, to run your Bytebot queries. This is useful to avoid running Chrome on your production hardware, and to avoid the overhead of managing a headless browser yourself.
Sign up to Browserless and obtain an API key
To start, you’ll need an API key from Browserless. You can sign up for an account at Browserless.
Once you have obtained an API key, it’s good practice to expose to your code via an environment variable.
This avoids hardcoding the API key in your code, which could lead to security issues.
In the example below, we assume you have set the environment variable BROWSERLESS_API_KEY
to your Browserless API key.
Use the Bytebot client with Browserless
Modifying your Puppeteer code to use Browserless is simple, as shown in the example below, but for more information please refer to the Browserless documentation.
You’ll need to replace the puppeteer.launch()
call with a call to puppeteer.connect()
with the Browserless URL and API key.
As suggested in the Browserless documentation, you may want to launch the browser locally during development and testing, and only use Browserless in production.
This can be achieved by using an environment variable (in this example called IS_PRODUCTION
) to determine whether to use Browserless or not.
Full Browserless example
The following is a full example of using Browserless with Bytebot to execute an action. It’s assumed that:
- You have correctly installed the
@bytebot/sdk
package andpuppeteer
- You have obtained a Browserless API key and set it as an environment variable
- You have obtained a Bytebot API key and set it as an environment variable
- You have created an environment variable
IS_PRODUCTION
to determine whether to use Browserless or not