fengmiguoji commited on
Commit
3656cb6
·
verified ·
1 Parent(s): a9a8ce1

Upload 2 files

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