Skip to content

Commit b4a4716

Browse files
authored
Fix: Change Playwright browser tool from sync to async (#17808)
1 parent 50a4a9d commit b4a4716

File tree

7 files changed

+580
-146
lines changed

7 files changed

+580
-146
lines changed

llama-index-integrations/tools/llama-index-tools-playwright/README.md

+23-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
This tool is a wrapper around the Playwright library. It allows you to navigate to a website, extract text and hyperlinks, and click on elements.
44

5+
> **Warning**
6+
> Only support async functions and playwright browser APIs.
7+
58
## Installation
69

710
```
@@ -10,55 +13,65 @@ pip install llama-index-tools-playwright
1013

1114
## Setup
1215

13-
In order to use this tool, you need to have a sync Playwright browser instance. You can hook one up by running the following code:
16+
In order to use this tool, you need to have a async Playwright browser instance. You can hook one up by running the following code:
1417

1518
```python
16-
browser = PlaywrightToolSpec.create_sync_playwright_browser(headless=False)
17-
playwright_tool = PlaywrightToolSpec.from_sync_browser(browser)
19+
browser = PlaywrightToolSpec.create_async_playwright_browser(headless=False)
20+
playwright_tool = PlaywrightToolSpec.from_async_browser(browser)
1821
```
1922

2023
## Usage
2124

2225
### Navigate to a website
2326

2427
```python
25-
playwright_tool.navigate_to("https://playwright.dev/python/docs/intro")
28+
await playwright_tool.navigate_to("https://playwright.dev/python/docs/intro")
29+
```
30+
31+
### Navigate back
32+
33+
```python
34+
await playwright_tool.navigate_back()
2635
```
2736

2837
### Get current page URL
2938

3039
```python
31-
playwright_tool.get_current_page()
40+
await playwright_tool.get_current_page()
3241
```
3342

3443
### Extract all hyperlinks
3544

3645
```python
37-
playwright_tool.extract_hyperlinks()
46+
await playwright_tool.extract_hyperlinks()
3847
```
3948

4049
### Extract all text
4150

4251
```python
43-
playwright_tool.extract_text()
52+
await playwright_tool.extract_text()
4453
```
4554

4655
### Get element attributes
4756

4857
```python
49-
element = playwright_tool.get_elements(
58+
element = await playwright_tool.get_elements(
5059
selector="ELEMENT_SELECTOR", attributes=["innerText"]
5160
)
5261
```
5362

5463
### Click on an element
5564

5665
```python
57-
playwright_tool.click(selector="ELEMENT_SELECTOR")
66+
await playwright_tool.click(selector="ELEMENT_SELECTOR")
5867
```
5968

6069
### Fill in an input field
6170

6271
```python
63-
playwright_tool.fill(selector="ELEMENT_SELECTOR", value="Hello")
72+
await playwright_tool.fill(selector="ELEMENT_SELECTOR", value="Hello")
6473
```
74+
75+
## Agentic Usage
76+
77+
This tool has a more extensive example usage documented in a Jupyter notebook [here](https://github.com/run-llama/llama_index/blob/main/llama-index-integrations/tools/llama-index-tools-playwright/examples/playwright_browser_agent.ipynb)

llama-index-integrations/tools/llama-index-tools-playwright/examples/BUILD

-1
This file was deleted.

0 commit comments

Comments
 (0)