Skip to content

Commit

Permalink
fix(gecko): rework permission api
Browse files Browse the repository at this point in the history
  • Loading branch information
SunriseFox authored and Jack-Works committed Oct 10, 2019
1 parent 1590dce commit b72e1d2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
14 changes: 9 additions & 5 deletions config-overrides/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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('<script src="/polyfill/browser-polyfill.min.js"></script>', '')
templateContent = templateContent.replace(
'<script src="/polyfill/browser-polyfill.min.js"></script>',
'<script src="/polyfill/permissions.js"></script>',
)
}
return new HtmlWebpackPlugin({
templateContent,
Expand Down
15 changes: 15 additions & 0 deletions src/polyfill/permissions.js
Original file line number Diff line number Diff line change
@@ -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})
}
})()

0 comments on commit b72e1d2

Please sign in to comment.