-
Notifications
You must be signed in to change notification settings - Fork 6
Add browser use guide #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
7ba74bb
9949471
1d12cdd
1e2914b
ec2fa06
a2b4c5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| --- | ||
| title: "Browser Use" | ||
| --- | ||
|
|
||
| [Browser Use](https://github.com/browser-use/browser-use) is the AI browser agent that empowers anyone to automate repetitive online tasks, no code required. By integrating with Kernel, you can run Browser Use Agents and automations with cloud-hosted browsers. | ||
|
|
||
| ## Adding Kernel to existing Browser Use implementations | ||
|
|
||
| If you already have a Browser Use implementation, you can easily switch to using Kernel's cloud browsers by updating your Browser definition. | ||
|
|
||
| ### 1. Install the Kernel SDK | ||
|
|
||
| ```bash | ||
| pip install onkernel | ||
| ``` | ||
|
|
||
| ### 2. Initialize Kernel and create a browser | ||
|
|
||
| Import the libraries and create a cloud browser session: | ||
|
|
||
| ```python | ||
| from onkernel import Kernel | ||
| from browser_use import Browser, Agent | ||
|
|
||
| # Initialize Kernel client | ||
| kernel = Kernel(api_key="your-api-key") | ||
|
|
||
| # Create a Kernel browser session | ||
| kernel_browser = kernel.browsers.create() | ||
| ``` | ||
|
|
||
| ### 3. Update your Browser definition | ||
|
|
||
| Replace your existing Browser initialization to use Kernel's CDP URL and display settings: | ||
|
|
||
| ```python | ||
| # Update your Browser definition to use Kernel's CDP URL | ||
| browser = Browser( | ||
| cdp_url=kernel_browser.cdp_ws_url, | ||
| headless=False, | ||
| window_size={'width': 1024, 'height': 786}, | ||
| viewport={'width': 1024, 'height': 786}, | ||
| device_scale_factor=1.0 | ||
| ) | ||
| ``` | ||
|
|
||
| ### 4. Create and run your agent | ||
|
|
||
| Use your existing Agent setup with the Kernel-powered browser: | ||
|
|
||
| ```python | ||
| # Use with your existing Agent setup | ||
| agent = Agent( | ||
| task="Your automation task", | ||
| llm=your_llm_instance, | ||
| browser_session=browser | ||
| ) | ||
|
|
||
| # Run your automation | ||
| result = agent.run() | ||
|
|
||
| # Clean up | ||
| kernel.browsers.delete_by_id(kernel_browser.session_id) | ||
| ``` | ||
|
|
||
| <Info> | ||
| If you're using Browser Use versions `< 0.7.9`, you may need to use a [custom resize class](https://github.com/onkernel/create-kernel-app/blob/main/templates/python/browser-use/session.py) to correct viewport sizing for the browser session. Here's how to use it: | ||
|
|
||
| ```python | ||
| agent = Agent( | ||
| task="Your automation task", | ||
| llm=your_llm_instance, | ||
| browser_session=BrowserSessionCustomResize(cdp_url=kernel_browser.cdp_ws_url) | ||
| ) | ||
| ``` | ||
| </Info> | ||
|
|
||
| ## Quick setup with our Browser Use example app | ||
|
|
||
| Alternatively, you can use our Kernel app template that includes a pre-configured Browser Use integration: | ||
|
|
||
| ```bash | ||
| npx @onkernel/create-kernel-app my-browser-use-app | ||
| ``` | ||
|
|
||
| Choose Python as the programming language and then select `browser-use` as the template. | ||
|
|
||
| Then follow the [Quickstart guide](/quickstart/) to deploy and run your Browser Use automation on Kernel's infrastructure. | ||
|
|
||
| ## Benefits of using Kernel with Browser Use | ||
|
|
||
| - **No local browser management**: Run automations without installing or maintaining browsers locally | ||
| - **Scalability**: Launch multiple browser sessions in parallel | ||
| - **Stealth mode**: Built-in anti-detection features for web scraping | ||
| - **Session persistence**: Maintain browser state across automation runs | ||
| - **Live view**: Debug your automations with real-time browser viewing | ||
|
|
||
| ## Next steps | ||
|
|
||
| - Check out [live view](/browsers/live-view) for debugging your automations | ||
| - Learn about [stealth mode](/browsers/stealth) for avoiding detection | ||
| - Learn how to properly [terminate browser sessions](/browsers/termination) | ||
| - Learn how to [deploy](/apps/deploy) your Browser Use app to Kernel | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ client = Kernel( | |
| api_key="My API Key", | ||
| ) | ||
| client.browsers.delete_by_id( | ||
| "id", | ||
| "htzv5orfit78e1m2biiifpbv", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intentional?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope - wondering if that's from Hiro's work? I didn't change that
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ohhh good call |
||
| ) | ||
| ``` | ||
| </CodeGroup> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <CodeGroup> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this from another commit that's not yet in |
||
| ```typescript Typescript/Javascript | ||
| import Kernel from '@onkernel/sdk'; | ||
|
|
||
| const client = new Kernel({ | ||
| apiKey: 'My API Key', | ||
| }); | ||
|
|
||
| await client.proxies.delete('id'); | ||
| ``` | ||
|
|
||
|
|
||
| ```python Python | ||
| from kernel import Kernel | ||
|
|
||
| client = Kernel( | ||
| api_key="My API Key", | ||
| ) | ||
| client.proxies.delete( | ||
| "id", | ||
| ) | ||
| ``` | ||
| </CodeGroup> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <CodeGroup> | ||
| ```typescript Typescript/Javascript | ||
| import Kernel from '@onkernel/sdk'; | ||
|
|
||
| const client = new Kernel({ | ||
| apiKey: 'My API Key', | ||
| }); | ||
|
|
||
| const proxy = await client.proxies.retrieve('id'); | ||
|
|
||
| console.log(proxy.id); | ||
| ``` | ||
|
|
||
|
|
||
| ```python Python | ||
| from kernel import Kernel | ||
|
|
||
| client = Kernel( | ||
| api_key="My API Key", | ||
| ) | ||
| proxy = client.proxies.retrieve( | ||
| "id", | ||
| ) | ||
| print(proxy.id) | ||
| ``` | ||
| </CodeGroup> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <CodeGroup> | ||
| ```typescript Typescript/Javascript | ||
| import Kernel from '@onkernel/sdk'; | ||
|
|
||
| const client = new Kernel({ | ||
| apiKey: 'My API Key', | ||
| }); | ||
|
|
||
| const proxies = await client.proxies.list(); | ||
|
|
||
| console.log(proxies); | ||
| ``` | ||
|
|
||
|
|
||
| ```python Python | ||
| from kernel import Kernel | ||
|
|
||
| client = Kernel( | ||
| api_key="My API Key", | ||
| ) | ||
| proxies = client.proxies.list() | ||
| print(proxies) | ||
| ``` | ||
| </CodeGroup> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <CodeGroup> | ||
| ```typescript Typescript/Javascript | ||
| import Kernel from '@onkernel/sdk'; | ||
|
|
||
| const client = new Kernel({ | ||
| apiKey: 'My API Key', | ||
| }); | ||
|
|
||
| const proxy = await client.proxies.create({ type: 'datacenter' }); | ||
|
|
||
| console.log(proxy.id); | ||
| ``` | ||
|
|
||
|
|
||
| ```python Python | ||
| from kernel import Kernel | ||
|
|
||
| client = Kernel( | ||
| api_key="My API Key", | ||
| ) | ||
| proxy = client.proxies.create( | ||
| type="datacenter", | ||
| ) | ||
| print(proxy.id) | ||
| ``` | ||
| </CodeGroup> |
Uh oh!
There was an error while loading. Please reload this page.