Create an Action
In this guide, you will create and execute a simple action on a local browser. If you want to create an action on a Bytebot-managed remote instance instead, click here.
Bytebot’s Act Function
With Bytebot’s act function, you can convert a natural language prompt into an array of BrowserActions. To accomplish this, use the .act(prompt: string, page: Page, options?: Object)
function. The function is async and accepts the following optional configurations:
To begin, start by writing a concise and clear prompt inside an async block:
Then, call act
, passing in the prompt text and the page:
If you run this code, you should get a printout in your console similar to:
The actions
array is a set of BrowserAction
objects, each with a type
(e.g., “Click” or “Hover”) and an xpath
(a reference to a specific DOM element). The pages
array is akin to the open tabs on the browser, each with a pageId
and url
.
Bytebot’s Execute Function
Now that we have an array of BrowserAction
objects, we need to manually execute them. You can accomplish that using the .execute(actions: BrowserAction[], page: Page)
function:
Now, the previously generated BrowserActions have been executed on the local instance.
Use Parameters to Handle Sensitive Content
Because Bytebot uses generally available AI models, it is important to safeguard any sensitive content from being shared with them. This is made possible by Bytebot’s parameters
option. Parameters allow for a query to be run with placeholders, with the sensitive data substituted after the browser execution.
To use parameters
, just include it as an attribute to the options object:
Now, the browser actions will be generated without sharing sensitive data (in this case, email and password).