Manifest.json 配置详解

manifest.json 是 Chrome 插件的核心配置文件,用来配置所有和插件相关的配置,必须放在根目录。
下面是一些常用配置项的说明,完整的配置文档 :
https://developer.chrome.com/docs/extensions/mv3/manifest/

配置项介绍

{
	"manifest_version": 3,
	"name": "测试插件",
	"version": "1.0.0",
	"description": "一个Chrome插件示例",
	"icons":
	{
		"16"  :  "img/icon.png",
		"48"  :  "img/icon.png",
		"128" :  "img/icon.png"
	},
	"background":
	{
		"service_worker":"js/background.js"
	},
	"permissions":
	[
		"contextMenus",
		"tabs",
		"notifications",
		"webRequest",
		"storage"
	],
	"action": 
	{
		"default_icon": "img/icon.png",
		"default_title": "一个示例Chrome插件示例",
		"default_popup": "popup.html"
	},
	"content_scripts": 
	[
		{
			"matches": ["https://www.lesscode.work/*"],
			"js": [
				"js/jquery.js", 
				"js/content-script.js"
			],
			"css": ["css/style.css"],
			"run_at": "document_end"
		}
	],
	"host_permissions": [
		"http://*/*", 
		"https://*/*"
	]

}

通过上面的配置信息,结合插件包目录结构您可以更加理解插件包内每个文件的作用。

注意

content_scripts 内的 "matches": ["此处必须指定具体网址,否则会出现权限问题"]。