Counts chrome tabs on Windows and submits the count to a REST API
Find a file
2025-07-25 20:48:53 +02:00
.gitignore update gitignore 2025-07-07 21:14:58 +02:00
config.py initial commit 2025-07-07 21:12:20 +02:00
LICENSE add license 2025-07-07 21:14:30 +02:00
main.py if detected chrome tab count is 0, assume chrome is not currently open and ignore the measurement instead of updating the count on the server 2025-07-25 20:43:42 +02:00
README.md add license section to readme 2025-07-25 20:48:53 +02:00
requirements.txt fix tab counter by using different library that actually works 2025-07-07 21:52:12 +02:00
tab_counter.py change weird '-'-like unicode character to proper '-' 2025-07-25 20:47:59 +02:00
test_server.py add test server 2025-07-07 22:02:00 +02:00

TabCounter

TabCounter is a Windowsonly Python utility that periodically counts your open Chrome tabs (via the UIAutomation API) and posts the count to a remote server.

Features

  • Noninvasive: reads Chromes window UI tree without injecting or modifying the browser.
  • Configurable polling interval.
  • Posts JSON payload {api_key, tab_count, timestamp} to your endpoint.
  • Headless console app; no GUI required.
  • Easy autostart via Task Scheduler or NSSM.

Requirements

  • Windows 10 or later
  • Python 3.8+

Installation

  1. Clone or download this repository.
  2. Create a virtual environment and install dependencies:
    python -m venv .venv
    .venv\Scripts\activate
    pip install -r requirements.txt
    

Configuration

Create a JSON config file at ~/.tabcounterconf.json (i.e. %USERPROFILE%\.tabcounterconf.json on Windows) with the following keys:

{
  "server_url": "https://your.server/endpoint",
  "api_key": "YOUR_API_KEY",
  "interval_sec": 300
}

You can override any setting via commandline flags:

python main.py [--config PATH] [--server-url URL] [--api-key KEY] [--interval N] [--once]

Usage

  • Run once and exit:
    python main.py --once
    
  • Run continuously every interval_sec seconds:
    python main.py
    

Autostart on Windows

Task Scheduler

Use PowerShell to register a scheduled task that runs at user logon:

$action = New-ScheduledTaskAction -Execute "C:\\path\\to\\python.exe" -Argument "C:\\path\\to\\main.py"
$trigger = New-ScheduledTaskTrigger -AtLogOn
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "TabCounter" -Description "Count Chrome tabs and post to server"

NSSM (as a Windows Service)

  1. Download NSSM (NonSucking Service Manager) and place nssm.exe in your PATH.
  2. Install and start the service:
    nssm install TabCounter "C:\\path\\to\\python.exe" "C:\\path\\to\\main.py"
    nssm set TabCounter Start SERVICE_AUTO_START
    nssm start TabCounter
    

Packaging

To create a standalone tabcounter.exe:

pip install pyinstaller
pyinstaller --onefile --name tabcounter main.py

Then distribute the generated dist/tabcounter.exe.

License

MIT License