2

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?

LeoR
  • 666
  • 1
  • 6
  • 20

1 Answers1

4

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, {}));
// ...
Community
  • 1
  • 1
Rob W
  • 341,306
  • 83
  • 791
  • 678