From ea1ae24c3f781de1dd294186331b870d6e31cb81 Mon Sep 17 00:00:00 2001 From: mkusaka Date: Tue, 26 Aug 2025 02:58:00 +0900 Subject: [PATCH] Migrate to Chrome Manifest V3 - Update manifest.json to use Manifest V3 format with service_worker - Replace chrome.browserAction API with chrome.action API - Fix XMLHttpRequest error in Service Worker by using native fetch - Update @types/chrome to v0.1.4 for proper Manifest V3 types --- manifest.json | 8 ++++---- package.json | 2 +- src/badge/implementation.ts | 4 ++-- src/chrome/fake-chrome.ts | 10 +++++----- src/github-api/implementation.ts | 1 + yarn.lock | 8 ++++---- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/manifest.json b/manifest.json index 97e8e63f..478d57c7 100644 --- a/manifest.json +++ b/manifest.json @@ -1,15 +1,15 @@ { - "manifest_version": 2, + "manifest_version": 3, "name": "PR Monitor", "version": "0.0.0", "description": "Get notified when you receive a pull request on GitHub.", "permissions": ["alarms", "notifications", "storage"], "optional_permissions": ["tabs"], "background": { - "scripts": ["background.js"], - "persistent": true + "service_worker": "background.js", + "type": "module" }, - "browser_action": { + "action": { "default_popup": "index.html#popup" }, "icons": { diff --git a/package.json b/package.json index 33d0b74b..8447e423 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "@babel/core": "^7.18.13", "@babel/preset-env": "^7.18.10", "@octokit/core": "^4.0.5", - "@types/chrome": "^0.0.195", + "@types/chrome": "^0.1.4", "@types/jest": "^28.1.7", "@types/node": "^18.7.10", "@types/react": "^18.0.17", diff --git a/src/badge/implementation.ts b/src/badge/implementation.ts index 730fc3b3..2ade429b 100644 --- a/src/badge/implementation.ts +++ b/src/badge/implementation.ts @@ -10,10 +10,10 @@ export function buildBadger(chromeApi: ChromeApi): Badger { } function updateBadge(chromeApi: ChromeApi, state: BadgeState) { - chromeApi.browserAction.setBadgeText({ + chromeApi.action.setBadgeText({ text: badgeLabel(state), }); - chromeApi.browserAction.setBadgeBackgroundColor({ + chromeApi.action.setBadgeBackgroundColor({ color: badgeColor(state), }); } diff --git a/src/chrome/fake-chrome.ts b/src/chrome/fake-chrome.ts index 35c8c03e..e5a714d0 100644 --- a/src/chrome/fake-chrome.ts +++ b/src/chrome/fake-chrome.ts @@ -6,14 +6,14 @@ import { ChromeApi, ChromeStorageItems } from "./api"; * outside of a Chrome extension. */ const partialFakeChrome: RecursivePartial = { - browserAction: { - setBadgeText(details: chrome.browserAction.BadgeTextDetails) { - console.log("chrome.browserAction.setBadgeText", details); + action: { + setBadgeText(details: chrome.action.BadgeTextDetails) { + console.log("chrome.action.setBadgeText", details); }, setBadgeBackgroundColor( - details: chrome.browserAction.BadgeBackgroundColorDetails + details: chrome.action.BadgeColorDetails ) { - console.log("chrome.browserAction.setBadgeBackgroundColor", details); + console.log("chrome.action.setBadgeBackgroundColor", details); }, }, runtime: { diff --git a/src/github-api/implementation.ts b/src/github-api/implementation.ts index afb28a6a..8202a410 100644 --- a/src/github-api/implementation.ts +++ b/src/github-api/implementation.ts @@ -47,6 +47,7 @@ export function buildGitHubApi(token: string): GitHubApi { headers: { Authorization: `Bearer ${token}`, }, + fetch: globalThis.fetch, }); return { diff --git a/yarn.lock b/yarn.lock index e2879507..02e32d4d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1611,10 +1611,10 @@ dependencies: "@types/node" "*" -"@types/chrome@^0.0.195": - version "0.0.195" - resolved "https://registry.yarnpkg.com/@types/chrome/-/chrome-0.0.195.tgz#c570f72857e11caa0a453a444828f75bca592cff" - integrity sha512-kmFh1xx7ehXoOVl6OjEBxmiYaquhxCaILjFGwPbW6xwbqzwDKCte+Mzl99aNWg3EP1B4rKVUuRm1vBsiRYks5g== +"@types/chrome@^0.1.4": + version "0.1.4" + resolved "https://registry.yarnpkg.com/@types/chrome/-/chrome-0.1.4.tgz#74a3a6c892e2c5d0a98997c4f038cb67cfbb0fa9" + integrity sha512-vfISO7SPppN3OKVUqWujtZ4vux3nhDqKaHYEHgfQuPARHuWJ3jjyc1s13H0ckzEc86/neTkCl1TeW72UK6jYKA== dependencies: "@types/filesystem" "*" "@types/har-format" "*"