From f3eb1975b8fe81c231c64f342a3b76720667268a Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 12 Apr 2026 18:52:38 +0000 Subject: [PATCH] Migrate extension to Manifest V3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - manifest_version: 2 → 3 - background.scripts → background.service_worker (MV3 requires service workers) - browser_action → action (renamed in MV3) - browserAction.setBadgeText → action.setBadgeText - Replace alert() with chrome.notifications.create() (alert unavailable in service workers) - Add notifications permission for the above - Fix browser global: `chrome || browser` → `globalThis.browser || chrome` - Move options.js script tag to end of - Bump version to 0.4.0 https://claude.ai/code/session_01YRKVY7sZgEwRGjqKVbf6Jt --- background.js | 13 +++++++++---- manifest.json | 13 ++++++------- options.html | 2 +- options.js | 6 +++--- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/background.js b/background.js index 16c39e8..fbc60d3 100644 --- a/background.js +++ b/background.js @@ -1,4 +1,4 @@ -const browser = chrome || browser +const browser = globalThis.browser || chrome const tabQuery = (options, params = {}) => new Promise(res => { if (!options.countPinnedTabs) params.pinned = false // only non-pinned tabs @@ -15,7 +15,7 @@ const totalRemaining = options => const updateBadge = options => { if (!options.displayBadge) { - browser.browserAction.setBadgeText({ text: "" }) + browser.action.setBadgeText({ text: "" }) return; } @@ -23,7 +23,7 @@ const updateBadge = options => { .then(remaining => { // console.log(remaining) // remaining = [remainingInWindow, remainingInTotal] - browser.browserAction.setBadgeText({ + browser.action.setBadgeText({ text: Math.min(...remaining).toString() }) }) @@ -104,7 +104,12 @@ const displayAlert = (options, place) => new Promise((res, rej) => { /{\s*(\S+)\s*}/g, replacer ) - alert(renderedMessage); + chrome.notifications.create('tab-limiter-alert', { + type: 'basic', + iconUrl: 'icons/48.png', + title: 'Tab Limiter', + message: renderedMessage + }, () => res(true)); }) let tabCount = -1 diff --git a/manifest.json b/manifest.json index 5058569..64ad200 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "Tab Limiter", "description": "Limit the number of open tabs – in total and per window", - "version": "0.3.0", + "version": "0.4.0", "author": "Matthias Vogt", "homepage_url": "https://github.com/matthias-vogt/tab-limiter", @@ -10,7 +10,7 @@ "128": "icons/128.png" }, - "browser_action": { + "action": { "default_icon": { "48": "icons/48.png", "128": "icons/128.png" @@ -20,13 +20,12 @@ }, "options_page": "options.html", "background": { - "scripts": [ - "background.js" - ] + "service_worker": "background.js" }, "permissions": [ - "storage" + "storage", + "notifications" ], - "manifest_version": 2 + "manifest_version": 3 } diff --git a/options.html b/options.html index da39684..c96fad3 100644 --- a/options.html +++ b/options.html @@ -5,7 +5,6 @@ - @@ -56,4 +55,5 @@

Options

+ diff --git a/options.js b/options.js index 5d28de1..29f40f0 100644 --- a/options.js +++ b/options.js @@ -1,4 +1,4 @@ -const browser = chrome || browser +const browser = globalThis.browser || chrome const tabQuery = (options, params = {}) => new Promise(res => { if (!options.countPinnedTabs) params.pinned = false // only non-pinned tabs @@ -15,7 +15,7 @@ const totalRemaining = options => const updateBadge = options => { if (!options.displayBadge) { - browser.browserAction.setBadgeText({ text: "" }) + browser.action.setBadgeText({ text: "" }) return; } @@ -23,7 +23,7 @@ const updateBadge = options => { .then(remaining => { // console.log(remaining) // remaining = [remainingInWindow, remainingInTotal] - browser.browserAction.setBadgeText({ + browser.action.setBadgeText({ text: Math.min(...remaining).toString() }) })