SilviuMatei commited on
Commit
c935f69
·
verified ·
1 Parent(s): 1aa340c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -26
app.py CHANGED
@@ -7,38 +7,32 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
10
- from selenium import webdriver
11
- from selenium.webdriver.chrome.options import Options
12
 
13
  @tool
14
  def get_device_info() -> str:
15
  """
16
- Opens a headless browser and executes JavaScript to silently retrieve device information.
17
 
18
  Returns:
19
  str: A string containing device details such as user agent, platform, and screen resolution.
20
  """
21
- options = Options()
22
- options.add_argument("--headless")
23
- options.add_argument("--disable-gpu")
24
- options.add_argument("--no-sandbox")
25
- options.add_argument("--disable-dev-shm-usage")
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
- driver = webdriver.Chrome(options=options)
28
-
29
- script = """
30
- return JSON.stringify({
31
- userAgent: navigator.userAgent,
32
- platform: navigator.platform,
33
- language: navigator.language,
34
- screenWidth: window.screen.width,
35
- screenHeight: window.screen.height
36
- });
37
- """
38
-
39
- driver.get("data:text/html,<script>document.title='device_info';</script>")
40
- device_info = driver.execute_script(script)
41
- driver.quit()
42
-
43
- return device_info
44
-
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
+ import playwright.sync_api as playwright
 
11
 
12
  @tool
13
  def get_device_info() -> str:
14
  """
15
+ Opens a headless browser using Playwright and executes JavaScript to silently retrieve device information.
16
 
17
  Returns:
18
  str: A string containing device details such as user agent, platform, and screen resolution.
19
  """
20
+ with playwright.sync_api.sync_playwright() as p:
21
+ browser = p.chromium.launch(headless=True)
22
+ page = browser.new_page()
23
+
24
+ script = """
25
+ () => JSON.stringify({
26
+ userAgent: navigator.userAgent,
27
+ platform: navigator.platform,
28
+ language: navigator.language,
29
+ screenWidth: window.screen.width,
30
+ screenHeight: window.screen.height
31
+ })
32
+ """
33
+
34
+ page.goto("about:blank")
35
+ device_info = page.evaluate(script)
36
+ browser.close()
37
 
38
+ return device_info