fix: use WebDriver new_window instead of JS window.open in tab_restart_browser#1146
fix: use WebDriver new_window instead of JS window.open in tab_restart_browser#1146
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a browser restart issue where popup-blocking preferences break tab restarting. The fix replaces a legacy Selenium 3 workaround with Selenium 4's native new_window() method, which bypasses content-level popup blocking.
Changes:
- Replace JavaScript
window.open('')with WebDriver'sswitch_to.new_window("window")intab_restart_browser() - Add regression test that enables popup blocking and verifies two visits complete successfully
- Document the previously-undocumented
prefsfield inBrowserParamsconfiguration
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| openwpm/commands/browser_commands.py | Replaces JS-based window creation with WebDriver protocol to avoid popup blocking issues |
| test/test_simple_commands.py | Adds regression test verifying visits work with popup blocking enabled |
| docs/Configuration.md | Documents the prefs field for setting custom Firefox preferences |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
03c7dfd to
b390ab7
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1146 +/- ##
==========================================
+ Coverage 56.62% 56.75% +0.13%
==========================================
Files 40 40
Lines 3910 3908 -2
==========================================
+ Hits 2214 2218 +4
+ Misses 1696 1690 -6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Using "window" instead of "tab" created an isolated cache context, causing test_cache_hits_recorded to fail with extra uncached requests.
b390ab7 to
0f03c2f
Compare
Fix black formatting, mypy errors (duplicate sleep arg, missing return type).
2f4a230 to
a5fa580
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bcd9fcc to
790e94c
Compare
Use new_window("tab") for tab_restart_browser — not subject to popup
blocking. Update HTTP_CACHED_REQUESTS to include resources re-fetched
due to the new tab having an isolated cache context.
Remove stealth extension files accidentally included in this branch.
790e94c to
457d53b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "image", | ||
| ), | ||
| # Resources re-requested when the tab restart opens a new tab; served from | ||
| # the shared HTTP cache (is_cached=1 in HTTP_CACHED_RESPONSES). |
There was a problem hiding this comment.
The new expectations add cached image/css entries for the second visit, but test_cache_hits_recorded’s docstring later in this file still states that cached images do not trigger the relevant instrumentation events. To avoid confusion for future maintenance, please update/clarify that docstring (or the inline comment here) to match the new observed behavior (i.e., which cached resource types are expected to appear in http_requests/http_responses).
| # the shared HTTP cache (is_cached=1 in HTTP_CACHED_RESPONSES). | |
| # the shared HTTP cache (is_cached=1 in HTTP_CACHED_RESPONSES), but still | |
| # expected to generate entries in http_requests/http_responses (for both | |
| # the cached stylesheet and cached images). |
Summary
window.open('')with Selenium 4'swebdriver.switch_to.new_window("tab")intab_restart_browser()dom.disable_open_during_load=True)prefsfield onBrowserParamsCloses #741
Closes #784
Test plan
test_get_with_popup_blockingpasses locallytest_get_site_visits_table_validstill passes (both headless and xvfb)black,isort,mypyall clean