chrome-extension-tools icon indicating copy to clipboard operation
chrome-extension-tools copied to clipboard

Add offscreen permission

Open eduardhasanaj opened this issue 1 year ago • 4 comments

Build tool

Rollup

Where do you see the problem?

  • [ ] In the browser
  • [X] In the terminal

Describe the bug

I need to use a new permission named "offscreen" but manifest input validation fails with:

[!] Error: There were problems with the extension manifest.
- "offscreen" at "/permissions/3" must be equal to one of the allowed values

Reproduction

Set offscreen in permissions array.

Logs

[!] Error: There were problems with the extension manifest.
- "offscreen" at "/permissions/3" must be equal to one of the allowed values

System Info

Windows, rollup-plugin

Severity

blocking all usage of RPCE

eduardhasanaj avatar May 08 '23 21:05 eduardhasanaj

I tried to fix it but I cannot find a manual on build process. Here is my pr untested. https://github.com/crxjs/chrome-extension-tools/pull/711

eduardhasanaj avatar May 08 '23 21:05 eduardhasanaj

This needs more work because offscreen document needs to be bundled and information about its path is not in manifest. I need help about building the rollup extension. After this I may submit a pull request.

eduardhasanaj avatar May 09 '23 13:05 eduardhasanaj

This needs more work because offscreen document needs to be bundled and information about its path is not in manifest. I need help about building the rollup extension. After this I may submit a pull request.

Hello, I also need permission offscreen, do you have any way?

ongnxco avatar Jul 20 '23 04:07 ongnxco

I temporarily use this method:

offscreen.html, offscreen.js

Use the plugin: rollup-plugin-copy to copy these 2 files to the dist folder or add offscreen.html to web_accessible_resources for them to be automatically copied to the dist folder.

Create a rollup-plugin to merge permissions in the dist/manifest.json file as follows.

import { readFile, writeFile } from 'fs/promises';

const mergePermissions = (options = {}) => {
    const {src = 'dist/manifest.json', dest = 'dist/manifest.json', permissions = []} = options;
    const hook = 'writeBundle';
    return {
        name: 'merge-permissions',
        [hook]: async () => {
            if(permissions.length > 0) {
                let manifest = await readFile(src, 'utf8');
                manifest = JSON.parse(manifest);
                manifest['permissions'] = manifest['permissions'].concat(permissions);
                await writeFile(dest, JSON.stringify(manifest, null, 2));
            }
        }
    }
}

export default mergePermissions;
plugins: [
...,
mergePermissions({
      permissions: ["offscreen"]
})

ongnxco avatar Jul 20 '23 05:07 ongnxco