From fe95293892021aa4b849a443c6fb159c39d2d0cb Mon Sep 17 00:00:00 2001 From: JongHak Seo Date: Wed, 11 Dec 2024 16:20:11 +0900 Subject: [PATCH] Fix #807 - Extract sidePanel config to withSidePanel (#809) Co-authored-by: Jonghakseo --- chrome-extension/manifest.js | 120 +++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 55 deletions(-) diff --git a/chrome-extension/manifest.js b/chrome-extension/manifest.js index e5113ea99..f456da07a 100755 --- a/chrome-extension/manifest.js +++ b/chrome-extension/manifest.js @@ -5,69 +5,79 @@ const packageJson = JSON.parse(fs.readFileSync('../package.json', 'utf8')); const isFirefox = process.env.__FIREFOX__ === 'true'; -const sidePanelConfig = { - side_panel: { - default_path: 'side-panel/index.html', - }, - permissions: ['sidePanel'], -}; +/** + * If you want to disable the sidePanel, you can delete withSidePanel function and remove the sidePanel HoC on the manifest declaration. + * + * ```js + * const manifest = { // remove `withSidePanel()` + * ``` + */ +function withSidePanel(manifest) { + // Firefox does not support sidePanel + if (isFirefox) { + return manifest; + } + return deepmerge(manifest, { + side_panel: { + default_path: 'side-panel/index.html', + }, + permissions: ['sidePanel'], + }); +} /** * After changing, please reload the extension at `chrome://extensions` * @type {chrome.runtime.ManifestV3} */ -const manifest = deepmerge( - { - manifest_version: 3, - default_locale: 'en', - /** - * if you want to support multiple languages, you can use the following reference - * https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Internationalization - */ - name: '__MSG_extensionName__', - version: packageJson.version, - description: '__MSG_extensionDescription__', - host_permissions: [''], - permissions: ['storage', 'scripting', 'tabs', 'notifications'], - options_page: 'options/index.html', - background: { - service_worker: 'background.iife.js', - type: 'module', +const manifest = withSidePanel({ + manifest_version: 3, + default_locale: 'en', + /** + * if you want to support multiple languages, you can use the following reference + * https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Internationalization + */ + name: '__MSG_extensionName__', + version: packageJson.version, + description: '__MSG_extensionDescription__', + host_permissions: [''], + permissions: ['storage', 'scripting', 'tabs', 'notifications'], + options_page: 'options/index.html', + background: { + service_worker: 'background.iife.js', + type: 'module', + }, + action: { + default_popup: 'popup/index.html', + default_icon: 'icon-34.png', + }, + chrome_url_overrides: { + newtab: 'new-tab/index.html', + }, + icons: { + 128: 'icon-128.png', + }, + content_scripts: [ + { + matches: ['http://*/*', 'https://*/*', ''], + js: ['content/index.iife.js'], }, - action: { - default_popup: 'popup/index.html', - default_icon: 'icon-34.png', + { + matches: ['http://*/*', 'https://*/*', ''], + js: ['content-ui/index.iife.js'], }, - chrome_url_overrides: { - newtab: 'new-tab/index.html', + { + matches: ['http://*/*', 'https://*/*', ''], + js: ['refresh.js'], // for public's HMR(refresh) support + css: ['content.css'], // public folder }, - icons: { - 128: 'icon-128.png', + ], + devtools_page: 'devtools/index.html', + web_accessible_resources: [ + { + resources: ['*.js', '*.css', '*.svg', 'icon-128.png', 'icon-34.png'], + matches: ['*://*/*'], }, - content_scripts: [ - { - matches: ['http://*/*', 'https://*/*', ''], - js: ['content/index.iife.js'], - }, - { - matches: ['http://*/*', 'https://*/*', ''], - js: ['content-ui/index.iife.js'], - }, - { - matches: ['http://*/*', 'https://*/*', ''], - js: ['refresh.js'], // for public's HMR(refresh) support - css: ['content.css'], // public folder - }, - ], - devtools_page: 'devtools/index.html', - web_accessible_resources: [ - { - resources: ['*.js', '*.css', '*.svg', 'icon-128.png', 'icon-34.png'], - matches: ['*://*/*'], - }, - ], - }, - !isFirefox && sidePanelConfig, -); + ], +}); export default manifest;