本文介绍: Chrome 浏览器 Manifest V3 版本中 scripting API 解析。
chrome.scripting
一、所需权限
二、Manifest
配置
使用 chrome.scripting API
,需要在 manifest.json
中声明 scripting
权限,以及要向其注入脚本的网页的主机权限。使用 host_permissions
关键字或 activeTab
权限。
三、注入
1. 注入脚本
2. 注入代码
3. 传递参数
4. 注入 CSS
5. 取消所有脚本
四、类型(Types
)
1. ContentScriptFilter
属性
2. CSSInjection
属性
3. ExecutionWorld
枚举值
4. InjectionResult
属性
5. InjectionTarget
属性
6. RegisteredContentScript
属性
7. ScriptInjection
属性
func
函数如下所示:
8. StyleOrigin
在 CSS
中,样式更改的来源分为三类。这些类别称为 style origins
。它们是 user agent origin
, user origin
和 author origin
。
枚举值
五、方法(Methods
)
1. executeScript()
1. 示例
2. 参数
3. 返回
2. getRegisteredContentScripts()
1. 示例
2. 参数
3. 返回
3. insertCSS()
1. 示例
2. 参数
3. 返回
4. registerContentScripts()
1. 示例
2. 参数
3. 返回
5. removeCSS()
1. 示例
2. 参数
3. 返回
6. unregisterContentScripts()
Promise Chrome 96 及更高版本
1. 示例
2. 参数
3. 返回
7. updateContentScripts()
1. 示例
2. 参数
3. 返回
引用
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。