Bug 1499533 - Fix console log stringifying bug in webcompat reporter; r=miketaylr
authorThomas Wisniewski <twisniewski@mozilla.com>
Thu, 18 Oct 2018 02:51:30 +0000
changeset 497599 8f1ae707ff7ba362c9931054c9f927141b20a2f7
parent 497598 adb07f2a1331142569039567d81f5168ada17198
child 497600 856c528a098312ad0ee77b5c6960993974ed19f4
push id9996
push userarchaeopteryx@coole-files.de
push dateThu, 18 Oct 2018 18:37:15 +0000
treeherdermozilla-beta@8efe26839243 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmiketaylr
bugs1499533
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1499533 - Fix console log stringifying bug in webcompat reporter; r=miketaylr Fix console log stringifying bug in webcompat reporter Differential Revision: https://phabricator.services.mozilla.com/D8984
browser/extensions/webcompat-reporter/experimentalAPIs/tabExtras.js
browser/extensions/webcompat-reporter/test/browser/browser_report_site_issue.js
browser/extensions/webcompat-reporter/test/browser/test.html
--- a/browser/extensions/webcompat-reporter/experimentalAPIs/tabExtras.js
+++ b/browser/extensions/webcompat-reporter/experimentalAPIs/tabExtras.js
@@ -42,18 +42,18 @@ function getInfoFrameScript(messageName)
                               .getService(Ci.nsIConsoleAPIStorage);
     let messages = [];
     for (const id of windowIds) {
       messages = messages.concat(ConsoleAPIStorage.getEvents(id) || []);
     }
     return messages.map(evt => {
       const {columnNumber, filename, level, lineNumber, timeStamp} = evt;
       const args = evt.arguments.map(arg => {
-        return arg.toString();
-      });
+        return "" + arg;
+      }).join(", ");
       const message = `[console.${level}(${args}) ${filename}:${lineNumber}:${columnNumber}]`;
       return {timeStamp, message};
     });
   }
 
   function getScriptErrors(windowIds, includePrivate = false) {
     const messages = Services.console.getMessageArray() || [];
     return messages.filter(message => {
--- a/browser/extensions/webcompat-reporter/test/browser/browser_report_site_issue.js
+++ b/browser/extensions/webcompat-reporter/test/browser/browser_report_site_issue.js
@@ -56,16 +56,19 @@ add_task(async function test_opened_page
     let urlParam = doc.getElementById("url").innerText;
     let preview = doc.getElementById("screenshot-preview");
     is(urlParam, args.TEST_PAGE, "Reported page is correctly added to the url param");
 
     let detailsParam = doc.getElementById("details").innerText;
     const details = JSON.parse(detailsParam);
     ok(typeof details == "object", "Details param is a stringified JSON object.");
     ok(Array.isArray(details.consoleLog), "Details has a consoleLog array.");
+    ok(details.consoleLog[0].match(/console\.log\(null\)[\s\S]*test.html:\d+:\d+/m), "Can handle degenerate console logs");
+    ok(details.consoleLog[1].match(/console\.error\(colored message\)[\s\S]*test.html:\d+:\d+/m), "Can handle fancy console logs");
+    ok(details.consoleLog[2].match(/document\.access is undefined[\s\S]*test.html:\d+:\d+/m), "Script errors are logged");
     ok(typeof details.buildID == "string", "Details has a buildID string.");
     ok(typeof details.channel == "string", "Details has a channel string.");
     ok(typeof details.hasTouchScreen == "boolean", "Details has a hasTouchScreen flag.");
     ok(typeof details["mixed active content blocked"] == "boolean", "Details has a mixed active content blocked flag.");
     ok(typeof details["mixed passive content blocked"] == "boolean", "Details has a mixed passive content blocked flag.");
     ok(typeof details["tracking content blocked"] == "string", "Details has a tracking content blocked string.");
     ok(typeof details["gfx.webrender.all"] == "boolean", "Details has gfx.webrender.all.");
     ok(typeof details["gfx.webrender.blob-images"] == "boolean", "Details has gfx.webrender.blob-images.");
--- a/browser/extensions/webcompat-reporter/test/browser/test.html
+++ b/browser/extensions/webcompat-reporter/test/browser/test.html
@@ -1,5 +1,13 @@
 <!DOCTYPE html>
 <meta charset="utf-8">
+<script>
+  /* eslint-disable no-console */
+  /* eslint-disable no-unused-expressions */
+  "use strict";
+  console.log(null);
+  console.error("%ccolored message", "background:green; color:white");
+  document.access.non.existent.property.to.trigger.error;
+</script>
 <style>
   body {background: rgb(0, 128, 0);}
 </style>