From 69bf0e2bb5848578c162ac6cd2b7d3a1492a0ae4 Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Sun, 21 Jan 2024 22:37:27 +0800 Subject: [PATCH] Show error message alert in MV3 --- index.ts | 5 +++-- package-lock.json | 29 ++++++++++++++++++++++++++++- package.json | 1 + 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/index.ts b/index.ts index 716e144..df93d63 100644 --- a/index.ts +++ b/index.ts @@ -2,6 +2,7 @@ import chromeP from 'webext-polyfill-kinda'; import {isBackground} from 'webext-detect-page'; import {isUrlPermittedByManifest} from 'webext-permissions'; import {getTabUrl} from 'webext-tools'; +import alert from 'webext-alert'; import {executeFunction} from 'webext-content-scripts'; const contextMenuId = 'webext-domain-permission-toggle:add-permission'; @@ -106,12 +107,12 @@ async function handleClick( await executeFunction( tab.id, text => { - alert(text); /* Can't pass a raw native function */ + window.alert(text); /* Can't pass a raw native function */ }, String(error), ); } catch { - alert(error); // One last attempt + void alert(String(error)); } } diff --git a/package-lock.json b/package-lock.json index e1ea260..8d533ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "4.1.0", "license": "MIT", "dependencies": { + "webext-alert": "^0.9.0", "webext-content-scripts": "^2.6.1", "webext-detect-page": "^5.0.0", "webext-permissions": "^3.1.2", @@ -25,7 +26,7 @@ "xo": "^0.56.0" }, "engines": { - "node": ">=18" + "node": ">=16" }, "funding": { "url": "https://github.com/sponsors/fregante" @@ -8380,6 +8381,21 @@ "integrity": "sha512-DEAoo25RfSYMuTGc9vPJzZcZullwIqRDSI9LOy+fkCJPi6hykCnfKaXTuPBDuXAUcqHXyOgFtHNp/kB2FjYHbw==", "dev": true }, + "node_modules/webext-alert": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/webext-alert/-/webext-alert-0.9.0.tgz", + "integrity": "sha512-/aWI4MlJWxO4pH7NVRZ+McXomQUAJIMOE7dqpTOc7UDPV44HlZth/VH3CLm5O9y+u0h6mYbIja2GFWa0og5CGw==", + "dependencies": { + "webext-detect-page": "^5.0.0", + "webext-events": "^2.0.0" + }, + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/fregante" + } + }, "node_modules/webext-content-scripts": { "version": "2.6.1", "resolved": "https://registry.npmjs.org/webext-content-scripts/-/webext-content-scripts-2.6.1.tgz", @@ -8406,6 +8422,17 @@ "url": "https://github.com/sponsors/fregante" } }, + "node_modules/webext-events": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/webext-events/-/webext-events-2.0.0.tgz", + "integrity": "sha512-ylI0lB9Ti5FapWsMJgTsDT0LAUqa9AlYG8KRTXqqvRn3zpw92xqgJ9HzOrpSLZXbb3cIe4YczAWsKvtDQKc+tA==", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/fregante" + } + }, "node_modules/webext-patterns": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/webext-patterns/-/webext-patterns-1.4.0.tgz", diff --git a/package.json b/package.json index 2e344cb..21fde28 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ } }, "dependencies": { + "webext-alert": "^0.9.0", "webext-content-scripts": "^2.6.1", "webext-detect-page": "^5.0.0", "webext-permissions": "^3.1.2",