An archive detects a browser when the configured one is not installed (#895)

A configured browser_executable was used without checking it exists.  A config on the media drive can outlive the
OS it was written on: Raspberry Pi OS's /usr/bin/chromium-browser is /usr/bin/chromium on Debian.  The wrapper
discards the browser's stderr, so its failed exec only showed as single-file's "Connection refused ... Child
process has already terminated", and every archive failed.  Now a missing configured browser is logged and one is
detected, as when none is configured.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lrnselfreliance 2026-10-27 18:58:52 -06:00 • committed by Roland
parent 9352002d07
commit 3c815245b4
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
2 changed files with 37 additions and 6 deletions

View file

@ -9,7 +9,7 @@ from typing import Callable, List, Optional, Tuple
from sqlalchemy import text
from sqlalchemy.orm import Session
from wrolpi.cmd import SINGLE_FILE_BIN, CHROMIUM, FIREFOX, DENO_BIN, SINGLE_FILE_DENO_SCRIPT
from wrolpi.cmd import SINGLE_FILE_BIN, CHROMIUM, FIREFOX, DENO_BIN, SINGLE_FILE_DENO_SCRIPT, which
from wrolpi.collections import Collection
from wrolpi.common import logger, register_modeler, register_refresh_cleanup, limit_concurrent, split_lines_by_length, \
slow_logger, get_title_from_html, strip_surrogates, TRACE_LEVEL
@ -137,11 +137,14 @@ class ArchiveDownloader(Downloader, ABC):
config = lib.get_archive_downloader_config()
# Determine browser executable
browser_executable = config.browser_executable
if browser_executable:
# Use configured browser path
browser = browser_executable
else:
browser = None
if browser_executable := config.browser_executable:
# Use the configured browser, if it is installed. A config can outlive the OS it was written on (e.g.
# Raspberry Pi OS names Chromium "chromium-browser").
if not (browser := which(browser_executable)):
logger.warning(f'Configured browser_executable is not installed, detecting a browser instead:'
f' {browser_executable}')
if not browser:
# Auto-detect: prefer Chromium, fallback to Firefox
browser = CHROMIUM or FIREFOX
if not browser:

View file

@ -238,3 +238,31 @@ async def test_finalize_adds_tags(async_client, test_session, test_directory, ta
assert len(archives) == 1
archive_tag_names = [tf.tag.name for tf in archives[0].file_group.tag_files]
assert tag.name in archive_tag_names
@pytest.mark.asyncio
@pytest.mark.parametrize('configured, expected', [
# A config can outlive the OS it was written on: Raspberry Pi OS names Chromium "chromium-browser".
('/nonexistent/chromium-browser', '/usr/bin/chromium'),
(None, '/usr/bin/chromium'),
('/bin/sh', '/bin/sh'),
])
async def test_do_singlefile_configured_browser(test_session, test_directory, monkeypatch, configured, expected):
"""The configured browser is used when it is installed; otherwise one is detected."""
from types import SimpleNamespace
import modules.archive
singlefile = b'<html><!--\n Page saved with SingleFile \n url: https://example.com \n--></html>'
process_runner, calls = make_process_runner_recorder(singlefile)
monkeypatch.setattr(modules.archive, 'DENO_BIN', '/usr/local/bin/deno')
monkeypatch.setattr(modules.archive, 'SINGLE_FILE_DENO_SCRIPT',
'/usr/local/lib/node_modules/single-file-cli/single-file')
monkeypatch.setattr(modules.archive, 'CHROMIUM', '/usr/bin/chromium')
monkeypatch.setattr(archive_downloader, 'process_runner', process_runner)
monkeypatch.setattr(modules.archive.lib, 'get_archive_downloader_config',
lambda: SimpleNamespace(browser_executable=configured, browser_args=None, user_agent=None))
prepared = PreparedArchive(url='https://example.com', destination=None, settings={})
await archive_downloader.do_singlefile(prepared, make_test_ctx())
capture, = calls
assert capture['env']['WROLPI_BROWSER'] == expected