[PR #1737] [MERGED] Reduce code duplication between Chrome utilities #1487

Closed
opened 2026-03-01 14:50:00 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ArchiveBox/ArchiveBox/pull/1737
Author: @pirate
Created: 12/31/2025
Status: Merged
Merged: 12/31/2025
Merged by: @pirate

Base: devHead: claude/reduce-chrome-duplication-JgWVr


📝 Commits (1)

  • fd9ba86 Reduce Chrome-related code duplication across JS and Python

📊 Changes

8 files changed (+469 additions, -401 deletions)

View changed files

📝 archivebox/plugins/chrome/chrome_utils.js (+118 -0)
📝 archivebox/plugins/chrome/on_Crawl__30_chrome_launch.bg.js (+2 -2)
archivebox/plugins/chrome/tests/chrome_test_helpers.py (+276 -0)
📝 archivebox/plugins/infiniscroll/tests/test_infiniscroll.py (+25 -111)
📝 archivebox/plugins/istilldontcareaboutcookies/on_Crawl__20_install_istilldontcareaboutcookies_extension.js (+5 -61)
📝 archivebox/plugins/modalcloser/tests/test_modalcloser.py (+25 -98)
📝 archivebox/plugins/twocaptcha/on_Crawl__20_install_twocaptcha_extension.js (+13 -68)
📝 archivebox/plugins/ublock/on_Crawl__20_install_ublock_extension.js (+5 -61)

📄 Description

This change consolidates duplicated logic between chrome_utils.js and extension installer hooks, as well as between Python plugin tests:

JavaScript changes:

  • Add getExtensionsDir() to centralize extension directory path calculation
  • Add installExtensionWithCache() to handle extension install + cache workflow
  • Add CLI commands for new utilities
  • Refactor all 3 extension installers (ublock, istilldontcareaboutcookies, twocaptcha) to use shared utilities, reducing each from ~115 lines to ~60
  • Update chrome_launch hook to use getExtensionsDir()

Python test changes:

  • Add chrome_test_helpers.py with shared Chrome session management utilities
  • Refactor infiniscroll and modalcloser tests to use shared helpers
  • setup_chrome_session(), cleanup_chrome(), get_test_env() now centralized
  • Add chrome_session() context manager for automatic cleanup

Net result: ~208 lines of code removed while maintaining same functionality.

Summary

Related issues

Changes these areas

  • Bugfixes
  • Feature behavior
  • Command line interface
  • Configuration options
  • Internal architecture
  • Snapshot data layout on disk

Summary by cubic

Consolidated Chrome extension path/install logic and unified Python test helpers to reduce duplication with no behavior changes. This removes ~208 LOC and makes extension installers and tests simpler to maintain.

  • New Features

    • getExtensionsDir() centralizes extension dir resolution (env override supported).
    • installExtensionWithCache() handles install + cache read/write.
    • Added CLI commands for both utilities.
  • Refactors

    • uBlock, I Still Don’t Care About Cookies, and 2captcha installers now use shared utilities.
    • chrome_launch hook now uses getExtensionsDir().
    • Added chrome_test_helpers.py (get_test_env, setup_chrome_session, cleanup_chrome, chrome_session); updated infiniscroll and modalcloser tests to use it.

Written for commit fd9ba86220. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ArchiveBox/ArchiveBox/pull/1737 **Author:** [@pirate](https://github.com/pirate) **Created:** 12/31/2025 **Status:** ✅ Merged **Merged:** 12/31/2025 **Merged by:** [@pirate](https://github.com/pirate) **Base:** `dev` ← **Head:** `claude/reduce-chrome-duplication-JgWVr` --- ### 📝 Commits (1) - [`fd9ba86`](https://github.com/ArchiveBox/ArchiveBox/commit/fd9ba86220479c7b2406644e79871334fed9887a) Reduce Chrome-related code duplication across JS and Python ### 📊 Changes **8 files changed** (+469 additions, -401 deletions) <details> <summary>View changed files</summary> 📝 `archivebox/plugins/chrome/chrome_utils.js` (+118 -0) 📝 `archivebox/plugins/chrome/on_Crawl__30_chrome_launch.bg.js` (+2 -2) ➕ `archivebox/plugins/chrome/tests/chrome_test_helpers.py` (+276 -0) 📝 `archivebox/plugins/infiniscroll/tests/test_infiniscroll.py` (+25 -111) 📝 `archivebox/plugins/istilldontcareaboutcookies/on_Crawl__20_install_istilldontcareaboutcookies_extension.js` (+5 -61) 📝 `archivebox/plugins/modalcloser/tests/test_modalcloser.py` (+25 -98) 📝 `archivebox/plugins/twocaptcha/on_Crawl__20_install_twocaptcha_extension.js` (+13 -68) 📝 `archivebox/plugins/ublock/on_Crawl__20_install_ublock_extension.js` (+5 -61) </details> ### 📄 Description This change consolidates duplicated logic between chrome_utils.js and extension installer hooks, as well as between Python plugin tests: JavaScript changes: - Add getExtensionsDir() to centralize extension directory path calculation - Add installExtensionWithCache() to handle extension install + cache workflow - Add CLI commands for new utilities - Refactor all 3 extension installers (ublock, istilldontcareaboutcookies, twocaptcha) to use shared utilities, reducing each from ~115 lines to ~60 - Update chrome_launch hook to use getExtensionsDir() Python test changes: - Add chrome_test_helpers.py with shared Chrome session management utilities - Refactor infiniscroll and modalcloser tests to use shared helpers - setup_chrome_session(), cleanup_chrome(), get_test_env() now centralized - Add chrome_session() context manager for automatic cleanup Net result: ~208 lines of code removed while maintaining same functionality. <!-- IMPORTANT: Do not submit PRs with only formatting / PEP8 / line length changes. --> # Summary <!--e.g. This PR fixes ABC or adds the ability to do XYZ...--> # Related issues <!-- e.g. #123 or Roadmap goal # https://github.com/pirate/ArchiveBox/wiki/Roadmap --> # Changes these areas - [ ] Bugfixes - [ ] Feature behavior - [ ] Command line interface - [ ] Configuration options - [ ] Internal architecture - [ ] Snapshot data layout on disk <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Consolidated Chrome extension path/install logic and unified Python test helpers to reduce duplication with no behavior changes. This removes ~208 LOC and makes extension installers and tests simpler to maintain. - **New Features** - getExtensionsDir() centralizes extension dir resolution (env override supported). - installExtensionWithCache() handles install + cache read/write. - Added CLI commands for both utilities. - **Refactors** - uBlock, I Still Don’t Care About Cookies, and 2captcha installers now use shared utilities. - chrome_launch hook now uses getExtensionsDir(). - Added chrome_test_helpers.py (get_test_env, setup_chrome_session, cleanup_chrome, chrome_session); updated infiniscroll and modalcloser tests to use it. <sup>Written for commit fd9ba86220479c7b2406644e79871334fed9887a. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-01 14:50:00 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ArchiveBox#1487
No description provided.