Skip to content

Commit

Permalink
Working MV3
Browse files Browse the repository at this point in the history
  • Loading branch information
cpiber committed Aug 8, 2024
1 parent e4099b5 commit 4d239cb
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 7 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ jobs:
path: |
extension-dist/
if-no-files-found: error

- name: Build V3
run: npm run clean && npm run build:all -- --configV3 true # does not run tests
env:
YT_API_KEY: ${{ secrets.YOUTUBE_KEY }}

- name: Archive extension V3
uses: actions/upload-artifact@v3
with:
name: enhancer_for_nebula_v3-${{ env.npm_package_version }}
path: |
extension-dist/
if-no-files-found: error

test:
name: Test
Expand Down
10 changes: 5 additions & 5 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ const css = (args) =>
*/
const other = (args) => {
if (!args.silent)
console.info(chalk`{blueBright [Rollup build]} Copying files and generating manifest`);
console.info(chalk`{blueBright [Rollup build]} Copying files and generating manifest ${args.configV3 ? 'MV3' : 'MV2'}`);
const otherglob = 'src/**/*.!(d.ts|ts|js|xcf|@(sa|sc|c)ss)';
/**
* @type {import('rollup').RollupOptions}
*/
const conf = {
input: 'src/manifest.ts',
input: args.configV3 ? 'src/manifest_v3.ts' : 'src/manifest.ts',
output: {
dir: 'extension-dist',
format: 'cjs',
Expand All @@ -151,7 +151,7 @@ const other = (args) => {
__VERSION__: JSON.stringify(process.env.npm_package_version),
preventAssignment: true,
}),
writeJSON(),
writeJSON(args.configV3 ? 'manifest_v3.js' : 'manifest.js'),
copy({
targets: [
{ src: otherglob, dest: 'extension-dist' },
Expand Down Expand Up @@ -223,7 +223,7 @@ function remove() {
/**
* @returns {import('rollup').Plugin}
*/
function writeJSON(filename = 'manifest.js') {
function writeJSON(filename = 'manifest.js', outfilename = 'manifest.json') {
return {
name: 'write-json',
generateBundle(_, bundle, isWrite) {
Expand All @@ -232,7 +232,7 @@ function writeJSON(filename = 'manifest.js') {
const manifest = nodeEval(bundle[filename].code);
this.emitFile({
type: 'asset',
fileName: filename.replace(/\.js$/, '.json'),
fileName: outfilename,
source: JSON.stringify(manifest, null, process.env.BUILD ? undefined : 2),
});
delete bundle[filename];
Expand Down
65 changes: 65 additions & 0 deletions src/manifest_v3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const manifest: browser._manifest.WebExtensionManifest = {
manifest_version: 3,

Check failure on line 2 in src/manifest_v3.ts

View workflow job for this annotation

GitHub Actions / Lint

Identifier 'manifest_version' is not in camel case
name: '__MSG_title__',
description: '__MSG_extensionDescription__',
version: __VERSION__,
icons: {
128: 'icons/icon_128.png',
64: 'icons/icon_64.png',
},
background: {
service_worker: 'scripts/background_script.js',

Check failure on line 11 in src/manifest_v3.ts

View workflow job for this annotation

GitHub Actions / Lint

Identifier 'service_worker' is not in camel case
},
content_scripts: [

Check failure on line 13 in src/manifest_v3.ts

View workflow job for this annotation

GitHub Actions / Lint

Identifier 'content_scripts' is not in camel case
{
matches: [
'*://*.nebula.app/*',
'*://*.nebula.tv/*',
'*://*.youtube.com/*',
],
js: [
'scripts/content_script.js',
],
css: [
'styles/content.css',
],
all_frames: true,

Check failure on line 26 in src/manifest_v3.ts

View workflow job for this annotation

GitHub Actions / Lint

Identifier 'all_frames' is not in camel case
},
],
web_accessible_resources: [

Check failure on line 29 in src/manifest_v3.ts

View workflow job for this annotation

GitHub Actions / Lint

Identifier 'web_accessible_resources' is not in camel case
{
resources: ['scripts/player.js'],
matches: ['*://*.nebula.tv/*'],
},
],
permissions: [
'storage',
],
host_permissions: [

Check failure on line 38 in src/manifest_v3.ts

View workflow job for this annotation

GitHub Actions / Lint

Identifier 'host_permissions' is not in camel case
// Only firefox requires this, and the subdomain must be completely specified, otherwise the request fails
'*://content.api.nebula.app/*',
'*://*.nebula.tv/*',
],
// @ts-expect-error for some reason these are not present? but specified in guide: https://developer.chrome.com/docs/extensions/develop/migrate/manifest
optional_host_permissions: [

Check failure on line 44 in src/manifest_v3.ts

View workflow job for this annotation

GitHub Actions / Lint

Identifier 'optional_host_permissions' is not in camel case
'*://*.googleapis.com/*',
],
action: {
default_icon: {

Check failure on line 48 in src/manifest_v3.ts

View workflow job for this annotation

GitHub Actions / Lint

Identifier 'default_icon' is not in camel case
128: 'icons/icon_128.png',
64: 'icons/icon_64.png',
},
default_title: '__MSG_title__',

Check failure on line 52 in src/manifest_v3.ts

View workflow job for this annotation

GitHub Actions / Lint

Identifier 'default_title' is not in camel case
},
options_ui: {

Check failure on line 54 in src/manifest_v3.ts

View workflow job for this annotation

GitHub Actions / Lint

Identifier 'options_ui' is not in camel case
page: 'options.html',
browser_style: true,
},
browser_specific_settings: {
gecko: {
id: 'nebula-enhancer@piber.at',
},
},
default_locale: 'en',
};
export default manifest;
1 change: 1 addition & 0 deletions src/scripts/background/misc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

// TODO: In MV3, DOMParser needs to work with an offscreen document instead: https://developer.chrome.com/docs/extensions/develop/migrate/to-service-workers#move-dom-and-window
export const loadCreators = async () => {
const res = await fetch('https://talent.nebula.tv/creators/');
const body = await res.text();
Expand Down
12 changes: 10 additions & 2 deletions src/scripts/background_script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ const videoFetchNebula = 50;

const { local, sync } = getBrowserInstance().storage;

getBrowserInstance().browserAction.onClicked.addListener(() => openOptions());
if (getBrowserInstance().action) {
getBrowserInstance().action.onClicked.addListener(() => openOptions());
} else {
getBrowserInstance().browserAction.onClicked.addListener(() => openOptions());
}

getBrowserInstance().runtime.onMessage.addListener(async (message: string | { [key: string]: any; }) => {
const keepAlive = setInterval(getBrowserInstance().runtime.getPlatformInfo, 25 * 1000);
try {
const msg = parseTypeObject(message);
console.dev.log('Handling message', msg);
Expand All @@ -24,7 +29,10 @@ getBrowserInstance().runtime.onMessage.addListener(async (message: string | { [k
case BrowserMessage.GET_VID:
return getNebulaVideo(msg);
}
} catch { }
} catch {
} finally {
clearInterval(keepAlive);
}
});

getBrowserInstance().runtime.onInstalled.addListener(async (details) => {
Expand Down

0 comments on commit 4d239cb

Please sign in to comment.