Initial commit
This commit is contained in:
commit
52ddc6ba9a
27 files changed
+2166
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import asyncio
|
||||
from typing import Any, Dict
|
||||
from tools.utils import ToolError
|
||||
|
||||
async def handle(args: Dict[str, Any], bridge: Any) -> list:
|
||||
"""
|
||||
Executes arbitrary JavaScript in the current page.
|
||||
"""
|
||||
js_code = args.get("js_code")
|
||||
if not js_code:
|
||||
raise ToolError("Missing required argument: 'js_code'")
|
||||
|
||||
request_id = f"req_{asyncio.get_event_loop().time()}_{id(args)}"
|
||||
params: Dict[str, Any] = {"js_code": str(js_code)}
|
||||
if args.get("window_id") is not None:
|
||||
params["window_id"] = int(args["window_id"])
|
||||
if args.get("tab_id") is not None:
|
||||
params["tab_id"] = int(args["tab_id"])
|
||||
|
||||
result = await bridge.send_to_extension(request_id, "execute_script", params)
|
||||
|
||||
output = result.get("result", "") if isinstance(result, dict) else str(result)
|
||||
|
||||
return [{"type": "text", "text": f"Script result:\n{output}"}]
|
||||
Reference in new issue
Block a user