Counts chrome tabs on Windows and submits the count to a REST API
- Python 100%
| .gitignore | ||
| config.py | ||
| LICENSE | ||
| main.py | ||
| README.md | ||
| requirements.txt | ||
| tab_counter.py | ||
| test_server.py | ||
TabCounter
TabCounter is a Windows‑only Python utility that periodically counts your open Chrome tabs (via the UI‑Automation API) and posts the count to a remote server.
Features
- Non‑invasive: reads Chrome’s 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 auto‑start via Task Scheduler or NSSM.
Requirements
- Windows 10 or later
- Python 3.8+
Installation
- Clone or download this repository.
- 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 command‑line 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_secseconds:python main.py
Auto‑start 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)
- Download NSSM (Non‑Sucking Service Manager) and place
nssm.exein your PATH. - 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.