Dave M.
Dave M.

Reputation: 1537

Chrome 89.0.4389.114 Extension Permissions (Manifest V3)

I'm trying to update a simple extension to Manifest V3. I must be doing something wrong, because simple tags such as permissions don't work right...I know Chrome is reading the stanza, because I get an error if I put a bogus permission in, but the about://extensions doesn't show permission contextMenus for my extension, even though it's there. And chrome.contextMenus is undefined, so I can't create my menu.

Is Manifest V3 still half-baked and not-ready-for-primetime, or am I doing something stupid that is silently ignored?

{
    "manifest_version": 3,
    "name": "TESS+",
    "version": "0.043",

    "description": "TESS+ -- My browser extension",

    "icons": {
        "48": "TESS+Icon.png"
    },

    "content_scripts": [
        {
            "matches": ["*://tmsearch.uspto.gov/bin/showfield*" ],
            "js": ["jquery-3.6.0.min.js", "tess+.js", "FH.js", "DateTime.js"]
        }
    ],

    "background": {
        "service_worker": "tess-bg.js"
    },

    "web_accessible_resources": [
        {
            "resources": [ "TESS+Button.png" ],
            "matches": [ "https://tsdr.uspto.gov/*" ]
        }
    ],

    "permissions": [
        "contextMenus"
    ],

    "host_permissions": [
        "http://tsdr.uspto.gov/",
        "https://tsdr.uspto.gov/"
    ]

}

Upvotes: 1

Views: 2800

Answers (2)

Dave M.
Dave M.

Reputation: 1537

As @wOxxOm guessed, I was trying to create my context menu from the foreground content-script, not from the background service worker.

For future reference, here's a simple contextMenu example using Manifest V3:

manifest.js:

{
    "manifest_version": 3,
    "name": "ManifestV3Test",
    "version": "0",

    "background": {
        "service_worker": "bg.js"
    },

    "content_scripts": [
        {
            "matches": [ "<all_urls>" ],
            "js": [ "fg.js" ]
        }
    ],

    "permissions": [
        "contextMenus"
    ]
}

bg.js:

/*
 * bg.js -- a ManifestV3 service_worker that installs a context menu
 *          plus minimal framework for messaging between here and
 *          a content script.
 */
chrome.runtime.onInstalled.addListener( function( ) {
    chrome.contextMenus.create( {
        id: 'a unique id',
        title: 'My Context Menu',
        contexts: [ 'all' ]
    } );
} );

chrome.contextMenus.onClicked.addListener( (info,tabs) => {
    console.log( 'context menu clicked' );
    console.log( info );
    console.log( tabs );
    chrome.tabs.sendMessage( tabs.id, 'request-object',
                             (rsp)=> { console.log( "content script replies:" );
                                       console.log( rsp ); } );
} );

fg.js:

/*
 * fg.js -- a content script for a minimal ManifestV3 test extension.
 */

console.log( "Activating content script...try context menu!" );

chrome.runtime.onMessage.addListener( (req,snd,rsp) => {
    console.log( snd.tab ? "another content script says:" : "the extension says:" );
    console.log( req );
    rsp( 'a-response-object' );
} );

This works as of 11-Apr-2021 on Chrome 89.0.4389.114 but Firefox-87.0 (MacOS) rejects it as "unsupported manifest version."

Upvotes: 8

woxxom
woxxom

Reputation: 73776

While it's true that MV3 is still semi-broken, but the permission thing is WAI (working as intended).

Chrome's list of permissions in chrome://extensions page shows only those entries that produce a warning during installation of an extension. See the list in the documentation. The contextMenus permission doesn't produce such a warning so it's not shown in the list.

Such behavior may seem stupid to a developer or a knowledgeable user, but Chrome has always been simplifying its UI/UX to accommodate the majority of people.

Upvotes: 0

Related Questions