Skip to content

Instantly share code, notes, and snippets.

@luckyrat
Created May 22, 2015 11:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luckyrat/7803415810fb4c09c975 to your computer and use it in GitHub Desktop.
Save luckyrat/7803415810fb4c09c975 to your computer and use it in GitHub Desktop.
importGlobalProperties test JSM
// JSM for working out which globalproperties can be imported in a specific Firefox version.
// https://developer.mozilla.org/en-US/docs/Components.utils.importGlobalProperties
// I'm not certain availability always equates to functionality but it probably does
// and in any case it's a way to narrow down the more involved test for functionality of each property
// Run from browser toolbox scratchpad like:
// Components.utils.import("resource://test-importGlobalProperties-addon/test.jsm");
Components.utils.import("resource://gre/modules/devtools/Console.jsm");
let props = ["does-not-exist", "atob", "Blob", "btoa", "crypto", "CSS", "File",
"indexedDB", "rtcIdentityProvider", "TextDecoder", "TextEncoder",
"URL", "URLSearchParams", "XMLHttpRequest" ];
for (let prop of props)
{
try {
Components.utils.importGlobalProperties([].concat(prop));
console.log(prop + " available");
} catch (e)
{
console.log(e);
}
}
var EXPORTED_SYMBOLS = [];
@Noitidart
Copy link

Awesomeness thanks very much! Slightly modified so the error messages arent overwhelming, for readability:

// JSM for working out which globalproperties can be imported in a specific Firefox version.
// https://developer.mozilla.org/en-US/docs/Components.utils.importGlobalProperties
// I'm not certain availability always equates to functionality but it probably does
// and in any case it's a way to narrow down the more involved test for functionality of each property

// Run from browser toolbox scratchpad like:
// Components.utils.import("resource://test-importGlobalProperties-addon/test.jsm");

Components.utils.import("resource://gre/modules/devtools/Console.jsm");

let props = ["does-not-exist", "atob", "Blob", "btoa", "crypto", "CSS", "File",
            "indexedDB", "rtcIdentityProvider", "TextDecoder", "TextEncoder", 
            "URL", "URLSearchParams", "XMLHttpRequest" ];

for (let prop of props)
{
    try {
        Components.utils.importGlobalProperties([].concat(prop));
        console.log(prop + " available");
    } catch (e)
    {
        if (e.message == 'Unknown property name: ' + prop) {
            console.error('UNAVAILABLE:', prop);
        } else {
            console.error(e);
        }
    }
}

var EXPORTED_SYMBOLS = [];

@Noitidart
Copy link

Run on Firefox 33 on Linux Mint:

"UNAVAILABLE: "does-not-exist"" Scratchpad/1:23
"atob available" Scratchpad/1:19
"UNAVAILABLE: "Blob"" Scratchpad/1:23
"btoa available" Scratchpad/1:19
"UNAVAILABLE: "crypto"" Scratchpad/1:23
"CSS available" Scratchpad/1:19
"UNAVAILABLE: "File"" Scratchpad/1:23
"indexedDB available" Scratchpad/1:19
"UNAVAILABLE: "rtcIdentityProvider"" Scratchpad/1:23
"TextDecoder available" Scratchpad/1:19
"TextEncoder available" Scratchpad/1:19
"URL available" Scratchpad/1:19
"UNAVAILABLE: "URLSearchParams"" Scratchpad/1:23
"XMLHttpRequest available" Scratchpad/1:19

@Noitidart
Copy link

Fx 37 on Ubuntu:

"UNAVAILABLE:" "does-not-exist" Scratchpad/1:23
"atob available" Scratchpad/1:19
"Blob available" Scratchpad/1:19
"btoa available" Scratchpad/1:19
"crypto available" Scratchpad/1:19
"CSS available" Scratchpad/1:19
"File available" Scratchpad/1:19
"indexedDB available" Scratchpad/1:19
"UNAVAILABLE:" "rtcIdentityProvider" Scratchpad/1:23
"TextDecoder available" Scratchpad/1:19
"TextEncoder available" Scratchpad/1:19
"URL available" Scratchpad/1:19
"URLSearchParams available" Scratchpad/1:19
"XMLHttpRequest available"

@Noitidart
Copy link

Fx34 on KaOSx

"UNAVAILABLE:" "does-not-exist" Scratchpad/1:23
"atob available" Scratchpad/1:19
"UNAVAILABLE:" "Blob" Scratchpad/1:23
"btoa available" Scratchpad/1:19
"UNAVAILABLE:" "crypto" Scratchpad/1:23
"CSS available" Scratchpad/1:19
"UNAVAILABLE:" "File" Scratchpad/1:23
"indexedDB available" Scratchpad/1:19
"UNAVAILABLE:" "rtcIdentityProvider" Scratchpad/1:23
"TextDecoder available" Scratchpad/1:19
"TextEncoder available" Scratchpad/1:19
"URL available" Scratchpad/1:19
"URLSearchParams available" Scratchpad/1:19
"XMLHttpRequest available" Scratchpad/1:19

@Noitidart
Copy link

Fx38 Win81

"UNAVAILABLE:" "does-not-exist" Scratchpad/1:23
"atob available" Scratchpad/4:19
"Blob available" Scratchpad/4:19
"btoa available" Scratchpad/4:19
"crypto available" Scratchpad/4:19
"CSS available" Scratchpad/4:19
"File available" Scratchpad/4:19
"indexedDB available" Scratchpad/4:19
"rtcIdentityProvider available" Scratchpad/4:19
"TextDecoder available" Scratchpad/4:19
"TextEncoder available" Scratchpad/4:19
"URL available" Scratchpad/4:19
"URLSearchParams available" Scratchpad/4:19
"XMLHttpRequest available" Scratchpad/4:19

@Noitidart
Copy link

Fx30.0.a2

"UNAVAILABLE:" "does-not-exist" Scratchpad/1:23
"atob available" Scratchpad/1:19
"UNAVAILABLE:" "Blob" Scratchpad/1:23
"btoa available" Scratchpad/1:19
"UNAVAILABLE:" "crypto" Scratchpad/1:23
"UNAVAILABLE:" "CSS" Scratchpad/1:23
"UNAVAILABLE:" "File" Scratchpad/1:23
"indexedDB available" Scratchpad/1:19
"UNAVAILABLE:" "rtcIdentityProvider" Scratchpad/1:23
"TextDecoder available" Scratchpad/1:19
"TextEncoder available" Scratchpad/1:19
"URL available" Scratchpad/1:19
"UNAVAILABLE:" "URLSearchParams" Scratchpad/1:23
"XMLHttpRequest available"

@luckyrat
Copy link
Author

FF36 (win7)

"UNAVAILABLE:" "does-not-exist" Scratchpad/1:32
"atob available" Scratchpad/1:28
"Blob available" Scratchpad/1:28
"btoa available" Scratchpad/1:28
"UNAVAILABLE:" "crypto" Scratchpad/1:32
"CSS available" Scratchpad/1:28
"File available" Scratchpad/1:28
"indexedDB available" Scratchpad/1:28
"UNAVAILABLE:" "rtcIdentityProvider" Scratchpad/1:32
"TextDecoder available" Scratchpad/1:28
"TextEncoder available" Scratchpad/1:28
"URL available" Scratchpad/1:28
"URLSearchParams available" Scratchpad/1:28
"XMLHttpRequest available" Scratchpad/1:28

@luckyrat
Copy link
Author

FF35 (win7)

"UNAVAILABLE:" "does-not-exist" Scratchpad/1:33
"atob available" Scratchpad/1:29
"Blob available" Scratchpad/1:29
"btoa available" Scratchpad/1:29
"UNAVAILABLE:" "crypto" Scratchpad/1:33
"CSS available" Scratchpad/1:29
"File available" Scratchpad/1:29
"indexedDB available" Scratchpad/1:29
"UNAVAILABLE:" "rtcIdentityProvider" Scratchpad/1:33
"TextDecoder available" Scratchpad/1:29
"TextEncoder available" Scratchpad/1:29
"URL available" Scratchpad/1:29
"URLSearchParams available" Scratchpad/1:29
"XMLHttpRequest available" Scratchpad/1:29

@luckyrat
Copy link
Author

FF32 (Win7)

"UNAVAILABLE:" "does-not-exist" Scratchpad/1:25
"atob available" Scratchpad/1:21
"UNAVAILABLE:" "Blob" Scratchpad/1:25
"btoa available" Scratchpad/1:21
"UNAVAILABLE:" "crypto" Scratchpad/1:25
"CSS available" Scratchpad/1:21
"UNAVAILABLE:" "File" Scratchpad/1:25
"indexedDB available" Scratchpad/1:21
"UNAVAILABLE:" "rtcIdentityProvider" Scratchpad/1:25
"TextDecoder available" Scratchpad/1:21
"TextEncoder available" Scratchpad/1:21
"URL available" Scratchpad/1:21
"UNAVAILABLE:" "URLSearchParams" Scratchpad/1:25
"XMLHttpRequest available" Scratchpad/1:21

@luckyrat
Copy link
Author

FF 31.6.0ESR (Win7):

"UNAVAILABLE:" "does-not-exist" Scratchpad/1:34
"atob available" Scratchpad/1:30
"UNAVAILABLE:" "Blob" Scratchpad/1:34
"btoa available" Scratchpad/1:30
"UNAVAILABLE:" "crypto" Scratchpad/1:34
"UNAVAILABLE:" "CSS" Scratchpad/1:34
"UNAVAILABLE:" "File" Scratchpad/1:34
"indexedDB available" Scratchpad/1:30
"UNAVAILABLE:" "rtcIdentityProvider" Scratchpad/1:34
"TextDecoder available" Scratchpad/1:30
"TextEncoder available" Scratchpad/1:30
"URL available" Scratchpad/1:30
"UNAVAILABLE:" "URLSearchParams" Scratchpad/1:34
"XMLHttpRequest available" Scratchpad/1:30

@luckyrat
Copy link
Author

FF28 and FF29 (win7) - identical results:

[object Error] Scratchpad/1:23
"atob available" Scratchpad/1:20
[object Error] Scratchpad/1:23
"btoa available" Scratchpad/1:20
[object Error] Scratchpad/1:23
[object Error] Scratchpad/1:23
[object Error] Scratchpad/1:23
"indexedDB available" Scratchpad/1:20
[object Error] Scratchpad/1:23
"TextDecoder available" Scratchpad/1:20
"TextEncoder available" Scratchpad/1:20
"URL available" Scratchpad/1:20
[object Error] Scratchpad/1:23
"XMLHttpRequest available" Scratchpad/1:20

@Noitidart
Copy link

So so fantastic thank you!!!! Ill review mdn :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment