Initialize a Browser
Initialize a Browser
In this guide, we will initialize a Bytebot-managed remote browser. If you want to use a local Puppeteer instance instead, click here.
Initialize Bytebot
To start, you will need to import the Bytebot SDK. If you haven’t installed Bytebot yet, please refer to our installation guide.
The BytebotClient includes all of the functions needed to start a browser session and create any browser actions. Its constructor requires an API key to be successfully initialized.
If you are using a .env, you may need to install dotenv to import it.
Start a Session
Before generating and executing a browser action, you will need to start a browser session. To start a browser session, use BytebotClient.browser.startSession(url: string) , where the url is the initial page on the browser.
If successful, the function will return an object with a sessionId attribute.
Because createSession is initializing a complete browser instance in a virtual environment, it can take 10s to 30s to complete.
End a Session
Once you are done with your browser, you should end your session to destroy the browser. To end a browser session, use BytebotClient.endSession(sessionId: string) , where the sessionId is a string of the session’s identifier.
When successful, the function will return an object with a sessionId
of the closed browser or an error
represented as a string
.
With the basics down, you are now ready to create actions and extract data.