summaryrefslogtreecommitdiffstats
path: root/dom/serviceworkers/test/console_monitor.js
blob: e3c347b1539202d9b0191b279fad878fc1c4a55e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* eslint-env mozilla/chrome-script */

let consoleListener;

function ConsoleListener() {
  Services.console.registerListener(this);
}

ConsoleListener.prototype = {
  callbacks: [],

  observe: aMsg => {
    if (!(aMsg instanceof Ci.nsIScriptError)) {
      return;
    }

    let msg = {
      cssSelectors: aMsg.cssSelectors,
      errorMessage: aMsg.errorMessage,
      sourceName: aMsg.sourceName,
      sourceLine: aMsg.sourceLine,
      lineNumber: aMsg.lineNumber,
      columnNumber: aMsg.columnNumber,
      category: aMsg.category,
      windowID: aMsg.outerWindowID,
      innerWindowID: aMsg.innerWindowID,
      isScriptError: true,
      isWarning: (aMsg.flags & Ci.nsIScriptError.warningFlag) === 1,
    };

    sendAsyncMessage("monitor", msg);
  },
};

addMessageListener("load", function(e) {
  consoleListener = new ConsoleListener();
  sendAsyncMessage("ready", {});
});

addMessageListener("unload", function(e) {
  Services.console.unregisterListener(consoleListener);
  consoleListener = null;
  sendAsyncMessage("unloaded", {});
});