我在哪里可以看到哪些Chrome扩展API对于哪个Chrome版本有效 [英] Where can I see which chrome extensions API is valid for which chrome version

查看:99
本文介绍了我在哪里可以看到哪些Chrome扩展API对于哪个Chrome版本有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢chrome通过其扩展API提供给我的内容。
但是我总是发现自己迷失在哪个chrome版本所支持的API的丛林中,以及最后一个chrome.experimental特性何时将其纳入支持的扩展中。



Chrome扩展程式页面让我很好地了解受支援的内容,但没有提到自什么版本。 实验性API概述也是如此。例如,该特定的API仍然是实验性的,或者它已经在金丝雀中受到支持。



如果我尝试从chrome 示例网站我通常必须从 chrome.experimental.foo chrome.foo ,或者发现它根本不被支持。 ( chrome.experimental.alarm ?)发生了什么?)这通常意味着只使用试验和错误方法来消除所有错误,直到样本运行。



tldr;
所以,我想知道是否有一个概览页面,告诉我自什么版本,什么API支持或何时决定放弃一个实验性的API。如果没有这样的网页,建议的方式或您的个人方法是如何处理这种情况的?

a href =http://www.chromium.org/developers/design-documents/extensions/how-the-extension-system-works/docs/how-docs-are-served =nofollow noreferrer> this页面中描述了生成官方文档的过程(从Chrome存储库自动生成)。在同一页面上,您还可以阅读如何检索旧分支的文档。请注意,文档在某种程度上是不完整的:尽管它们仍然存在(如 onRequest )。



扩展程序新增功能是API更改和更新的简要列表(不包括大多数的实验性API)。它必须手动编辑,所以它并不总是最新的。例如,当前的稳定版本是20,但该页面的最后一个条目是19.



如果您确实需要包含所有API的单个页面可以使用以下方法:


  • 首先,安装所有Chrome版本。自动完成后,这并不耗时:我编写了一个脚本,可以自动安装Chrome,它可以复制以前的配置文件:请参阅这个答案 存在以下功能:


    1. 编写一个清单文件,其中包含所有权限(始终忽略无法识别的权限)。

    2. Chrome 18+:使用清单版本1和2复制扩展。某些API在清单版本1中处于禁用状态(示例 )。
    3. 测试某个功能是否实现并且按预期运行非常耗时。出于这个原因,你最好测试API的存在。

      这样做的一个合理的方式是递归地遍历 chrome ,然后记录结果(显示给用户/发布到服务器)。

    4. 测试过程。使用以下方法之一:


      • 使用一个Chrome配置文件,并以最低版本开始测试。 为每个Chrome版本使用单独的配置文件,以便您可以并排测试多个Chrome版本。


    5. 后处理:解读结果。



获取信息的示例代码:

  / ** 
*返回一个显示所有已定义方法的JSON序列化对象
* @param root Root,例如。 chrome
* @param results Object,结果将如{tabs:{get:'function'}}
* /
函数getInfo(root,results){
if (root == null)返回结果;
var keys = Object.keys(root),i,key;
结果=结果|| {};
for(i = 0; i key = keys [i];
switch(typeof root [key]){
casefunction:
results [key] ='function';
休息;
caseobject:
if(subtree instanceof Array)break; //排除数组
var subtree = results [key] = {};
getInfo(root [key],subtree); //递归
break;
默认值:
/ *您是否真的想知道基元?
*(如chrome.windows.WINDOW_ID_NONE)* /
}
}
返回结果;
}
/ *示例:获取数据,以便将其保存以供以后使用* /
var dataToPostForLaterComparision = JSON.stringify(getInfo(chrome,{}));
// ...


I love what chrome offers me through its extension API. But I always find myself lost in the jungle of what API is supported by which chrome version and when did the last chrome.experimental feature make it into the supported extensions.

The Chrome extension page gives me a nice overview what is supported, but without mentioning since what version. The same is true for the experimental API overview. Is that specific API still experimental or is it already supported in canary, for example.

If I try a sample from the chrome Samples website I usually have to change some API calls from chrome.experimental.foo to chrome.foo or find out that it is not supported at all. (What happened to chrome.experimental.alarm?) That usually means to just use the trial and error approach to eliminate all errors, until the sample works.

tldr; So, I'm wondering is there an overview page which tells me since what version, what API is supported or when it was decided to drop an experimental API. And if there is no such page, what is the recommended way or your personal approach to deal with this situation?

解决方案

On this page, the process of generating the official documentation (automatically from the Chrome repository) is described. On the same page, you can also read how to retrieve documentation for older branches. Note that the documentation is somehow incomplete: Deprecated APIs are included immediately, although they're still existent (such as onRequest).

What's New in Extensions is a brief list of API changes and updates (excluding most of the experimental APIs). It has to be manually edited, so it's not always up-to-date. For example, the current stable version is 20, but the page's last entry is 19.

If you really need a single page containing all API changes, the following approach can be used:

  • First, install all Chrome versions. This is not time consuming when done automatically: I've written a script which automates the installation of Chrome, which duplicates a previous profile: see this answer.
  • Testing for the existence of the feature:

    1. Write a manifest file which includes all permissions (unrecognised permissions are always ignored).
    2. Chrome 18+: Duplicate the extension with manifest version 1 and 2. Some APIs are disabled in manifest version 1 (example).
    3. Testing whether a feature is implemented and behaving as expected is very time-consuming. For this reason, you'd better test for the existence of an API.
      A reasonable manner to do this is to recursively loop through the properties of chrome, and log the results (displayed to user / posted to a server).

  • The process of testing. Use one of the following methods:
    • Use a single Chrome profile, and start testing at the lowest version.
    • Use a separate profile for each Chrome version, so that you can test multiple Chrome versions side-by-side.
  • Post-processing: Interpret the results.

Example code to get information:

/** 
 * Returns a JSON-serializable object which shows all defined methods
 * @param root    Root, eg.  chrome
 * @param results Object, the result will look like {tabs:{get:'function'}}
 */
function getInfo(root, results) {
    if (root == null) return results;
    var keys = Object.keys(root), i, key;
    results = results || {};
    for (i=0; i<keys.length; i++) {
        key = keys[i];
        switch (typeof root[key]) {
            case "function":
                results[key] = 'function';
            break;
            case "object":
                if (subtree instanceof Array) break; // Exclude arrays
                var subtree = results[key] = {};
                getInfo(root[key], subtree);         // Recursion
            break;
            default:
                /* Do you really want to know about primitives?
                 * ( Such as chrome.windows.WINDOW_ID_NONE ) */
        }
    }
    return results;
}
/* Example: Get data, so that it can be saved for later use */
var dataToPostForLaterComparision = JSON.stringify(getInfo(chrome, {}));
// ...

这篇关于我在哪里可以看到哪些Chrome扩展API对于哪个Chrome版本有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆