-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add playwright for browser automation and update compile scripts to include as external * Add support for browser cleanup and image definition from buffers in templates * Add HTML to Markdown conversion support in BrowserPage and update dependencies * Add auto-playwright and sanitize-html dependencies, implement HTMLToMarkdown conversion in core package * add HTML global type * Add installation instructions and script metadata for browse function * Add exec and browse method documentation to ShellHost interface * Remove HTMLToMarkdown import from playwright CLI module
- Loading branch information
Showing
35 changed files
with
3,128 additions
and
59 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
title: Browse | ||
sidebar: | ||
order: 30 | ||
--- | ||
|
||
GenAIScript provides a simplified API to interact with a headless browser using [Playwright](https://playwright.dev/) . | ||
This allows you to interact with web pages, scrape data, and automate tasks. | ||
|
||
```js | ||
const page = await host.browse( | ||
"https://github.com/microsoft/genaiscript/blob/main/packages/sample/src/penguins.csv" | ||
) | ||
const table = page.locator('table[data-testid="csv-table"]') | ||
const csv = parsers.HTMLToMarkdown(await table.innerHTML()) | ||
def("DATA", csv) | ||
$`Analyze DATA.` | ||
``` | ||
|
||
## Installation | ||
|
||
You will need to install Playright locally before using the `browse` function. | ||
|
||
```bash | ||
npx playwright install-deps chromium | ||
``` | ||
|
||
## `host.browse` | ||
|
||
This function launches a new browser instance and optionally navigates to the page. | ||
|
||
```js | ||
const page = await host.browse(url) | ||
``` | ||
|
||
You can configure a number of options for the browser instance: | ||
|
||
```js | ||
const page = await host.browse(url, { incognito: true }) | ||
``` | ||
|
||
## (Advanced) Native Playwright APIs | ||
|
||
The `page` instance returned is a native [Playwright Page](https://playwright.dev/docs/api/class-page) object. | ||
You can import `playwright` and case the instance back to the native playwright object. | ||
|
||
```js | ||
import { Page } from "playwright" | ||
|
||
const page = await host.browse(url) as Page | ||
``` |
Oops, something went wrong.