From ecfe4772a493a586739e9811d10549496ec729bc Mon Sep 17 00:00:00 2001 From: r2dev2 Date: Fri, 17 Feb 2023 23:10:43 -0800 Subject: [PATCH 1/5] use background.scripts in ff manifest --- src/manifest.json | 5 ++++- vite.config.ts | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/manifest.json b/src/manifest.json index c91b8d18..a7b6f366 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -24,7 +24,10 @@ "all_frames": true } ], - "background": { + "{{firefox}}.background": { + "scripts": ["scripts/chat-background.ts"] + }, + "{{chrome}}.background": { "service_worker": "scripts/chat-background.ts" }, "action": { diff --git a/vite.config.ts b/vite.config.ts index a0aea0c9..4893750f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -30,7 +30,7 @@ export default defineConfig({ 'scripts/chat-interceptor.ts' ], disableAutoLaunch: process.env.BROWSER === 'none', - browser: process.env.BROWSER === 'none' ? undefined : process.env.BROWSER, + browser: process.env.BROWSER === undefined ? 'firefox' : process.env.BROWSER, webExtConfig: { startUrl: 'https://www.youtube.com/watch?v=5qap5aO4i9A' } @@ -47,6 +47,11 @@ export default defineConfig({ transform: (content) => { const newManifest = JSON.parse(content.toString()); newManifest.incognito = 'split'; + if ('scripts' in newManifest.background) { + newManifest.background = { + service_worker: newManifest.background.scripts[0] + }; + } return JSON.stringify(newManifest, null, 2); }, rename: 'manifest.chrome.json' From 36e134e4f25d5bdca9de6aceed1218d79cf38a24 Mon Sep 17 00:00:00 2001 From: r2dev2 Date: Fri, 17 Feb 2023 23:43:43 -0800 Subject: [PATCH 2/5] add yarn dev:chrome, dev:firefox, modify yarn start --- README.md | 10 ++++++++-- package.json | 10 +++++++--- vite.config.ts | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d6ec608f..1a2ecdb5 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,13 @@ yarn # install dependencies Build or serve the extension: ```bash -yarn start # watch mode -yarn build # production mode +yarn dev:firefox # devserver for firefox extension +yarn dev:chrome # devserver for chrome extension +yarn start # alias to yarn dev:chrome for backwards compat +yarn start:none # alias to yarn dev:chrome for backwards compat +yarn start:firefox # devserver + open extension in firefox +yarn start:chrome # devserver + open extension in chrome +yarn build # production mode (firefox) +yarn build:chrome # production mode (chrome) VERSION=x.x.x yarn build ``` diff --git a/package.json b/package.json index 386bdbbc..c4f7a2e9 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,14 @@ "private": true, "scripts": { "build": "vite build", + "build:chrome": "cross-env BROWSER=chrome vite build", "package": "node utils/package.js", - "start": "cross-env MINIFY=false BROWSER=none vite build --watch", - "start:chrome": "cross-env MINIFY=false BROWSER=chrome vite build --watch", - "start:firefox": "cross-env MINIFY=false BROWSER=firefox vite build --watch", + "dev:chrome": "cross-env MINIFY=false BROWSER=chrome vite build --watch", + "dev:firefox": "cross-env MINIFY=false BROWSER=firefox vite build --watch", + "start": "yarn dev:chrome", + "start:none": "yarn dev:chrome", + "start:chrome": "cross-env HC_AUTOLAUNCH=menace yarn dev:chrome", + "start:firefox": "cross-env HC_AUTOLAUNCH=menace yarn dev:firefox", "format:check": "eslint ." }, "devDependencies": { diff --git a/vite.config.ts b/vite.config.ts index 4893750f..564dd56b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -29,10 +29,10 @@ export default defineConfig({ 'hyperchat.html', 'scripts/chat-interceptor.ts' ], - disableAutoLaunch: process.env.BROWSER === 'none', + disableAutoLaunch: process.env.HC_AUTOLAUNCH === undefined, browser: process.env.BROWSER === undefined ? 'firefox' : process.env.BROWSER, webExtConfig: { - startUrl: 'https://www.youtube.com/watch?v=5qap5aO4i9A' + startUrl: 'https://www.youtube.com/watch?v=jfKfPfyJRdk' } }), svelte({ From 62218de83d60e9e77d11f566666b61a905637ee4 Mon Sep 17 00:00:00 2001 From: r2dev2 Date: Sun, 12 Mar 2023 15:08:28 -0700 Subject: [PATCH 3/5] =?UTF-8?q?proxy=20extension=20to=20content=20script?= =?UTF-8?q?=20thru=20bg=20for=20ff=20=F0=9F=A7=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Hyperchat.svelte | 18 ++++++++++++------ src/scripts/chat-background.ts | 18 +++++++++++++++++- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/components/Hyperchat.svelte b/src/components/Hyperchat.svelte index 7eadee5a..fdfe2cb8 100644 --- a/src/components/Hyperchat.svelte +++ b/src/components/Hyperchat.svelte @@ -15,6 +15,8 @@ // paramsTabId, // paramsFrameId, // paramsIsReplay, + getBrowser, + Browser, Theme, YoutubeEmojiRenderMode, chatUserActionsItems @@ -258,13 +260,17 @@ return; } - // const frameInfo = { - // tabId: parseInt(paramsTabId), - // frameId: parseInt(paramsFrameId) - // }; + // ff doesn't support extension to content script raw messaging yet + if (getBrowser() == Browser.FIREFOX) { + const frameInfo = { + tabId: parseInt(paramsTabId), + frameId: parseInt(paramsFrameId) + }; - // $port = chrome.runtime.connect(); - $port = chrome.tabs.connect(parseInt(paramsTabId), { frameId: parseInt(paramsFrameId) }); + $port = chrome.runtime.connect({ name: JSON.stringify(frameInfo) }); + } else { + $port = chrome.tabs.connect(parseInt(paramsTabId), { frameId: parseInt(paramsFrameId) }); + } $port?.onMessage.addListener(onPortMessage); diff --git a/src/scripts/chat-background.ts b/src/scripts/chat-background.ts index 20e7bd68..2c3f3fa0 100644 --- a/src/scripts/chat-background.ts +++ b/src/scripts/chat-background.ts @@ -1,4 +1,4 @@ -import { isLiveTL } from '../ts/chat-constants'; +import { isLiveTL, Browser, getBrowser } from '../ts/chat-constants'; chrome.action.onClicked.addListener(() => { if (isLiveTL) { @@ -18,3 +18,19 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { }, () => {}); } }); + +// ff doesn't support extension to content script raw messaging yet +// so we proxy the messaging +if (getBrowser() == Browser.FIREFOX) { + chrome.runtime.onConnect.addListener(hc => { + // frameId and tabId should be int + const { frameId, tabId } = JSON.parse(hc.name); + const interceptorPort = chrome.tabs.connect(tabId, { frameId }); + interceptorPort.onMessage.addListener(msg => { + hc.postMessage(msg); + }); + hc.onMessage.addListener(msg => { + interceptorPort.postMessage(msg); + }); + }); +} From aa99119513a1976ce9939ba44fd4519cc36e1598 Mon Sep 17 00:00:00 2001 From: r2dev2 Date: Sun, 12 Mar 2023 15:42:19 -0700 Subject: [PATCH 4/5] =?UTF-8?q?yarn:build=20defaults=20to=20chrome=20now?= =?UTF-8?q?=20=E2=9A=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- src/manifest.json | 3 ++- utils/package.js | 10 +++++----- vite.config.ts | 12 +++++++----- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index c4f7a2e9..97c8b647 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,9 @@ "version": "69.42.0", "private": true, "scripts": { - "build": "vite build", + "build": "yarn build:chrome", "build:chrome": "cross-env BROWSER=chrome vite build", + "build:firefox": "cross-env BROWSER=firefox vite build", "package": "node utils/package.js", "dev:chrome": "cross-env MINIFY=false BROWSER=chrome vite build --watch", "dev:firefox": "cross-env MINIFY=false BROWSER=firefox vite build --watch", diff --git a/src/manifest.json b/src/manifest.json index a7b6f366..3dee9034 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -45,5 +45,6 @@ "options_ui": { "page": "options.html", "open_in_tab": true - } + }, + "{{chrome}}.incognito": "split" } diff --git a/utils/package.js b/utils/package.js index 830f3bb2..ad3a1bd7 100644 --- a/utils/package.js +++ b/utils/package.js @@ -3,11 +3,11 @@ const { spawn } = require('child_process'); const cmds = [ 'mkdir -p dist', 'cd build', - 'zip -9r ../dist/HyperChat-Firefox.zip .', - 'cp ../dist/HyperChat-Firefox.zip ../dist/HyperChat-Chrome.zip', - 'zip -d ../dist/HyperChat-Chrome.zip manifest.json', - 'printf "@ manifest.chrome.json\\n@=manifest.json\\n" | zipnote -w ../dist/HyperChat-Chrome.zip', - 'zip -d ../dist/HyperChat-Firefox.zip manifest.chrome.json' + 'zip -9r ../dist/HyperChat-Chrome.zip .', + 'cp ../dist/HyperChat-Chrome.zip ../dist/HyperChat-Firefox.zip', + 'zip -d ../dist/HyperChat-Firefox.zip manifest.json', + 'printf "@ manifest.firefox.json\\n@=manifest.json\\n" | zipnote -w ../dist/HyperChat-Firefox.zip', + 'zip -d ../dist/HyperChat-Chrome.zip manifest.firefox.json' ]; spawn( diff --git a/vite.config.ts b/vite.config.ts index 564dd56b..cef15d27 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -30,7 +30,7 @@ export default defineConfig({ 'scripts/chat-interceptor.ts' ], disableAutoLaunch: process.env.HC_AUTOLAUNCH === undefined, - browser: process.env.BROWSER === undefined ? 'firefox' : process.env.BROWSER, + browser: process.env.BROWSER === undefined ? 'chrome' : process.env.BROWSER, webExtConfig: { startUrl: 'https://www.youtube.com/watch?v=jfKfPfyJRdk' } @@ -46,15 +46,17 @@ export default defineConfig({ dest: 'build/', transform: (content) => { const newManifest = JSON.parse(content.toString()); - newManifest.incognito = 'split'; - if ('scripts' in newManifest.background) { + if ('incognito' in newManifest) { + delete newManifest.incognito; + } + if ('service_worker' in newManifest.background) { newManifest.background = { - service_worker: newManifest.background.scripts[0] + scripts: [newManifest.background.service_worker] }; } return JSON.stringify(newManifest, null, 2); }, - rename: 'manifest.chrome.json' + rename: 'manifest.firefox.json' }] }) ] From a7eccb8bf4643334409442e6b84e5c4f01c3e75f Mon Sep 17 00:00:00 2001 From: r2dev2 Date: Mon, 13 Mar 2023 11:34:59 -0700 Subject: [PATCH 5/5] =?UTF-8?q?update=20readme=20with=20build=20commands?= =?UTF-8?q?=20=F0=9F=91=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a2ecdb5..eb105cac 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,8 @@ yarn start # alias to yarn dev:chrome for backwards compat yarn start:none # alias to yarn dev:chrome for backwards compat yarn start:firefox # devserver + open extension in firefox yarn start:chrome # devserver + open extension in chrome -yarn build # production mode (firefox) +yarn build # production mode (chrome) yarn build:chrome # production mode (chrome) +yarn build:firefox # production mode (firefox) VERSION=x.x.x yarn build ```