Fix chrome user data dir problem (#2503)

This commit is contained in:
Shuchang Zheng
2025-05-28 22:41:06 -07:00
committed by GitHub
parent 869757398a
commit cf08ca951e
11 changed files with 283 additions and 85 deletions

View File

@@ -67,9 +67,9 @@ skyvern = Skyvern()
task = await skyvern.run_task(prompt="Find the top post on hackernews today")
print(task)
```
A browser will pop up. Skyvern will start executing the task in the browser and close the it when the task is done. You will be able to review the task from http://localhost:8080/history
Skyvern starts running the task in a browser that pops up and closes it when the task is done. You will be able to review the task from http://localhost:8080/history
You can also run a task autonomously on Skyvern Cloud:
You can also run a task on Skyvern Cloud:
```python
from skyvern import Skyvern
@@ -78,28 +78,65 @@ task = await skyvern.run_task(prompt="Find the top post on hackernews today")
print(task)
```
Or any hosted Skyvern service:
Or your local Skyvern service from step 2:
```python
skyvern = Skyvern(base_url="http://localhost:8000", api_key="SKYVERN API KEY")
skyvern = Skyvern(base_url="http://localhost:8000", api_key="LOCAL SKYVERN API KEY")
task = await skyvern.run_task(prompt="Find the top post on hackernews today")
print(task)
```
Check out more features to use for Skyvern task in our [official doc](https://docs.skyvern.com/running-tasks/run-tasks). Here are a couple of interesting examples:
#### Let Skyvern control your own browser
Firstly, add two variables to your .env file:
#### Control your own browser (Chrome)
> ⚠️ WARNING: Since [Chrome 136](https://developer.chrome.com/blog/remote-debugging-port), Chrome refuses any CDP connect to the browser using the default user_data_dir. In order to use your browser data, Skyvern copies your default user_data_dir to `./tmp/user_data_dir` the first time connecting to your local browser. ⚠️
1. Just With Python Code
```python
from skyvern import Skyvern
# The path to your Chrome browser. This example path is for Mac.
browser_path = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
skyvern = Skyvern(
base_url="http://localhost:8000",
api_key="YOUR_API_KEY",
browser_path=browser_path,
)
task = await skyvern.run_task(
prompt="Find the top post on hackernews today",
)
```
# This is the path to your local chromium-compatible browser. We're using Google Chrome in Mac as an example
2. With Skyvern Service
Add two variables to your .env file:
```bash
# The path to your Chrome browser. This example path is for Mac.
CHROME_EXECUTABLE_PATH="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
BROWSER_TYPE=cdp-connect
```
Secondly, make sure you quit your browser (Skyvern will restart it) and run the task:
Restart Skyvern service `skyvern run all` and run the task through UI or code:
```python
from skyvern import Skyvern
skyvern = Skyvern()
task = await skyvern.run_task(prompt="Find the top post on hackernews today")
skyvern = Skyvern(
base_url="http://localhost:8000",
api_key="YOUR_API_KEY",
)
task = await skyvern.run_task(
prompt="Find the top post on hackernews today",
)
```
#### Run Skyvern with any remote browser
Grab the cdp connection url and pass it to Skyvern
```python
from skyvern import Skyvern
skyvern = Skyvern(cdp_url="your cdp connection url")
task = await skyvern.run_task(
prompt="Find the top post on hackernews today",
)
```
#### Get consistent output schema from your run
@@ -130,7 +167,6 @@ task = await skyvern.run_task(
)
```
### Helpful commands to debug issues
**Launch the Skyvern Server Separately**