From 39c8031cd758f94192097eb347202aa4f08657c5 Mon Sep 17 00:00:00 2001 From: TC Date: Wed, 13 Jan 2021 21:28:42 +0100 Subject: [PATCH] Disable context isolation (to load ffmpeg wasm) --- index.js | 4 +- plugins/downloader/front.js | 44 +++++++++++----------- plugins/downloader/templates/download.html | 2 +- plugins/navigation/templates/back.html | 2 +- plugins/navigation/templates/forward.html | 2 +- preload.js | 7 +++- 6 files changed, 35 insertions(+), 26 deletions(-) diff --git a/index.js b/index.js index a083d4d9..10b6f2d9 100644 --- a/index.js +++ b/index.js @@ -86,7 +86,9 @@ function createMainWindow() { backgroundColor: "#000", show: false, webPreferences: { - contextIsolation: true, + // TODO: re-enable contextIsolation once it can work with ffmepg.wasm + // Possible bundling? https://github.com/ffmpegwasm/ffmpeg.wasm/issues/126 + contextIsolation: false, preload: path.join(__dirname, "preload.js"), nodeIntegrationInSubFrames: true, nativeWindowOpen: true, // window.open return Window object(like in regular browsers), not BrowserWindowProxy diff --git a/plugins/downloader/front.js b/plugins/downloader/front.js index d235da65..732fd161 100644 --- a/plugins/downloader/front.js +++ b/plugins/downloader/front.js @@ -30,28 +30,30 @@ const reinit = () => { } }; -contextBridge.exposeInMainWorld("downloader", { - download: () => { - const videoUrl = window.location.href; +// TODO: re-enable once contextIsolation is set to true +// contextBridge.exposeInMainWorld("downloader", { +// download: () => { +global.download = () => { + const videoUrl = window.location.href; - downloadVideoToMP3( - videoUrl, - (feedback) => { - if (!progress) { - console.warn("Cannot update progress"); - } else { - progress.innerHTML = feedback; - } - }, - (error) => { - triggerAction(CHANNEL, ACTIONS.ERROR, error); - reinit(); - }, - reinit, - pluginOptions - ); - }, -}); + downloadVideoToMP3( + videoUrl, + (feedback) => { + if (!progress) { + console.warn("Cannot update progress"); + } else { + progress.innerHTML = feedback; + } + }, + (error) => { + triggerAction(CHANNEL, ACTIONS.ERROR, error); + reinit(); + }, + reinit, + pluginOptions + ); +}; +// }); function observeMenu(options) { pluginOptions = { ...pluginOptions, ...options }; diff --git a/plugins/downloader/templates/download.html b/plugins/downloader/templates/download.html index 7f9ab3ce..138464fb 100644 --- a/plugins/downloader/templates/download.html +++ b/plugins/downloader/templates/download.html @@ -4,7 +4,7 @@ tabindex="-1" aria-disabled="false" aria-selected="false" - onclick="downloader.download()" + onclick="download()" >