contentScripts 编辑

Use this API to register content scripts. Registering a content script instructs the browser to insert the given content scripts into pages that match the given URL patterns.

This API is very similar to the "content_scripts" manifest.json key, except that with  "content_scripts" , the set of content scripts and associated patterns is fixed at install time. With the contentScripts API, an extension can register and unregister scripts at runtime.

To use the API, call contentScripts.register() passing in an object defining the scripts to register, the URL patterns, and other options. This returns a Promise that is resolved with a contentScripts.RegisteredContentScript object.

The RegisteredContentScript object represents the scripts that were registered in the register() call. It defines an unregister() method that you can use to unregister the content scripts. Content scripts are also unregistered automatically when the page that created them is destroyed. For example, if they are registered from the background page they will be unregistered automatically when the background page is destroyed, and if they are registered from a sidebar or a popup, they will be unregistered automatically when the sidebar or popup is closed.

There is no contentScripts API permission, but an extension must have the appropriate host permissions for any patterns it passes to register().

Types

contentScripts.RegisteredContentScript

An object of this type is returned by the contentScripts.register() function. It represents the content scripts that were registered by that call, and can be used to unregister the content script.

Functions

contentScripts.register()
Registers the given content scripts.

Browser compatibility

BCD tables only load in the browser

Example extensions

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:128 次

字数:3409

最后编辑:6 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文