Chrome 89.0.4389.114 扩展程序权限(清单 V3)

Dav*_* M. 1 google-chrome browser-extension google-chrome-extension manifest.json

我正在尝试更新 Manifest V3 的简单扩展。我一定做错了什么,因为诸如此类的简单标签permissions无法正常工作...我知道 Chrome 正在读取该节,因为如果我输入虚假权限,我会收到错误,但 about://extensions 不会没有显示contextMenus我的扩展程序的许可,即使它在那里。并且chrome.contextMenus未定义,所以我无法创建我的菜单。

Manifest V3 是否还处于半生不熟状态,尚未准备好迎接黄金时段,或者我正在做一些被默默忽略的愚蠢事情?

{
    "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/"
    ]

}
Run Code Online (Sandbox Code Playgroud)

Dav*_* M. 8

正如 @wOxxOm 猜测的那样,我试图从前台内容脚本而不是后台服务人员创建上下文菜单。

为了便于将来参考,这里有一个使用 Manifest V3 的简单 contextMenu 示例:

清单.js:

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

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

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

    "permissions": [
        "contextMenus"
    ]
}
Run Code Online (Sandbox Code Playgroud)

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 ); } );
} );
Run Code Online (Sandbox Code Playgroud)

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' );
} );
Run Code Online (Sandbox Code Playgroud)

自 2021 年 4 月 11 日起,此功能可在 Chrome 89.0.4389.114 上运行,但 Firefox-87.0 (MacOS) 将其拒绝为“不受支持的清单版本”。