From b72e1d2f9ac4fc0471ce78b0338017c0822548b1 Mon Sep 17 00:00:00 2001 From: SunriseFox Date: Mon, 23 Sep 2019 18:24:28 +0800 Subject: [PATCH] fix(gecko): rework permission api --- config-overrides/index.js | 14 +++++++++----- src/polyfill/permissions.js | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 src/polyfill/permissions.js diff --git a/config-overrides/index.js b/config-overrides/index.js index e590cad49978..03646823acbf 100644 --- a/config-overrides/index.js +++ b/config-overrides/index.js @@ -48,16 +48,17 @@ const target = (argv => ({ WKWebview: (argv['wk-webview']), }))(require('yargs').argv) -if (target.Firefox) { - polyfills = polyfills.filter(name => !name.includes('webextension-polyfill')) -} - /** * @param config {import("webpack").Configuration} * @param env {'development' | 'production'} * @returns {import("webpack").Configuration} */ function override(config, env) { + if (target.Firefox) { + polyfills = polyfills.filter(name => !name.includes('webextension-polyfill')) + polyfills.push(src('src/polyfill/permissions.js')) + } + // CSP bans eval // And non-inline source-map not working if (env === 'development') config.devtool = 'inline-source-map' @@ -105,7 +106,10 @@ function override(config, env) { function newPage(options = {}) { let templateContent = fs.readFileSync(path.join(__dirname, './template.html'), 'utf8') if (target.Firefox) { - templateContent = templateContent.replace('', '') + templateContent = templateContent.replace( + '', + '', + ) } return new HtmlWebpackPlugin({ templateContent, diff --git a/src/polyfill/permissions.js b/src/polyfill/permissions.js new file mode 100644 index 000000000000..b5e9418c21b9 --- /dev/null +++ b/src/polyfill/permissions.js @@ -0,0 +1,15 @@ +;(()=>{ + if (!browser) return + if (browser.permissions) return + browser.permissions = {} + const requestedUrls = [] + browser.permissions.request = ({origins}) => { + for (let i of origins) { + if (requestedUrls.indexOf(i) === -1) requestedUrls.push(i) + } + return Promise.resolve(true) + } + browser.permissions.getAll = () => { + return Promise.resolve({origins: requestedUrls}) + } +})()