Browser Automation
GenAIScript provides a simplified API to interact with a headless browser using Playwright . This allows you to interact with web pages, scrape data, and automate tasks.
Installation
Playwright needs to install the browsers and dependencies before execution. GenAIScript will automatically try to install them if it fails to load the browser. However, you can also do it manually using the following command:
If you see this error message, you might have to install the dependencies manually.
host.browse
This function launches a new browser instance and optionally navigates to a page. The pages are automatically closed when the script ends.
You can configure a number of options for the browser instance:
Locators
You can select elements on the page using the page.get...
or page.locator
method.
Element contents
You can access innerHTML
, innerText
, value
and textContent
of an element.
You can use the parsers in HTML to convert the HTML to Markdown.
Screenshot
You can take a screenshot of the current page or a locator and use it with vision-enabled LLM (like gpt-4o
) using defImages
.
Interacting with Elements
(Advanced) Native Playwright APIs
The page
instance returned is a native Playwright Page object.
You can import playwright
and cast the instance back to the native Playwright object.