queue/source/manifest.ts

62 lines
1.5 KiB
TypeScript
Raw Normal View History

/* eslint-disable @typescript-eslint/naming-convention */
2023-04-15 10:02:21 +00:00
import {type Manifest} from "webextension-polyfill";
2023-04-11 11:16:56 +00:00
/**
* Creates the WebExtension manifest based on the browser target.
*
* @param browser The browser target ("firefox" or "chromium").
* @returns The WebExtension manifest.
*/
export function createManifest(browser: string): Manifest.WebExtensionManifest {
const manifest: Manifest.WebExtensionManifest = {
manifest_version: Number.NaN,
2023-04-15 10:02:21 +00:00
name: "Queue",
version: "0.3.2",
permissions: ["contextMenus", "storage"],
options_ui: {
2023-04-15 10:02:21 +00:00
page: "options/index.html",
open_in_tab: true,
},
};
2023-04-11 11:16:56 +00:00
const icons: Manifest.IconPath = {
2023-04-15 10:02:21 +00:00
128: "queue.png",
};
2023-04-11 11:16:56 +00:00
const action: Manifest.ActionManifest = {
default_icon: icons,
};
2023-04-15 10:02:21 +00:00
const backgroundScript = "background/setup.js";
2023-04-15 10:02:21 +00:00
if (browser === "firefox") {
manifest.manifest_version = 2;
manifest.background = {
scripts: [backgroundScript],
};
2023-04-11 11:16:56 +00:00
manifest.browser_action = action;
manifest.browser_specific_settings = {
gecko: {
2023-04-15 10:02:21 +00:00
id: "{c3560e6b-00e5-4ab3-b89e-8a54ee5b2c9f}",
strict_min_version: "102.0",
},
};
2023-04-15 10:02:21 +00:00
} else if (browser === "chromium") {
2023-04-11 11:16:56 +00:00
manifest.manifest_version = 3;
manifest.action = action;
manifest.background = {
service_worker: backgroundScript,
2023-04-15 10:02:21 +00:00
type: "module",
2023-04-11 11:16:56 +00:00
};
} else {
throw new Error(`Unknown target browser: ${browser}`);
}
if (Number.isNaN(manifest.manifest_version)) {
2023-04-15 10:02:21 +00:00
throw new TypeError("Manifest version is NaN");
}
return manifest;
}