Bug 1429425 - contentScripts.register runAt option should be set to document_idle when missing. draft
authorLuca Greco <lgreco@mozilla.com>
Wed, 31 Jan 2018 20:55:39 +0100
changeset 749605 b42551eb54a04370aeda30af2828fcc16b816efc
parent 749604 3804441e575c9f46fcb03894de3c780eeae7197f
push id97456
push userluca.greco@alcacoop.it
push dateWed, 31 Jan 2018 19:57:09 +0000
bugs1429425
milestone60.0a1
Bug 1429425 - contentScripts.register runAt option should be set to document_idle when missing. MozReview-Commit-ID: 1D1J8zmVWqC
toolkit/components/extensions/ext-contentScripts.js
toolkit/components/extensions/test/xpcshell/test_ext_contentScripts_register.js
--- a/toolkit/components/extensions/ext-contentScripts.js
+++ b/toolkit/components/extensions/ext-contentScripts.js
@@ -63,17 +63,17 @@ class ContentScriptParent {
 
     const options = {
       matches: details.matches,
       exclude_matches: details.excludeMatches,
       include_globs: details.includeGlobs,
       exclude_globs: details.excludeGlobs,
       all_frames: details.allFrames,
       match_about_blank: details.matchAboutBlank,
-      run_at: details.runAt,
+      run_at: details.runAt || "document_idle",
       js: [],
       css: [],
     };
 
     const convertCodeToURL = (data, mime) => {
       const blob = new context.cloneScope.Blob(data, {type: mime});
       const blobURL = context.cloneScope.URL.createObjectURL(blob);
 
--- a/toolkit/components/extensions/test/xpcshell/test_ext_contentScripts_register.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_contentScripts_register.js
@@ -303,17 +303,16 @@ add_task(async function test_contentscri
         js: [{code: `(${textScriptCodeEnd})()`}],
         runAt: "document_end",
       },
       {
         matches: ["http://localhost/*/file_sample.html"],
         js: [{code: `(${textScriptCodeIdle})()`}],
         runAt: "document_idle",
       },
-
       // Extension URLs.
       {
         matches: ["http://localhost/*/file_sample.html"],
         js: [{file: "content_script_start.js"}],
         runAt: "document_start",
       },
       {
         matches: ["http://localhost/*/file_sample.html"],
@@ -323,17 +322,17 @@ add_task(async function test_contentscri
       {
         matches: ["http://localhost/*/file_sample.html"],
         js: [{file: "content_script_idle.js"}],
         runAt: "document_idle",
       },
       {
         matches: ["http://localhost/*/file_sample.html"],
         js: [{file: "content_script.js"}],
-        runAt: "document_idle",
+        // do not specify a runAt to ensure that it defaults to document_idle when missing.
       },
     ];
 
     const expectedAPIs = ["unregister"];
 
     for (const scriptOptions of content_scripts) {
       const script = await browser.contentScripts.register(scriptOptions);
       const actualAPIs = Object.keys(script);