Browser extension that closes the active tab when navigating back on the first history entry, replicating Safari's iOS behavior.
BackToClose brings Safari's iOS tab closing behavior to Chrome and Firefox. When you open a link in a new tab and hit back on the first page, the tab closes automatically, returning you to the original tab for a seamless browsing experience.
-
Clone the repository
-
Install dependencies:
pnpm install
-
Build the extension:
# For Chrome pnpm build # For Firefox pnpm build:firefox
-
Load the extension in your browser:
- Chrome: Navigate to
chrome://extensions, enable Developer mode, click "Load unpacked", and select the.output/chrome-mv3folder - Firefox: Navigate to
about:debugging#/runtime/this-firefox, click "Load Temporary Add-on", and select themanifest.jsonfile in.output/firefox-mv3
- Chrome: Navigate to
pnpm dev- Start development server for Chromepnpm dev:firefox- Start development server for Firefoxpnpm build- Build for Chromepnpm build:firefox- Build for Firefoxpnpm zip- Create distribution package for Chromepnpm zip:firefox- Create distribution package for Firefoxpnpm compile- Type check without emitting files
- Tab Tracking: The background script identifies new tabs, particularly child tabs (opened from another tab)
- History Manipulation: Content scripts modify the browser history by:
- Changing the first history entry to have title "Close Tab" with special state
- Pushing the current page as the next entry
- Waiting for user interaction before applying changes (browser security requirement)
- Back Navigation Detection: Listens for PopStateEvents to detect when user navigates back to the special entry
- Tab Closure: Background script closes the tab when triggered
- Chrome (Manifest v3)
- Firefox (Manifest v3)