-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti_tab_example.py
35 lines (28 loc) · 980 Bytes
/
multi_tab_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from browser_use import Browser, BrowserConfig
from selenium_driverless import webdriver
import asyncio
async def main():
# Configure browser-use to connect to selenium-driverless instance
browser = Browser(
config=BrowserConfig(
wss_url='ws://localhost:3000' # Replace with your API URL
)
)
# Start browser and create new tabs
async with browser:
# Open first tab
tab1 = await browser.new_tab()
await tab1.goto('https://example.com')
# Open second tab
tab2 = await browser.new_tab()
await tab2.goto('https://google.com')
# Switch between tabs and perform operations
await tab1.bring_to_front()
print(f'Tab 1 title: {await tab1.title()}')
await tab2.bring_to_front()
print(f'Tab 2 title: {await tab2.title()}')
# Close tabs
await tab1.close()
await tab2.close()
if __name__ == '__main__':
asyncio.run(main())