{"id":15710656,"url":"https://github.com/serhiiyahdzhyiev/tabs-manager","last_synced_at":"2025-09-03T00:47:29.041Z","repository":{"id":254696714,"uuid":"847288546","full_name":"SerhiiYahdzhyiev/tabs-manager","owner":"SerhiiYahdzhyiev","description":"This repository holds sources for TabsManager mini-library for browser extensions development.","archived":false,"fork":false,"pushed_at":"2024-10-01T22:49:59.000Z","size":47,"stargazers_count":0,"open_issues_count":21,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-03T21:09:05.491Z","etag":null,"topics":["chrome-api","chrome-extension","chrome-extensions","extension","extensions","js","tabs","tabs-management","ts"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SerhiiYahdzhyiev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-25T11:56:21.000Z","updated_at":"2024-10-01T21:19:08.000Z","dependencies_parsed_at":"2024-08-25T13:23:42.731Z","dependency_job_id":"29b7bede-7ba3-4794-ada7-1f2066e1066d","html_url":"https://github.com/SerhiiYahdzhyiev/tabs-manager","commit_stats":null,"previous_names":["serhiiyahdzhyiev/tabs-manager"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SerhiiYahdzhyiev%2Ftabs-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SerhiiYahdzhyiev%2Ftabs-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SerhiiYahdzhyiev%2Ftabs-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SerhiiYahdzhyiev%2Ftabs-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SerhiiYahdzhyiev","download_url":"https://codeload.github.com/SerhiiYahdzhyiev/tabs-manager/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219870354,"owners_count":16555160,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chrome-api","chrome-extension","chrome-extensions","extension","extensions","js","tabs","tabs-management","ts"],"created_at":"2024-10-03T21:09:15.109Z","updated_at":"2025-04-16T02:39:22.233Z","avatar_url":"https://github.com/SerhiiYahdzhyiev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TabsManager Library\n\n**TabsManager** is a JavaScript library designed to simplify browser tab\nmanagement for browser extension developers. It offers a developer-friendly API\nto interact with browser tabs, track their lifecycle, and manage them\nefficiently.\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Initialization](#initialization)\n  - [Public Methods](#public-methods)\n- [Sandbox Extensions](#sandbox-extensions)\n- [License](#license)\n\n## Installation\n\nDownload minified file from this repo's releases and add it to your browser\nextension development project.\n\nFor example:\n\n```bash\n/my-extension\n│\n├── /lib\n│   └── tabs-manager.min.js\n└── manifest.json\n```\n\n*With Service Worker:*\n\n`manifest.json`;\n```json\n{\n    \"background\": {\n        \"service_worker\": \"background.js\"\n    },\n}\n```\n\n`background.js`:\n```javascript\nimportScripts(\"./lib/tabs-manager.min.js\");\n\n// ...\n```\n\n*As Background Page Script:*\n\n`manifest.json`;\n```json\n{\n    \"background\": {\n        \"scripts\": [\n            \"./lib/tabs-manager.min.js\",\n            \"./background.js\"\n        ]\n    },\n}\n```\n\n## Usage\n\n### Initialization\n\nTo initialize the `TabsManager`, the library must be included in your extension\nscript. Ensure your extension has the required permissions (`tabs` and\n`activeTab`) in the `manifest.json`.\n\n```json\n{\n  \"permissions\": [\n    \"tabs\",\n    \"activeTab\"\n  ]\n}\n```\n\n*NOTE: Library also has some optional permissions extra functionalities:*\n\n- \"scripting\"\n- \"debugger\"\n\n*Some methods will not work without them and will yield a warning to the console.*\n*Full pack of permissions will look like this:*\n\n```json\n{\n  \"permissions\": [\n    \"tabs\",\n    \"activeTab\",\n    \"scripting\",\n    \"debugger\",\n  ]\n}\n```\n\n**WARNING:** *Currently threre are some unfixed issues regarding `debugger` permission\nand methods related to it in Firefox browser!*\n\nThen, instantiate the `TabsManager` object in your extensino's code:\n\n```javascript\nconst manager = new TabsManager(); // Withour options...\nconst my_manager = new TabsManager({name: \"My Manager\"}); // Withour custom name\n```\n\n*Note:* You can create as many instances of `TabsManager` as you want, but with\ncurrent capabilities of this object this probably does not make much sense, but\nI'm working on it. In the future you will be able to use managers, like this:\n\n```javascript\nconst gitHubTabs = new TabsManager({\n    filters: [\n            {\n                type: \"host\",\n                value: \"github.com\"\n            },\n            // ...\n        ]\n    });\n```\n\nThe previous example is a draft, if you have any ideas on how to improve the\ninterface or extend functionalities, please consider contributing.\n\n*Note: Construction options/payload currently can be omitted as it is not in\nuse yet...*\n\n### Public Methods\n\nThe **TabsManager** provides several methods for managing and retrieving tab\ninformation.\n\n#### `TabsManager.withTabs(cb)`\n\nA static utility to access all currently tracked tabs. Takes a callback\nfunction that operates on the tabs.\n\n**Parameters:**\n\n- `cb`: A function that receives the `Tabs` instance and performs operations\n        on it.\n\n```javascript\nconst doSomething = TabsManager.withTabs((tabs, myArg) =\u003e {\n    console.log(tabs);\n    console.log(myArg);\n    //...Do something...\n});\n\ndoSomething(42); // [Tab, Tab ...], 42\n```\n\n#### `manager.getAll()`\n\nRetrieve all currently open tabs tracked by the manager.\n\n**Returns:**\n\n- An array of `Tab` objects.\n\n```javascript\nconst allTabs = manager.getAll();\n```\n\n#### `manager.get(key)`\n\nRetrieve a specific tab by its ID or tabs list by URL.\n\n**Parameters:**\n\n- `key`: The ID or URL of the tab(s).\n\n**Returns:**\n\n- A `Tab` object if found (or list of `Tab` objects), otherwise `null`.\n\n```javascript\nconst tab = manager.get(123); // by ID\nconst tabsByUrl = manager.get('https://example.com'); // by URL\n```\n\n#### `manager.has(key)`\n\nCheck if a tab exists by its ID or URL.\n\n**Parameters:**\n\n- `key`: The ID or URL of the tab.\n\n**Returns:**\n\n- `true` if the tab exists, `false` otherwise.\n\n```javascript\nconst exists = manager.has(123);\n```\n\n`TabsManager` instances also provide some handy getters/properties for accessing tabs:\n\n#### `tabs`\n\nCurrently returns an array of `Tab` instances.\n\nExample:\n\n```javascript\nconst manager = new TabsManager();\n\nmanager.tabs[0]; // Access first tab\n```\n\n#### `first`\n\nReturns first `Tab`.\n\nExample:\n\n```javascript\nconst manager = new TabsManager();\n\nmanager.first; // Access first tab\n```\n\n#### `last`\n\nReturns last `Tab`.\n\nExample:\n\n```javascript\nconst manager = new TabsManager();\n\nmanager.first; // Access last tab\n```\n\n##### TabsManager objects also have following methods from \u003cbrowser|chrome\u003e.tabs object:\n    - create\n    - connect\n    - discard\n    - query\n    - remove\n    - reload\n    - update\n\nTheir signatures in most cases are the same as in `chrome.tabs`.\n\n### The `Tab` Class\n\nEach tab in **TabsManager** is wrapped in a `Tab` class that provides\nadditional properties/getters:\n\n- `createdAt`: The timestamp when the tab was created.\n- `uptime`: Time elapsed since the tab was created.\n- `msFromLastAccessed`: Time in milliseconds since the tab was last accessed.\n- `urlObj`: Tabs url as `URL` instance.\n    - `host`\n    - `hostname`\n    - `origin`\n    - `href`\n    - `protocol`\n    - `username`\n    - `hash`\n    - `password`\n    - `pathname`\n    - `search`\n    - `searchParams` (URLSearchParams | null)\n    - `port`\n\nFrom first minor version you can also call some manipulation methods on the `Tab`\nclass instance directly like this:\n\n```javascript\nconst first = manager.first;\n\nawait first.remove(); // Close first tab...\n```\n\nHere is the list of available manipulation methods:\n\n- **connect(options: chrome.tas.ConnectInfo)**\n- **async clearAllInputs()**\n- **async discard()**\n- **async duplicate()**\n- **async duplicate()**\n- **async goForward()**\n- **async goBack()**\n- **async getLanguage()**\n- **async getScreenshot(options: chrome.tabs.CaptureVisibleTabOptions)**\n- **async move(options: chrome.tabs.MoveProperties)**\n- **async reload()**\n- **async remove()**\n- **async update(options: chrome.tabs.UpdateProperties)**\n- **async focus()**\n- **async forceClose()** *Requires optional permissions!*\n\n## Sandbox Extensions\n\nThis repository holds some sandbox/playground extensions to test/develop\nthe library. Check the nexted `README.md` file inside `__test__/ext`.\n\n## License\n\nThis library is licensed under the MIT License. See the LICENSE file for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserhiiyahdzhyiev%2Ftabs-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserhiiyahdzhyiev%2Ftabs-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserhiiyahdzhyiev%2Ftabs-manager/lists"}