CHROME扩展开发文档之·清单 V3 迁移清单

清单 V3 迁移清单

发表于 •更新于

此页面提供了一个快速参考,可帮助您确定可能需要对 Manifest V2 扩展进行的任何更改,以便它在 Manifest V3 (MV3) 下工作。有关这些更改性质的更多说明,请参阅MV3 迁移指南

# API清单

您可能需要根据 API 表面的更改进行一些更改。本节列出了这些更改。

您的清单中有主机权限吗?
MV3中的主机权限是一个单独的元素;您没有在permissions或 中指定它们optional_permissions

  • 将主机权限移动到host_permissionsmanifest.json 中的字段中。

你在使用背景页面吗?
后台页面被MV3 中的 Service Worker 替换

  • 更换background.pagebackground.scriptsbackground.service_workermanifest.json中。请注意,该service_worker字段采用字符串,而不是字符串数组。
  • background.persistent从 manifest.json 中删除。
  • 更新后台脚本以适应 Service Worker 执行上下文。
陷阱

服务工作者必须在根级别注册:他们不能在嵌套目录中。

您是否使用manifest.json 中的browser_actionorpage_action属性?
这些属性在 MV3中统一为一个属性

  • 将这些属性替换为action.

您使用的是chrome.browserAction还是chrome.pageActionJavaScript API?
这两个等效的API在 MV3中统一为一个 API

  • 迁移到chrome.actionAPI。

您当前是否使用 的阻止版本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 with declarativeNetRequest.
  • 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 V2Manifest 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_policycontent_security_policy.extension_pagescontent_security_policy.sandbox视情况而定。
  • 去除到外部域的引用script-srcworker-srcobject-src,和style-src指示如果存在的话。

最近更新时间: 改进文章

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值