登录 | 注册

格式:Manifest文件

每一个扩展,可安装的WebApp,和皮肤,都有一个JSON格式的manifest文件,叫manifest.json,里面提供了重要的信息 。

字段说明

下面的脚本演示了所有支持的字段,每个字段都有连接指向专有的说明。必须的字段只有:name和version。

{
	// Required    
	"name": "My Extension",    
	"version": "versionString",      
	
	// Recommended    
	"description": "A plain text description",    
	"icons": { ... },    
	"default_locale": "en",      
	
	// Pick one (or none)    
	"browser_action": {...},    
	"page_action": {...},    
	"theme": {...},    
	"app": {...},      
	
	// Add any of these that you need    
	"background_page": "aFile.html",    
	"chrome_url_overrides": {...},    
	"content_scripts": [...],    
	"homepage_url": "http://path/to/homepage",    
	"incognito": "spanning" or "split",    
	"key": "publicKey",    
	"minimum_chrome_version": "versionString",    
	"omnibox": { "keyword" : "aString" },    
	"options_page": "aFile.html",    
	"permissions": [...],    
	"plugins": [...],    
	"update_url": "http://path/to/updateInfo.xml"  
}  

字段详细信息

这一节只说明在另外一页没有说明的字段,如果需要完整的字段列表,可以看这个链接:Field summary.,里面有详细的描述。

app

可安装的webapp,包括打包过的app,需要这个字段来指定app需要使用的url。最重要的是app的启动页面------当用户在点击app的图标后,浏览器将导航到的地方。

更详细的信息,请参考文档hosted appspackaged apps.:

default_locale

指定这个扩展保的缺省字符串的子目录:_lcoales。如果扩展有_locales目录,这个字段是必须的。如果没有_locales目录,这个字段是必须不存在的。具体见Internationalization.。

description

描述扩种的一段字符串(不能是html或者其他格式,不能超过132个字符)。这个描述必须对浏览器扩展的管理界面和Chrome Web Store都合适。你可以指定本地相关的字符串,具体参考:Internationalization

homepage_url

这个扩展的主页 url。扩展的管理界面里面将有一个链接指向这个url。如果你将扩展放在自己的网站上,这个url就很有用了。如果你通过了Extensions GalleryChrome Web Store来分发扩展,主页 缺省就是扩展的页面。

icons

一个或者多个图标来表示扩展,app,和皮肤。你通常可以提供一个128x128的图标,这个图标将在webstore安装时候使用。扩展需要一个48x48的图标,扩展管理页面需要这个图标。同时,你还可以提供给一个16x16的图标作为扩页面的fa网页图标 。这个16x16的图标,还将显示在实验性的扩展infobar特性上。

图标要求是png格式,因为png格式是对透明支持最好的。你也可以用其他webkit支持的格式,如BMP,GIF,ICON和JPEG。下面有个例子:

"icons": 
{ 
	"16": "icon16.png",             
	"48": "icon48.png",            
	"128": "icon128.png" 
},  

注意:请只使用文档说明的图标大小。

可能你已经注意到了,chrome有时候会将这些图标尺寸变小,比如,安装对话框将128-像素图标缩小为69-像素了。

然而,Chrome的界面细节可能每个版本都不一样,但每次变动都假设开发者使用的是文档标注过的尺寸。如果你使用了其他的尺寸,你的图标可能看起来很丑,在将来的某个版本中。

如果你使用Chrome Developer Dashboard上传你的扩展、app、皮肤,你需要上传附带的图片,包括至少一张扩展的缩略图。更多信息请参考 :Chrome Web Store developer documentation

incognito

可选值:"spanning"和"split",指定当扩展在允许隐身模式下运行时如何响应。

扩展的缺省值是Spanning,这意味着扩展将在一个共享的进程里面运行。隐身标签页的事件和消息都会发送到这个共享进程,来源通过incognito标志来区分。

可安装的webapp的缺省值是split,这个意思是隐身模式下的webapp都将运行在他们自己的隐身进程中。如果app或扩展有背景页面,也将运行在隐身进程中。隐身进程和普通进程一样,只是cookie保存在内存中而已。每个进程只可看到和自己相关的事件和消息(比如,隐身进程只能看到隐身标签也更新)。这些进程之间不能互相通信。

根据经验,如果你的扩展或app需要在隐身浏览器里面开一个标签页,使用split;如果你的扩展或app需要登记录到远程服务器或者本地永久配置,用spanning。

key

在开发阶段,这个值可以作为扩展、app和皮肤的唯一标示来使用。

注意:你并不需要好使用这个值。相反,你应该写代码让这个值不符合relative pathschrome.extension.getURL()

为了得到一个合适的的值,首先安装你的扩展,从.crx文件。 (你需要上传你的扩展或者手动打包).然后,在你的用户数据目录,查看manifest.json文件,就可以看到这个字段已经被填充了。

minimum_chrome_version

你的扩展,app或皮肤需要的chrome的最小版本,如果有这个需要的话。这个字符串的格式和 version字段一样。

name

用来标示这个扩展的一个简短的纯文本。这个字段将用在安装对话框,扩展管理界面,和store里面。你可以指定一个本地相关的字符串为这个字段,具体参考:Internationalization

permissions

扩展或app将使用的一组权限。每个权限是一列已知字符串列表中的一个,如geolocatioin或者一个匹配模式,来指定可以访问的一个或者多个主机。权限可以帮助限定危险,如果你的扩展或者app被攻击。一些权限在安装之前,会告知用户,具体参考:Permission Warnings.

如果一个扩展api需要你的声明一个权限在manifest文件,一般的,api的文档将告诉怎么做。例如,Tabs页面告诉你这么声明一个tabs权限。

这是一个扩展的manifest文件的权限设置的一部分。

"permissions": 
[    
	"tabs",    
	"bookmarks",    
	"http://www.blogger.com/",    
	"http://*.google.com/",    
	"unlimitedStorage"  
],  

下面的表格列举了一个扩展或者app可以使用的权限。

注意:托管的app能使用权限:xxx,其他的都不能使用。

Permission Description
match pattern Specifies ahost permission. Required if the extension wants to interact with the code running on pages. Many extension capabilities, such as cross-origin XMLHttpRequests,programmatically injected content scripts, and the cookies API require host permissions. For details on the syntax, see Match Patterns.
"background"

Makes Chrome start up early and and shut down late, so that apps and extensions can have a longer life.

When any installed hosted app, packaged app, or extension has "background" permission, Chrome runs (invisibly) as soon as the user logs into their computer—before the user launches Chrome. The "background" permission also makes Chrome continue running (even after its last window is closed) until the user explicitly quits Chrome.

Note:Disabled apps and extensions are treated as if they aren't installed.

You typically use the "background" permission with a background page or (for hosted apps) a background window.

"bookmarks" Required if the extension uses the chrome.bookmarks module.
"chrome://favicon/" Required if the extension uses the "chrome://favicon/url" mechanism to display the favicon of a page. For example, to display the favicon of http://www.google.com/, you declare the "chrome://favicon/" permission and use HTML code like this:
<img src="chrome://favicon/http://www.google.com/">
"contextMenus" Required if the extension uses the chrome.contextMenus module.
"cookies" Required if the extension uses the chrome.cookies module.
"experimental" Required if the extension uses any chrome.experimental.* APIs.
"geolocation" Allows the extension to use the proposed HTML5 geolocation API without prompting the user for permission.
"history" Required if the extension uses the chrome.history module.
"idle" Required if the extension uses the chrome.idle module.
"management" Required if the extension uses the chrome.management module.
"notifications" Allows the extension to use the proposed HTML5 notification API without calling permission methods (such ascheckPermission()). For more information see Desktop Notifications.
"tabs" Required if the extension uses the chrome.tabs or chrome.windows module.
"unlimitedStorage" Provides an unlimited quota for storing HTML5 client-side data, such as databases and local storage files. Without this permission, the extension is limited to 5 MB of local storage.

Note:This permission applies only to Web SQL Database and application cache (see issue 58985). Also, it doesn't currently work with wildcard subdomains such ashttp://*.example.com.

version

扩展的版本用一个到4个数字来表示,中间用点隔开。这些数字有些规则:必须在0到65535之间,非零数字不能0开头,比如,99999和032是不合法的。

下面是一些版本字符串例子:

  • "version": "1"
  • "version": "1.0"
  • "version": "2.10.2"
  • "version": "3.1.2.4567"

自动升级系统将比较版本来确定一个已经安装的扩展是否需要升级。如果一个发布的扩展有一个更新的版本字符串,比一个安装的扩展,这个扩展将自动升级。

版本字符串从比较从左边开始。如果这些数字相等,这个数字的右边的数字将被比较,这样持续下去。比如:1.2.0就比1.1.9.9999更新。

缺少的数字将用0来代替。例子,1.1.9.9999就比1.1.更新。

具体信息请参考Autoupdating

此页面的开发文档由360工程师翻译自Chromium官方的扩展开发文档,您可以随意传播、转阅。

Powered by 360