Skip to content

letuanhai/BackToClose

Repository files navigation

BackToClose

Browser extension that closes the active tab when navigating back on the first history entry, replicating Safari's iOS behavior.

Overview

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.

Development

Build From Source

  1. Clone the repository

  2. Install dependencies:

    pnpm install
  3. Build the extension:

    # For Chrome
    pnpm build
    
    # For Firefox
    pnpm build:firefox
  4. Load the extension in your browser:

    • Chrome: Navigate to chrome://extensions, enable Developer mode, click "Load unpacked", and select the .output/chrome-mv3 folder
    • Firefox: Navigate to about:debugging#/runtime/this-firefox, click "Load Temporary Add-on", and select the manifest.json file in .output/firefox-mv3

Commands

  • pnpm dev - Start development server for Chrome
  • pnpm dev:firefox - Start development server for Firefox
  • pnpm build - Build for Chrome
  • pnpm build:firefox - Build for Firefox
  • pnpm zip - Create distribution package for Chrome
  • pnpm zip:firefox - Create distribution package for Firefox
  • pnpm compile - Type check without emitting files

How It Works

  1. Tab Tracking: The background script identifies new tabs, particularly child tabs (opened from another tab)
  2. 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)
  3. Back Navigation Detection: Listens for PopStateEvents to detect when user navigates back to the special entry
  4. Tab Closure: Background script closes the tab when triggered

Browser Compatibility

  • Chrome (Manifest v3)
  • Firefox (Manifest v3)

About

Browser extension that closes the active tab when navigating back on the first history entry

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published