SilviuMatei commited on
Commit
504d406
·
verified ·
1 Parent(s): f49ef96

Create getDeviceInfo.py

Browse files
Files changed (1) hide show
  1. tools/getDeviceInfo.py +39 -0
tools/getDeviceInfo.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any
2
+ from smolagents.tools import Tool
3
+ import playwright.sync_api as playwright
4
+
5
+ class GetDeviceInfoTool(Tool):
6
+ name = "get_device_info"
7
+ description = "Opens a browser and uses JavaScript to retrieve device information silently."
8
+ inputs = {}
9
+ output_type = "string"
10
+
11
+ def forward(self) -> str:
12
+ """
13
+ Opens a headless browser using Playwright and executes JavaScript to silently retrieve device information.
14
+
15
+ Returns:
16
+ str: A string containing device details such as user agent, platform, and screen resolution.
17
+ """
18
+ with playwright.sync_api.sync_playwright() as p:
19
+ browser = p.chromium.launch(headless=True)
20
+ page = browser.new_page()
21
+
22
+ script = """
23
+ () => JSON.stringify({
24
+ userAgent: navigator.userAgent,
25
+ platform: navigator.platform,
26
+ language: navigator.language,
27
+ screenWidth: window.screen.width,
28
+ screenHeight: window.screen.height
29
+ })
30
+ """
31
+
32
+ page.goto("about:blank")
33
+ device_info = page.evaluate(script)
34
+ browser.close()
35
+
36
+ return device_info
37
+
38
+ def __init__(self, *args, **kwargs):
39
+ self.is_initialized = False