Josedcape commited on
Commit
302f75f
·
verified ·
1 Parent(s): 85d7952

Upload 2 files

Browse files
Files changed (1) hide show
  1. src/custom_controller.py +27 -0
src/custom_controller.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pyperclip
2
+ from browser_use.agent.views import ActionResult
3
+ from browser_use.browser.context import BrowserContext
4
+ from browser_use.controller.service import Controller
5
+
6
+
7
+ class CustomController(Controller):
8
+ def __init__(self):
9
+ super().__init__()
10
+ self._register_custom_actions()
11
+
12
+ def _register_custom_actions(self):
13
+ """Register all custom browser actions"""
14
+
15
+ @self.registry.action("Copy text to clipboard")
16
+ def copy_to_clipboard(text: str):
17
+ pyperclip.copy(text)
18
+ return ActionResult(extracted_content=text)
19
+
20
+ @self.registry.action("Paste text from clipboard", requires_browser=True)
21
+ async def paste_from_clipboard(browser: BrowserContext):
22
+ text = pyperclip.paste()
23
+ # send text to browser
24
+ page = await browser.get_current_page()
25
+ await page.keyboard.type(text)
26
+
27
+ return ActionResult(extracted_content=text)