Jens c212113638 fix: improve Windows browser autodetection paths and diagnose fallback (#816)
## ℹ️ Description
This pull request fixes Windows browser auto-detection failures reported
by users where `diagnose`/startup could not find an installed browser
even when Chrome or Edge were present in standard locations. It also
makes diagnostics resilient when auto-detection fails by avoiding an
assertion-driven abort and continuing with a clear failure log.

- Link to the related issue(s): Issue #815
- Describe the motivation and context for this change.
- Users reported `Installed browser could not be detected` on Windows
despite having a browser installed.
- The previous Windows candidate list used a mix of incomplete paths and
direct `os.environ[...]` lookups that could raise when variables were
missing.
- The updated path candidates and ordering were aligned with common
Windows install locations used by Playwright’s channel/executable
resolution logic (Chrome/Edge under `LOCALAPPDATA`, `PROGRAMFILES`, and
`PROGRAMFILES(X86)`).

## 📋 Changes Summary
- Expanded Windows browser path candidates in `get_compatible_browser()`
to include common Google Chrome and Microsoft Edge install paths, while
keeping Chromium and PATH fallbacks.
- Replaced unsafe direct env-var indexing with safe retrieval
(`os.environ.get(...)`) and added a fallback derivation for
`LOCALAPPDATA` via `USERPROFILE\\AppData\\Local` when needed.
- Kept legacy Chrome path candidates
(`...\\Chrome\\Application\\chrome.exe`) as compatibility fallback.
- Updated diagnostics flow to catch browser auto-detection assertion
failures and continue with `(fail) No compatible browser found` instead
of crashing.
- Added/updated unit tests to verify:
  - Windows detection for LocalAppData Chrome/Edge/Chromium paths.
- Missing Windows env vars no longer cause key lookup failures and still
surface the intended final detection assertion.
- `diagnose_browser_issues()` handles auto-detection assertion failures
without raising and logs the expected failure message.


### ⚙️ Type of Change
Select the type(s) of change(s) included in this pull request:
- [x] 🐞 Bug fix (non-breaking change which fixes an issue)


##  Checklist
Before requesting a review, confirm the following:
- [x] I have reviewed my changes to ensure they meet the project's
standards.
- [x] I have tested my changes and ensured that all tests pass (`pdm run
test`).
- [x] I have formatted the code (`pdm run format`).
- [x] I have verified that linting passes (`pdm run lint`).
- [x] I have updated documentation where necessary.

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Hardened Windows browser auto-detection: checks additional common
installation locations for Chrome/Chromium/Edge and treats detection
failures as non-fatal, allowing diagnostics to continue with fallback
behavior and debug logging when no browser is found.

* **Tests**
* Expanded Windows detection tests to cover more path scenarios and
added cases verifying failure-mode diagnostics and logging.

* **Style**
  * Minor formatting tweak in default configuration.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-09 19:55:05 +01:00
2025-10-14 15:56:35 +02:00
2022-01-11 13:45:20 +01:00
2025-05-15 19:52:41 +02:00
2022-08-21 20:29:55 +02:00
2022-01-11 13:45:20 +01:00
2025-11-16 17:50:04 +01:00

kleinanzeigen-bot

Build Status License Contributor Covenant codecov

Feedback and high-quality pull requests are highly welcome!

  1. About
  2. Installation
  3. Usage
  4. Configuration
    1. Main configuration
    2. Ad configuration
    3. Using an existing browser window
    4. Browser Connection Issues
  5. Development Notes
  6. Related Open-Source Projects
  7. License

About

kleinanzeigen-bot is a command-line application to publish, update, delete, and republish listings on kleinanzeigen.de.

Key Features

  • Automated Publishing: Publish new listings from YAML/JSON configuration files
  • Smart Republishing: Automatically republish listings at configurable intervals to keep them at the top of search results
  • Bulk Management: Update or delete multiple listings at once
  • Download Listings: Download existing listings from your profile to local configuration files
  • Extend Listings: Extend ads close to expiry to keep watchers/savers and preserve the monthly ad quota
  • Browser Automation: Uses Chromium-based browsers (Chrome, Edge, Chromium) for reliable automation
  • Flexible Configuration: Configure defaults once, override per listing as needed

The use of this program could violate the terms of service of kleinanzeigen.de applicable at the time of use. It is your responsibility to ensure the legal compliance of its use. The developers assume no liability for any damages or legal consequences. Use is at your own risk. Any unlawful use is strictly prohibited.

⚠️ Rechtliche Hinweise

Die Verwendung dieses Programms kann unter Umständen gegen die zum jeweiligen Zeitpunkt bei kleinanzeigen.de geltenden Nutzungsbedingungen verstoßen. Es liegt in Ihrer Verantwortung, die rechtliche Zulässigkeit der Nutzung dieses Programms zu prüfen. Die Entwickler übernehmen keinerlei Haftung für mögliche Schäden oder rechtliche Konsequenzen. Die Nutzung erfolgt auf eigenes Risiko. Jede rechtswidrige Verwendung ist untersagt.

Installation

Installation using pre-compiled exe

  1. The following components need to be installed:

    1. Chromium, Google Chrome, or Chromium-based Microsoft Edge browser
  2. Open a command/terminal window

  3. Download and run the app by entering the following commands:

    1. On Windows:

      curl -L https://github.com/Second-Hand-Friends/kleinanzeigen-bot/releases/download/latest/kleinanzeigen-bot-windows-amd64.exe -o kleinanzeigen-bot.exe
      
      kleinanzeigen-bot --help
      
    2. On Linux:

      curl -L https://github.com/Second-Hand-Friends/kleinanzeigen-bot/releases/download/latest/kleinanzeigen-bot-linux-amd64 -o kleinanzeigen-bot
      
      chmod 755 kleinanzeigen-bot
      
      ./kleinanzeigen-bot --help
      
    3. On macOS:

      curl -L https://github.com/Second-Hand-Friends/kleinanzeigen-bot/releases/download/latest/kleinanzeigen-bot-darwin-amd64 -o kleinanzeigen-bot
      
      chmod 755 kleinanzeigen-bot
      
      ./kleinanzeigen-bot --help
      

Installation using Docker

  1. The following components need to be installed:
    1. Docker
    2. Bash (on Windows e.g. via Cygwin, MSys2 or git)
    3. X11 - X Window System display server (on Windows e.g. Portable-X-Server)

Running the docker image:

  1. Ensure the X11 Server is running

  2. Run the docker image:

    X11_DISPLAY=192.168.50.34:0.0 # replace with IP address of workstation where X11 server is running
    
    DATA_DIR=/var/opt/data/kleinanzeigen-bot # path to config
    
    # /mnt/data is the container's default working directory
    docker run --rm --interactive --tty \
      --shm-size=256m \
      -e DISPLAY=$X11_DISPLAY \
      -v $DATA_DIR:/mnt/data \
      ghcr.io/second-hand-friends/kleinanzeigen-bot \
      --help
    

Installation from source

  1. The following components need to be installed:

    1. Chromium, Google Chrome, or Chromium-based Microsoft Edge browser
    2. Python 3.10 or newer
    3. pip
    4. git client
  2. Open a command/terminal window

  3. Clone the repo using

    git clone https://github.com/Second-Hand-Friends/kleinanzeigen-bot/
    
  4. Change into the directory:

    cd kleinanzeigen-bot
    
  5. Install the Python dependencies using:

    pip install pdm
    
    pdm install
    
  6. Run the app:

    pdm run app --help
    

Installation from source using Docker

  1. The following components need to be installed:

    1. Docker
    2. git client
    3. Bash (on Windows e.g. via Cygwin, MSys2 or git)
    4. X11 - X Window System display server (on Windows e.g. Portable-X-Server)
  2. Clone the repo using

    git clone https://github.com/Second-Hand-Friends/kleinanzeigen-bot/
    
  3. Open the cloned directory in a Bash terminal window and navigate to the docker subdirectory

  4. Execute bash build-image.sh

  5. Ensure the image is built:

    $ docker image ls
    REPOSITORY                            TAG      IMAGE ID       CREATED       SIZE
    second-hand-friends/kleinanzeigen-bot latest   c31fd256eeea   1 minute ago  590MB
    python                                3-slim   2052f0475488   5 days ago    123MB
    

Running the docker image:

  1. Ensure the X11 Server is running

  2. Run the docker image:

    X11_DISPLAY=192.168.50.34:0.0 # replace with IP address of workstation where X11 server is running
    
    DATA_DIR=/var/opt/data/kleinanzeigen-bot # path to config
    
    # /mnt/data is the container's default working directory
    docker run --rm --interactive --tty \
      --shm-size=256m \
      -e DISPLAY=$X11_DISPLAY \
      -v $DATA_DIR:/mnt/data \
      second-hand-friends/kleinanzeigen-bot \
      --help
    

Usage

Usage: kleinanzeigen-bot COMMAND [OPTIONS]

Commands:
  publish  - (re-)publishes ads
  verify   - verifies the configuration files
  delete   - deletes ads
  update   - updates published ads
  download - downloads one or multiple ads
  extend   - extends active ads that expire soon (keeps watchers/savers and does not count towards the monthly ad quota)
  update-check - checks for available updates
  update-content-hash  recalculates each ad's content_hash based on the current ad_defaults;
                      use this after changing config.yaml/ad_defaults to avoid every ad being marked "changed" and republished
  create-config - creates a new default configuration file if one does not exist
  diagnose - diagnoses browser connection issues and shows troubleshooting information
  --
  help     - displays this help (default command)
  version  - displays the application version

Options:
  --ads=all|due|new|changed|<id(s)> (publish) - specifies which ads to (re-)publish (DEFAULT: due)
        Possible values:
        * all: (re-)publish all ads ignoring republication_interval
        * due: publish all new ads and republish ads according the republication_interval
        * new: only publish new ads (i.e. ads that have no id in the config file)
        * changed: only publish ads that have been modified since last publication
        * <id(s)>: provide one or several ads by ID to (re-)publish, like e.g. "--ads=1,2,3" ignoring republication_interval
        * Combinations: You can combine multiple selectors with commas, e.g. "--ads=changed,due" to publish both changed and due ads
  --ads=all|new|<id(s)> (download) - specifies which ads to download (DEFAULT: new)
        Possible values:
        * all: downloads all ads from your profile
        * new: downloads ads from your profile that are not locally saved yet
        * <id(s)>: provide one or several ads by ID to download, like e.g. "--ads=1,2,3"
  --ads=all|<id(s)> (extend) - specifies which ads to extend (DEFAULT: all)
        Possible values:
        * all: extend all eligible ads in your profile
        * <id(s)>: provide one or several ads by ID to extend, like e.g. "--ads=1,2,3"
        * Note: kleinanzeigen.de only allows extending ads within 8 days of expiry; ads outside this window are skipped.
  --ads=changed|<id(s)> (update) - specifies which ads to update (DEFAULT: changed)
        Possible values:
        * changed: only update ads that have been modified since last publication
        * <id(s)>: provide one or several ads by ID to update, like e.g. "--ads=1,2,3"
  --force           - alias for '--ads=all'
  --keep-old        - don't delete old ads on republication
  --config=<PATH>   - path to the config YAML or JSON file (DEFAULT: ./config.yaml)
  --logfile=<PATH>  - path to the logfile (DEFAULT: ./kleinanzeigen-bot.log)
  --lang=en|de      - display language (STANDARD: system language if supported, otherwise English)
  -v, --verbose     - enables verbose output - only useful when troubleshooting issues

Note: The output of kleinanzeigen-bot help is always the most up-to-date reference for available commands and options.

Limitation of download: It's only possible to extract the cheapest given shipping option.

Configuration

All configuration files can be in YAML or JSON format.

Installation modes (portable vs. system-wide)

On first run, the app may ask which installation mode to use. In non-interactive environments (CI/headless), it defaults to portable mode and will not prompt.

The --config and --logfile flags override only their specific paths. They do not change the chosen installation mode or other mode-dependent paths (downloads, state files, etc.).

  1. Portable mode (recommended for most users, especially on Windows):

    • Stores config, logs, downloads, and state in the current directory
    • No admin permissions required
    • Easy backup/migration; works from USB drives
  2. System-wide mode (advanced users / multi-user setups):

    • Stores files in OS-standard locations
    • Cleaner directory structure; better separation from working directory
    • Requires proper permissions for user data directories

OS notes (brief):

  • Windows: System-wide uses AppData (Roaming/Local); portable keeps everything beside the .exe.
  • Linux: System-wide follows XDG Base Directory spec; portable stays in the current working directory.
  • macOS: System-wide uses ~/Library/Application Support/kleinanzeigen-bot (and related dirs); portable stays in the current directory.

1) Main configuration ⚙️

The main configuration file (config.yaml) is required to run the bot. It contains your login credentials and controls all bot behavior.

Quick start:

# Generate a config file with all defaults
kleinanzeigen-bot create-config

# Or specify a custom location
kleinanzeigen-bot --config /path/to/config.yaml publish

Minimal config.yaml:

# yaml-language-server: $schema=https://raw.githubusercontent.com/Second-Hand-Friends/kleinanzeigen-bot/main/schemas/config.schema.json
login:
  username: "your_username"
  password: "your_password"

📖 Complete Configuration Reference →

Full documentation including timeout tuning, browser settings, ad defaults, diagnostics, and all available options.

2) Ad configuration 📝

Each ad is defined in a separate YAML/JSON file (default pattern: ad_*.yaml). These files specify the title, description, price, category, images, and other ad-specific settings.

Quick example (ad_laptop.yaml):

# yaml-language-server: $schema=https://raw.githubusercontent.com/Second-Hand-Friends/kleinanzeigen-bot/main/schemas/ad.schema.json
active: true
title: "Gaming Laptop - RTX 3060"
description: |
  Powerful gaming laptop in excellent condition.
  Includes original box and charger.
category: "Elektronik > Notebooks"
price: 450
price_type: NEGOTIABLE
images:
  - "laptop/*.jpg"  # Relative to ad file location (or use absolute paths); glob patterns supported

📖 Complete Ad Configuration Reference →

Full documentation including automatic price reduction, shipping options, category IDs, and special attributes.

3) Using an existing browser window (Optional)

By default a new browser process will be launched. To reuse a manually launched browser window/process, you can enable remote debugging. This is useful for debugging or when you want to keep your browser session open.

For detailed instructions on setting up remote debugging with Chrome 136+ security requirements, see Browser Troubleshooting - Using an Existing Browser Window.

Browser Connection Issues

If you encounter browser connection problems, the bot includes a diagnostic command to help identify issues:

For binary users:

kleinanzeigen-bot diagnose

For source users:

pdm run app diagnose

This command will check your browser setup and provide troubleshooting information. For detailed solutions to common browser connection issues, see the Browser Connection Troubleshooting Guide.

Development Notes

Please read CONTRIBUTING.md before contributing code. Thank you!

Related Open-Source projects

License

All files in this repository are released under the GNU Affero General Public License v3.0 or later.

Individual files contain the following tag instead of the full license text:

SPDX-License-Identifier: AGPL-3.0-or-later

This enables machine processing of license information based on the SPDX License Identifiers that are available here: https://spdx.org/licenses/.

Description
No description provided
Readme 8.5 MiB
Languages
Python 99.4%
Dockerfile 0.3%
Shell 0.3%