清单 V3 迁移清单
此页面提供了一个快速参考,可帮助您确定可能需要对 Manifest V2 扩展进行的任何更改,以便它在 Manifest V3 (MV3) 下工作。有关这些更改性质的更多说明,请参阅MV3 迁移指南。
# API清单
您可能需要根据 API 表面的更改进行一些更改。本节列出了这些更改。
您的清单中有主机权限吗?
MV3中的主机权限是一个单独的元素;您没有在permissions
或 中指定它们optional_permissions
。
- 将主机权限移动到
host_permissions
manifest.json 中的字段中。
你在使用背景页面吗?
后台页面被MV3 中的 Service Worker 替换。
- 更换
background.page
或background.scripts
与background.service_worker
manifest.json中。请注意,该service_worker
字段采用字符串,而不是字符串数组。 background.persistent
从 manifest.json 中删除。- 更新后台脚本以适应 Service Worker 执行上下文。
服务工作者必须在根级别注册:他们不能在嵌套目录中。
您是否使用manifest.json 中的browser_action
orpage_action
属性?
这些属性在 MV3中统一为一个属性。
- 将这些属性替换为
action
.
您使用的是chrome.browserAction
还是chrome.pageAction
JavaScript API?
这两个等效的API在 MV3中统一为一个 API。
- 迁移到
chrome.action
API。
您当前是否使用 的阻止版本chrome.webRequest
?
这个 API在 MV3 中被替换declarativeNetRequest
。
This only applies to user-installed extensions; force installed extensions (extensions distributed using ExtensionInstallForcelist). These extensions — typically used in an enterprise setting — can still use the blocking version of chrome.webRequest
.
- Migrate request modification logic to
chrome.declarativeNetRequest
rules. - Replace the
webRequestBlocking
permission withdeclarativeNetRequest
. - Remove the
webRequest
permission if you no longer need to observe network requests. - Remove unnecessary host permissions; blocking a request or upgrading a request's protocol doesn't require host permissions with
declarativeNetRequest
.
Are you using these scripting/CSS methods in the chrome.tabs API?
In Manifest V3, several methods move from chrome.tabs
to the chrome.scripting
API.
- Change any of the following MV2 calls to use the correct MV3 API:
Manifest V2 | Manifest V3 |
---|---|
tabs.executeScript() | scripting.executeScript() |
tabs.insertCSS() | scripting.insertCSS() |
tabs.removeCSS() | scripting.removeCSS() |
Are you executing remote code or arbitrary strings?
You can no longer execute external logic using chrome.scripting.executeScript({code: '...'})
, eval()
, and new Function()
.
- Move all external code (JS, Wasm, CSS) into your extension bundle.
- Update script and style references to load resources from the extension bundle.
- Use
chrome.runtime.getURL()
to build resource URLs at runtime.
Are you executing functions that expect an MV2 background context?
The adoption of service workers in MV3 isn't compatible with methods like chrome.runtime.getBackgroundPage()
, chrome.extension.getBackgroundPage()
, chrome.extension.getExtensionTabs()
, and chrome.extension.getViews()
.
- 迁移到在其他上下文和后台服务工作者之间传递消息的设计。
# 安全检查表
您可能需要根据安全策略的更改进行一些更改。本节列出了这些更改。
您是否在内容脚本中发出 CORS 请求?
- 将这些请求移至后台服务工作者。
您是否content_security_policy
在 manifest.json 中使用自定义?
- 替换
content_security_policy
为content_security_policy.extension_pages
或content_security_policy.sandbox
视情况而定。 - 去除到外部域的引用
script-src
,worker-src
,object-src
,和style-src
指示如果存在的话。