Skip to content

Commit 60b1153

Browse files
author
Shriyansh Agnihotri
authored
Adding browser resolutuion feature for chrome and resolving P0 bug of new installation with HF_HOME envrionment variable (#18)
### Summary 📝 Adding browser resolution feature for chrome and resolving P0 bug of new installation with HF_HOME envrionment variable ### Details 1. Borwser resolution feature for chrome ### Bugfixes 🐛 Blocker for installation, caused because HF_HOME env variable not handled properly in 0.0.20
1 parent 64634d5 commit 60b1153

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

.env-example

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ PROJECT_SOURCE_ROOT=folder where to save data.
1212

1313
TOKENIZERS_PARALLELISM=false
1414
MODE=prod
15-
HEADLESS=true
15+
HEADLESS=false
1616
RECORD_VIDEO=false
17-
TAKE_SCREENSHOTS=false
17+
TAKE_SCREENSHOTS=true
1818
BROWSER_TYPE=chromium
19-
CAPTURE_NETWORK=false
19+
CAPTURE_NETWORK=true
2020
HF_HOME=./.cache
21+
BROWSER_RESOLUTION=1920,1080

helper_scripts/hercules_setup.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -ex
23

34
# curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11
45

@@ -18,8 +19,15 @@ export HEADLESS=false
1819
# create a new directory named 'opt'
1920
mkdir -p opt/input opt/output opt/test_data
2021

21-
# create a intput/test.feature file
22-
echo "Feature: Open Google homepage\nScenario: User opens Google homepage\n Given I have a web browser open\n When I navigate to https://www.google.com\n Then I should see the Google homepage" > opt/input/test.feature
22+
# create a input/test.feature file
23+
cat << 'EOF' > opt/input/test.feature
24+
Feature: Open Google homepage
25+
26+
Scenario: User opens Google homepage
27+
Given I have a web browser open
28+
When I navigate to https://www.google.com
29+
Then I should see the Google homepage
30+
EOF
2331

2432
# get gpt-4o model API key by asking user
2533
echo "Enter your GPT-4o model API key:"

testzeus_hercules/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def _merge_from_env(self) -> None:
165165
"TOKENIZERS_PARALLELISM",
166166
"DONT_CLOSE_BROWSER",
167167
"TOKEN_VERBOSE",
168+
"BROWSER_RESOLUTION",
168169
]
169170

170171
for key in relevant_keys:
@@ -250,6 +251,7 @@ def _finalize_defaults(self) -> None:
250251
self._config["TOKENIZERS_PARALLELISM"] = "false"
251252

252253
self._config.setdefault("TOKEN_VERBOSE", "false")
254+
self._config.setdefault("BROWSER_RESOLUTION", "1920,1080")
253255

254256
# HEADLESS, RECORD_VIDEO, etc. can also be "finalized" here if needed
255257
self._config.setdefault("HEADLESS", "true")
@@ -309,6 +311,9 @@ def get_browser_type(self) -> str:
309311

310312
def should_capture_network(self) -> bool:
311313
return self._config["CAPTURE_NETWORK"].lower().strip() == "true"
314+
315+
def get_hf_home(self) -> str:
316+
return self._config["HF_HOME"]
312317

313318
# -------------------------------------------------------------------------
314319
# Directory creation logic (mirroring your original code)
@@ -374,6 +379,9 @@ def get_project_temp_path(self, test_id: Optional[str] = None) -> str:
374379

375380
def get_token_verbose(self) -> bool:
376381
return self._config["TOKEN_VERBOSE"].lower().strip() == "true"
382+
383+
def get_resolution(self) -> str:
384+
return self._config["BROWSER_RESOLUTION"]
377385

378386
# -------------------------------------------------------------------------
379387
# Telemetry

testzeus_hercules/core/playwright_manager.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,26 @@ async def prepare_extension(self) -> None:
220220

221221
async def create_browser_context(self) -> None:
222222
user_dir: str = os.environ.get("BROWSER_STORAGE_DIR", "")
223+
resolution: str = CONF.get_resolution()
223224
disable_args = [
224-
"--disable-blink-features=AutomationControlled",
225225
"--disable-session-crashed-bubble",
226+
"--disable-notifications",
227+
"--no-sandbox",
228+
"--disable-blink-features=AutomationControlled",
226229
"--disable-infobars",
230+
"--disable-background-timer-throttling",
227231
"--disable-popup-blocking",
228-
"--disable-notifications",
232+
"--disable-backgrounding-occluded-windows",
233+
"--disable-renderer-backgrounding",
234+
"--disable-window-activation",
235+
"--disable-focus-on-load",
236+
"--no-first-run",
237+
"--no-default-browser-check",
238+
"--window-position=0,0",
239+
"--disable-web-security",
240+
"--disable-site-isolation-trials",
241+
"--disable-features=IsolateOrigins,site-per-process",
242+
f"--window-size={resolution}",
229243
]
230244
if self.cdp_config:
231245
# Connect over CDP

testzeus_hercules/core/tools/api_sec_calls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from testzeus_hercules.utils.logger import logger
1616

1717
# Define cache and binary paths
18-
CACHE_DIR = Path(os.environ["HF_HOME"]) / "nuclei_tool"
18+
CACHE_DIR = Path(CONF.get_hf_home()) / "nuclei_tool"
1919
NUCLEI_BINARY = CACHE_DIR / "nuclei"
2020

2121

0 commit comments

Comments
 (0)