poptab
v1.1.0
Published
A CLI tool and library to clean up specific browser tabs.
Maintainers
Readme
poptab
A CLI tool and library to clean up specific browser tabs.
Overview
This is a trivial CLI tool to close browser tabs whose URLs contain a given URL string.
I use it in a few projects to clean up stale tabs during development sessions.
By default, poptab is silent: it prints nothing on success, failure, or unsupported platforms, and exits 0. Pass --verbose to surface status messages, and --strict to fail hard with a non-zero exit code. This makes poptab safe to drop into cross-platform package.json scripts without cluttering output.
Getting started
Dependencies
The poptab CLI tool requires Node 20.19.0+. The exported APIs are ESM-only and share the Node 20.19.0+ requirement. Poptab is implemented in TypeScript and bundles type definitions.
It can close tabs in Chromium, Chrome, or Safari
The implementation relies on macOS-specific scripting capabilities. On Linux and Windows it is a no-op.
Installation
Invoke directly:
npx poptabOr, install locally to access the CLI commands in a single project or to import the provided APIs:
npm install poptabOr, install globally for access across your system:
npm install --global poptabUsage
By default, poptab will close tabs in an open Chromium browser containing //localhost:.
Library
import { popTab } from 'poptab'
const closedTabs = await popTab({
browser: 'chrome',
urlContains: '127.0.0.1:',
})
console.log(`Closed ${closedTabs} tab(s)`)CLI
Command: poptab
Close browser tabs containing a given URL string.
Usage:
poptab| Option | Description | Type | Default |
| ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- | ---------------- |
| --browser-b | Browser to target for tab cleanup | "chromium" "chrome" "safari" | "chromium" |
| --url-contains-u | String that tab URLs must contain to be closed | string | "//localhost:" |
| --strict-s | Exit with a non-zero status code on failure. Default is to exit cleanly so poptab can be safely chained in scripts (e.g. poptab && next-command). | boolean | false |
| --verbose | Print status messages (successes, skips, and errors). Default is silent so poptab does not clutter script output. | boolean | false |
| --help-h | Show help | boolean | |
| --version-v | Show version number | boolean | |
Implementation notes
Other projects of interest:
- better-opn AppleScript approach. Eponymous NPM package seems sketchy / abandoned.
- kill-tabs This kills the processes instead of closing actual tabs.
- open-in-browser-tab Pairs with a browser extension.
Maintainers
Contributing
Issues and pull requests are welcome.
License
MIT © Eric Mika
