How to upgrade extension to manifest v2 and remain

2019-08-25 18:31发布

I want to upgrade all my extensions to version 2 but still remain backward compatible for people that still have an older versions of chrome installed.

Since multiple manifest versions are currently unsupported, I would like to know which is the lowest version of Chrome that will support "manifest_version": 2 and its properties.

1条回答
我命由我不由天
2楼-- · 2019-08-25 18:49

Manifest v2 was introduced in Chrome 18. Using Manifest version 2 adds several requirements to a extension, the most significant being:

  1. The default Content Security Policy which disallows external JavaScript files to be loaded via <script> tags in extension's context, and which disallowes execution of JavaScript code which are created via a string: Inline event listeners, inline scripts, eval, etc.
    A consequence of broken features are JSONP and eval-based templating engines. These can be solved by using ordinary cross-site AJAX respectively the sandbox Chrome 21+.
  2. The web_accessible_resources field is initiated at an empty list and hence all resources are blacklisted by default.
  3. The "background_page" manifest entry becomes unavailable (superseded by "background" + "scripts" or "page").

Manifest 2 also allows some APIs to be used, for example the chrome.storage API. When manifest v2 is left out, this message will appear below your extension.

Except for the last remark, all of these requirements result in a stricter coding guideline for Chrome extensions (compared to manifest v1).

  1. Any code which complies with the CSP is also working in manifest v1.
  2. All of the extension's sources are whitelisted, thus accessible to ordinary web pages.
  3. "background": {"scripts": ["..."]} (and "page") is backwards-incompatible with Chrome 17 and lower, because it's introduced in Chrome 18. Use "background_page": "background.html" instead.

One extension for all Chrome versions can only be used if you're not using a background page. In other cases, such a hybrid (manifest v1+v2 compatible) extension cannot be achieved.

If you intend to distribute two different extensions, set "minimum_chrome_version": "18" in your manifest file. Don't forget to mention the location of the extension for older browsers.

查看更多
登录 后发表回答