Bug 1442778 - Add "chromeContext" parameter to console API and console service messages. r=smaug
authorEden Chuang <echuang@mozilla.com>
Mon, 01 Apr 2019 22:42:34 +0000
changeset 467518 642420401dbe4795fd32d7c3de41d2dad5d733bc
parent 467517 6ccad746f5d83af425dec5b26c5bca6f6bcfbb46
child 467519 3305707514a18ff272af09a9e426819b9b47dc6a
push id82019
push useraiakab@mozilla.com
push dateTue, 02 Apr 2019 02:19:51 +0000
treeherderautoland@642420401dbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1442778
milestone68.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 1442778 - Add "chromeContext" parameter to console API and console service messages. r=smaug 1. Adding a new attribute chromeContext in ConsoleEvent 2. Adding a new boolean attribute isFromChromeContext in nsIConsoleMessage 3. Sending IsFromChromeContext to the parent process Differential Revision: https://phabricator.services.mozilla.com/D23330
caps/nsScriptSecurityManager.cpp
chrome/nsChromeRegistry.cpp
devtools/client/webconsole/test/fixtures/stubs/consoleApi.js
dom/base/PostMessageEvent.cpp
dom/base/PostMessageEvent.h
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
dom/base/nsFrameMessageManager.cpp
dom/base/nsGlobalWindowOuter.cpp
dom/bindings/nsIScriptError.idl
dom/bindings/nsScriptError.cpp
dom/bindings/nsScriptError.h
dom/console/Console.cpp
dom/console/ConsoleInstance.cpp
dom/console/tests/test_console_binding.html
dom/console/tests/test_devtools_pref.html
dom/console/tests/test_jsm.xul
dom/indexedDB/ReportInternalError.cpp
dom/indexedDB/ScriptErrorHelper.cpp
dom/ipc/ContentChild.cpp
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
dom/ipc/PContent.ipdl
dom/localstorage/ReportInternalError.cpp
dom/quota/ActorsParent.cpp
dom/security/nsCSPUtils.cpp
dom/webidl/Console.webidl
dom/websocket/WebSocket.cpp
js/ipc/JavaScriptParent.cpp
js/xpconnect/src/XPCWrappedNativeInfo.cpp
netwerk/protocol/http/HttpChannelChild.cpp
netwerk/protocol/http/nsCORSListenerProxy.cpp
netwerk/protocol/http/nsCORSListenerProxy.h
security/manager/ssl/nsNSSCallbacks.cpp
toolkit/components/telemetry/core/TelemetryCommon.cpp
toolkit/modules/Console.jsm
xpcom/components/ManifestParser.cpp
xpcom/ds/nsObserverService.cpp
--- a/caps/nsScriptSecurityManager.cpp
+++ b/caps/nsScriptSecurityManager.cpp
@@ -1143,17 +1143,18 @@ nsresult nsScriptSecurityManager::Report
   nsCOMPtr<nsIConsoleService> console(
       do_GetService(NS_CONSOLESERVICE_CONTRACTID));
   NS_ENSURE_TRUE(console, NS_ERROR_FAILURE);
   nsCOMPtr<nsIScriptError> error(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
   NS_ENSURE_TRUE(error, NS_ERROR_FAILURE);
 
   // using category of "SOP" so we can link to MDN
   rv = error->Init(message, EmptyString(), EmptyString(), 0, 0,
-                   nsIScriptError::errorFlag, "SOP", aFromPrivateWindow);
+                   nsIScriptError::errorFlag, "SOP", aFromPrivateWindow,
+                   true /* From chrome context */);
   NS_ENSURE_SUCCESS(rv, rv);
   console->LogMessage(error);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsScriptSecurityManager::CheckLoadURIStrWithPrincipal(
     nsIPrincipal* aPrincipal, const nsACString& aTargetURIStr,
--- a/chrome/nsChromeRegistry.cpp
+++ b/chrome/nsChromeRegistry.cpp
@@ -75,20 +75,20 @@ void nsChromeRegistry::LogMessageWithCon
   va_start(args, aMsg);
   mozilla::SmprintfPointer formatted = mozilla::Vsmprintf(aMsg, args);
   va_end(args);
   if (!formatted) return;
 
   nsCString spec;
   if (aURL) aURL->GetSpec(spec);
 
-  rv = error->Init(NS_ConvertUTF8toUTF16(formatted.get()),
-                   NS_ConvertUTF8toUTF16(spec), EmptyString(), aLineNumber, 0,
-                   flags, "chrome registration",
-                   false /* from private window */);
+  rv = error->Init(
+      NS_ConvertUTF8toUTF16(formatted.get()), NS_ConvertUTF8toUTF16(spec),
+      EmptyString(), aLineNumber, 0, flags, "chrome registration",
+      false /* from private window */, true /* from chrome context */);
 
   if (NS_FAILED(rv)) return;
 
   console->LogMessage(error);
 }
 
 nsChromeRegistry::~nsChromeRegistry() { gChromeRegistry = nullptr; }
 
--- a/devtools/client/webconsole/test/fixtures/stubs/consoleApi.js
+++ b/devtools/client/webconsole/test/fixtures/stubs/consoleApi.js
@@ -2099,16 +2099,17 @@ stubPreparedMessages.set(`console.countR
 
 stubPackets.set(`console.log('foobar', 'test')`, {
   "message": {
     "addonId": "",
     "arguments": [
       "foobar",
       "test"
     ],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "log",
     "lineNumber": 1,
     "prefix": "",
@@ -2128,16 +2129,17 @@ stubPackets.set(`console.log('foobar', '
 stubPackets.set(`console.log(undefined)`, {
   "message": {
     "addonId": "",
     "arguments": [
       {
         "type": "undefined"
       }
     ],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "log",
     "lineNumber": 1,
     "prefix": "",
@@ -2155,16 +2157,17 @@ stubPackets.set(`console.log(undefined)`
 });
 
 stubPackets.set(`console.warn('danger, will robinson!')`, {
   "message": {
     "addonId": "",
     "arguments": [
       "danger, will robinson!"
     ],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "warn",
     "lineNumber": 1,
     "prefix": "",
@@ -2184,16 +2187,17 @@ stubPackets.set(`console.warn('danger, w
 stubPackets.set(`console.log(NaN)`, {
   "message": {
     "addonId": "",
     "arguments": [
       {
         "type": "NaN"
       }
     ],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "log",
     "lineNumber": 1,
     "prefix": "",
@@ -2213,16 +2217,17 @@ stubPackets.set(`console.log(NaN)`, {
 stubPackets.set(`console.log(null)`, {
   "message": {
     "addonId": "",
     "arguments": [
       {
         "type": "null"
       }
     ],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "log",
     "lineNumber": 1,
     "prefix": "",
@@ -2240,16 +2245,17 @@ stubPackets.set(`console.log(null)`, {
 });
 
 stubPackets.set(`console.log('鼬')`, {
   "message": {
     "addonId": "",
     "arguments": [
       "鼬"
     ],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "log",
     "lineNumber": 1,
     "prefix": "",
@@ -2265,16 +2271,17 @@ stubPackets.set(`console.log('鼬')`, {
   "type": "consoleAPICall",
   "from": "server1.conn0.child1/consoleActor2"
 });
 
 stubPackets.set(`console.clear()`, {
   "message": {
     "addonId": "",
     "arguments": [],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "clear",
     "lineNumber": 1,
     "prefix": "",
@@ -2292,16 +2299,17 @@ stubPackets.set(`console.clear()`, {
 });
 
 stubPackets.set(`console.count('bar')`, {
   "message": {
     "addonId": "",
     "arguments": [
       "bar"
     ],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": {
       "count": 1,
       "label": "bar"
     },
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
@@ -2345,16 +2353,17 @@ stubPackets.set(`console.assert(false, {
           },
           "ownSymbols": [],
           "ownPropertiesLength": 1,
           "ownSymbolsLength": 0,
           "safeGetterValues": {}
         }
       }
     ],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "assert",
     "lineNumber": 1,
     "prefix": "",
@@ -2381,16 +2390,17 @@ stubPackets.set(`console.assert(false, {
 });
 
 stubPackets.set(`console.log('hello \nfrom \rthe \"string world!')`, {
   "message": {
     "addonId": "",
     "arguments": [
       "hello \nfrom \rthe \"string world!"
     ],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "log",
     "lineNumber": 1,
     "prefix": "",
@@ -2408,16 +2418,17 @@ stubPackets.set(`console.log('hello \nfr
 });
 
 stubPackets.set(`console.log('úṇĩçödê țĕșť')`, {
   "message": {
     "addonId": "",
     "arguments": [
       "úṇĩçödê țĕșť"
     ],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "log",
     "lineNumber": 1,
     "prefix": "",
@@ -2447,16 +2458,17 @@ stubPackets.set(`console.dirxml(window)`
         "sealed": false,
         "ownPropertyLength": 830,
         "preview": {
           "kind": "ObjectWithURL",
           "url": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html"
         }
       }
     ],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "dirxml",
     "lineNumber": 1,
     "prefix": "",
@@ -2492,16 +2504,17 @@ stubPackets.set(`console.log('myarray', 
           "items": [
             "red",
             "green",
             "blue"
           ]
         }
       }
     ],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "log",
     "lineNumber": 1,
     "prefix": "",
@@ -2529,16 +2542,17 @@ stubPackets.set(`console.log('myregex', 
         "class": "RegExp",
         "extensible": true,
         "frozen": false,
         "sealed": false,
         "ownPropertyLength": 1,
         "displayString": "/a.b.c/"
       }
     ],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "log",
     "lineNumber": 1,
     "prefix": "",
@@ -2573,16 +2587,17 @@ stubPackets.set(`console.table(['red', '
           "items": [
             "red",
             "green",
             "blue"
           ]
         }
       }
     ],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "table",
     "lineNumber": 1,
     "prefix": "",
@@ -2636,16 +2651,17 @@ stubPackets.set(`console.log('myobject',
           },
           "ownSymbols": [],
           "ownPropertiesLength": 3,
           "ownSymbolsLength": 0,
           "safeGetterValues": {}
         }
       }
     ],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "log",
     "lineNumber": 1,
     "prefix": "",
@@ -2663,16 +2679,17 @@ stubPackets.set(`console.log('myobject',
 });
 
 stubPackets.set(`console.debug('debug message');`, {
   "message": {
     "addonId": "",
     "arguments": [
       "debug message"
     ],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "debug",
     "lineNumber": 1,
     "prefix": "",
@@ -2690,16 +2707,17 @@ stubPackets.set(`console.debug('debug me
 });
 
 stubPackets.set(`console.info('info message');`, {
   "message": {
     "addonId": "",
     "arguments": [
       "info message"
     ],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "info",
     "lineNumber": 1,
     "prefix": "",
@@ -2717,16 +2735,17 @@ stubPackets.set(`console.info('info mess
 });
 
 stubPackets.set(`console.error('error message');`, {
   "message": {
     "addonId": "",
     "arguments": [
       "error message"
     ],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "error",
     "lineNumber": 1,
     "prefix": "",
@@ -2776,16 +2795,17 @@ stubPackets.set(`console.log('mymap')`, 
             [
               "key2",
               "value2"
             ]
           ]
         }
       }
     ],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "log",
     "lineNumber": 5,
     "prefix": "",
@@ -2820,16 +2840,17 @@ stubPackets.set(`console.log('myset')`, 
           "length": 2,
           "items": [
             "a",
             "b"
           ]
         }
       }
     ],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "log",
     "lineNumber": 2,
     "prefix": "",
@@ -2845,16 +2866,17 @@ stubPackets.set(`console.log('myset')`, 
   "type": "consoleAPICall",
   "from": "server1.conn0.child1/consoleActor2"
 });
 
 stubPackets.set(`console.trace()`, {
   "message": {
     "addonId": "",
     "arguments": [],
+    "chromeContext": false,
     "columnNumber": 11,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "testStacktraceFiltering",
     "groupName": "",
     "level": "trace",
     "lineNumber": 3,
     "prefix": "",
@@ -2937,16 +2959,17 @@ stubPackets.set(`console.trace('bar', {'
           "items": [
             1,
             2,
             3
           ]
         }
       }
     ],
+    "chromeContext": false,
     "columnNumber": 11,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "testStacktraceWithLog",
     "groupName": "",
     "level": "trace",
     "lineNumber": 3,
     "prefix": "",
@@ -2987,16 +3010,17 @@ stubPackets.set(`console.trace('bar', {'
 });
 
 stubPackets.set(`console.time('bar')`, {
   "message": {
     "addonId": "",
     "arguments": [
       "bar"
     ],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "time",
     "lineNumber": 2,
     "prefix": "",
@@ -3016,16 +3040,17 @@ stubPackets.set(`console.time('bar')`, {
 });
 
 stubPackets.set(`timerAlreadyExists`, {
   "message": {
     "addonId": "",
     "arguments": [
       "bar"
     ],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "time",
     "lineNumber": 3,
     "prefix": "",
@@ -3046,16 +3071,17 @@ stubPackets.set(`timerAlreadyExists`, {
 });
 
 stubPackets.set(`console.timeLog('bar') - 1`, {
   "message": {
     "addonId": "",
     "arguments": [
       "bar"
     ],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "timeLog",
     "lineNumber": 4,
     "prefix": "",
@@ -3101,16 +3127,17 @@ stubPackets.set(`console.timeLog('bar') 
           },
           "ownSymbols": [],
           "ownPropertiesLength": 1,
           "ownSymbolsLength": 0,
           "safeGetterValues": {}
         }
       }
     ],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "timeLog",
     "lineNumber": 5,
     "prefix": "",
@@ -3131,16 +3158,17 @@ stubPackets.set(`console.timeLog('bar') 
 });
 
 stubPackets.set(`console.timeEnd('bar')`, {
   "message": {
     "addonId": "",
     "arguments": [
       "bar"
     ],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "timeEnd",
     "lineNumber": 6,
     "prefix": "",
@@ -3161,16 +3189,17 @@ stubPackets.set(`console.timeEnd('bar')`
 });
 
 stubPackets.set(`timeEnd.timerDoesntExist`, {
   "message": {
     "addonId": "",
     "arguments": [
       "bar"
     ],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "timeEnd",
     "lineNumber": 7,
     "prefix": "",
@@ -3191,16 +3220,17 @@ stubPackets.set(`timeEnd.timerDoesntExis
 });
 
 stubPackets.set(`timeLog.timerDoesntExist`, {
   "message": {
     "addonId": "",
     "arguments": [
       "bar"
     ],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "timeLog",
     "lineNumber": 8,
     "prefix": "",
@@ -3221,16 +3251,17 @@ stubPackets.set(`timeLog.timerDoesntExis
 });
 
 stubPackets.set(`console.table('bar')`, {
   "message": {
     "addonId": "",
     "arguments": [
       "bar"
     ],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "table",
     "lineNumber": 2,
     "prefix": "",
@@ -3265,16 +3296,17 @@ stubPackets.set(`console.table(['a', 'b'
           "items": [
             "a",
             "b",
             "c"
           ]
         }
       }
     ],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "table",
     "lineNumber": 2,
     "prefix": "",
@@ -3292,16 +3324,17 @@ stubPackets.set(`console.table(['a', 'b'
 });
 
 stubPackets.set(`console.group('bar')`, {
   "message": {
     "addonId": "",
     "arguments": [
       "bar"
     ],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "bar",
     "level": "group",
     "lineNumber": 2,
     "prefix": "",
@@ -3317,16 +3350,17 @@ stubPackets.set(`console.group('bar')`, 
   "type": "consoleAPICall",
   "from": "server1.conn0.child1/consoleActor2"
 });
 
 stubPackets.set(`console.groupEnd('bar')`, {
   "message": {
     "addonId": "",
     "arguments": [],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "bar",
     "level": "groupEnd",
     "lineNumber": 3,
     "prefix": "",
@@ -3344,16 +3378,17 @@ stubPackets.set(`console.groupEnd('bar')
 });
 
 stubPackets.set(`console.groupCollapsed('foo')`, {
   "message": {
     "addonId": "",
     "arguments": [
       "foo"
     ],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "foo",
     "level": "groupCollapsed",
     "lineNumber": 2,
     "prefix": "",
@@ -3369,16 +3404,17 @@ stubPackets.set(`console.groupCollapsed(
   "type": "consoleAPICall",
   "from": "server1.conn0.child1/consoleActor2"
 });
 
 stubPackets.set(`console.groupEnd('foo')`, {
   "message": {
     "addonId": "",
     "arguments": [],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "foo",
     "level": "groupEnd",
     "lineNumber": 3,
     "prefix": "",
@@ -3394,16 +3430,17 @@ stubPackets.set(`console.groupEnd('foo')
   "type": "consoleAPICall",
   "from": "server1.conn0.child1/consoleActor2"
 });
 
 stubPackets.set(`console.group()`, {
   "message": {
     "addonId": "",
     "arguments": [],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "group",
     "lineNumber": 2,
     "prefix": "",
@@ -3419,16 +3456,17 @@ stubPackets.set(`console.group()`, {
   "type": "consoleAPICall",
   "from": "server1.conn0.child1/consoleActor2"
 });
 
 stubPackets.set(`console.groupEnd()`, {
   "message": {
     "addonId": "",
     "arguments": [],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "groupEnd",
     "lineNumber": 3,
     "prefix": "",
@@ -3447,16 +3485,17 @@ stubPackets.set(`console.groupEnd()`, {
 
 stubPackets.set(`console.log(%cfoobar)`, {
   "message": {
     "addonId": "",
     "arguments": [
       "foo",
       "bar"
     ],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "log",
     "lineNumber": 2,
     "prefix": "",
@@ -3479,16 +3518,17 @@ stubPackets.set(`console.log(%cfoobar)`,
 stubPackets.set(`console.log("%cHello%c|%cWorld")`, {
   "message": {
     "addonId": "",
     "arguments": [
       "Hello",
       "|",
       "World"
     ],
+    "chromeContext": false,
     "columnNumber": 11,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "log",
     "lineNumber": 2,
     "prefix": "",
@@ -3511,16 +3551,17 @@ stubPackets.set(`console.log("%cHello%c|
 
 stubPackets.set(`console.group(%cfoo%cbar)`, {
   "message": {
     "addonId": "",
     "arguments": [
       "foo",
       "bar"
     ],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "foo bar",
     "level": "group",
     "lineNumber": 2,
     "prefix": "",
@@ -3539,16 +3580,17 @@ stubPackets.set(`console.group(%cfoo%cba
   "type": "consoleAPICall",
   "from": "server1.conn0.child1/consoleActor2"
 });
 
 stubPackets.set(`console.groupEnd(%cfoo%cbar)`, {
   "message": {
     "addonId": "",
     "arguments": [],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "foo bar",
     "level": "groupEnd",
     "lineNumber": 6,
     "prefix": "",
@@ -3567,16 +3609,17 @@ stubPackets.set(`console.groupEnd(%cfoo%
 
 stubPackets.set(`console.groupCollapsed(%cfoo%cbaz)`, {
   "message": {
     "addonId": "",
     "arguments": [
       "foo",
       "baz"
     ],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "foo baz",
     "level": "groupCollapsed",
     "lineNumber": 2,
     "prefix": "",
@@ -3595,16 +3638,17 @@ stubPackets.set(`console.groupCollapsed(
   "type": "consoleAPICall",
   "from": "server1.conn0.child1/consoleActor2"
 });
 
 stubPackets.set(`console.groupEnd(%cfoo%cbaz)`, {
   "message": {
     "addonId": "",
     "arguments": [],
+    "chromeContext": false,
     "columnNumber": 9,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "foo baz",
     "level": "groupEnd",
     "lineNumber": 6,
     "prefix": "",
@@ -3663,16 +3707,17 @@ stubPackets.set(`console.dir({C, M, Y, K
           },
           "ownSymbols": [],
           "ownPropertiesLength": 4,
           "ownSymbolsLength": 0,
           "safeGetterValues": {}
         }
       }
     ],
+    "chromeContext": false,
     "columnNumber": 35,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "dir",
     "lineNumber": 1,
     "prefix": "",
@@ -3690,16 +3735,17 @@ stubPackets.set(`console.dir({C, M, Y, K
 });
 
 stubPackets.set(`console.count | default: 1`, {
   "message": {
     "addonId": "",
     "arguments": [
       "default"
     ],
+    "chromeContext": false,
     "columnNumber": 13,
     "counter": {
       "count": 1,
       "label": "default"
     },
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
@@ -3720,16 +3766,17 @@ stubPackets.set(`console.count | default
 });
 
 stubPackets.set(`console.count | default: 2`, {
   "message": {
     "addonId": "",
     "arguments": [
       "default"
     ],
+    "chromeContext": false,
     "columnNumber": 13,
     "counter": {
       "count": 2,
       "label": "default"
     },
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
@@ -3750,16 +3797,17 @@ stubPackets.set(`console.count | default
 });
 
 stubPackets.set(`console.count | test counter: 1`, {
   "message": {
     "addonId": "",
     "arguments": [
       "test counter"
     ],
+    "chromeContext": false,
     "columnNumber": 13,
     "counter": {
       "count": 1,
       "label": "test counter"
     },
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
@@ -3780,16 +3828,17 @@ stubPackets.set(`console.count | test co
 });
 
 stubPackets.set(`console.count | test counter: 2`, {
   "message": {
     "addonId": "",
     "arguments": [
       "test counter"
     ],
+    "chromeContext": false,
     "columnNumber": 13,
     "counter": {
       "count": 2,
       "label": "test counter"
     },
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
@@ -3810,16 +3859,17 @@ stubPackets.set(`console.count | test co
 });
 
 stubPackets.set(`console.count | default: 3`, {
   "message": {
     "addonId": "",
     "arguments": [
       "default"
     ],
+    "chromeContext": false,
     "columnNumber": 13,
     "counter": {
       "count": 3,
       "label": "default"
     },
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
@@ -3838,16 +3888,17 @@ stubPackets.set(`console.count | default
   "type": "consoleAPICall",
   "from": "server1.conn0.child1/consoleActor2"
 });
 
 stubPackets.set(`console.count | clear`, {
   "message": {
     "addonId": "",
     "arguments": [],
+    "chromeContext": false,
     "columnNumber": 13,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "clear",
     "lineNumber": 7,
     "prefix": "",
@@ -3865,16 +3916,17 @@ stubPackets.set(`console.count | clear`,
 });
 
 stubPackets.set(`console.count | default: 4`, {
   "message": {
     "addonId": "",
     "arguments": [
       "default"
     ],
+    "chromeContext": false,
     "columnNumber": 13,
     "counter": {
       "count": 4,
       "label": "default"
     },
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
@@ -3895,16 +3947,17 @@ stubPackets.set(`console.count | default
 });
 
 stubPackets.set(`console.count | test counter: 3`, {
   "message": {
     "addonId": "",
     "arguments": [
       "test counter"
     ],
+    "chromeContext": false,
     "columnNumber": 13,
     "counter": {
       "count": 3,
       "label": "test counter"
     },
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
@@ -3925,16 +3978,17 @@ stubPackets.set(`console.count | test co
 });
 
 stubPackets.set(`console.countReset | test counter: 0`, {
   "message": {
     "addonId": "",
     "arguments": [
       "test counter"
     ],
+    "chromeContext": false,
     "columnNumber": 13,
     "counter": {
       "count": 0,
       "label": "test counter"
     },
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
@@ -3955,16 +4009,17 @@ stubPackets.set(`console.countReset | te
 });
 
 stubPackets.set(`console.countReset | counterDoesntExist`, {
   "message": {
     "addonId": "",
     "arguments": [
       "test counter"
     ],
+    "chromeContext": false,
     "columnNumber": 13,
     "counter": {
       "error": "counterDoesntExist",
       "label": "test counter"
     },
     "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
--- a/dom/base/PostMessageEvent.cpp
+++ b/dom/base/PostMessageEvent.cpp
@@ -14,17 +14,16 @@
 #include "mozilla/dom/FileListBinding.h"
 #include "mozilla/dom/MessageEventBinding.h"
 #include "mozilla/dom/MessagePort.h"
 #include "mozilla/dom/MessagePortBinding.h"
 #include "mozilla/dom/PMessagePort.h"
 #include "mozilla/dom/StructuredCloneTags.h"
 #include "mozilla/dom/UnionConversions.h"
 #include "mozilla/EventDispatcher.h"
-#include "nsContentUtils.h"
 #include "nsDocShell.h"
 #include "nsGlobalWindow.h"
 #include "nsIConsoleService.h"
 #include "nsIPresShell.h"
 #include "nsIPrincipal.h"
 #include "nsIScriptError.h"
 #include "nsNetUtil.h"
 #include "nsPresContext.h"
@@ -132,19 +131,20 @@ PostMessageEvent::Run() {
         rv = errorObject->InitWithSourceURI(
             errorText, callerDocumentURI, EmptyString(), 0, 0,
             nsIScriptError::errorFlag, "DOM Window", mCallerWindowID.value());
       } else {
         nsString uriSpec;
         rv = NS_GetSanitizedURIStringFromURI(callerDocumentURI, uriSpec);
         NS_ENSURE_SUCCESS(rv, rv);
 
-        rv = errorObject->Init(errorText, uriSpec, EmptyString(), 0, 0,
-                               nsIScriptError::errorFlag, "DOM Window",
-                               mIsFromPrivateWindow);
+        rv = errorObject->Init(
+            errorText, uriSpec, EmptyString(), 0, 0, nsIScriptError::errorFlag,
+            "DOM Window", mIsFromPrivateWindow,
+            nsContentUtils::IsSystemPrincipal(mProvidedPrincipal));
       }
       NS_ENSURE_SUCCESS(rv, rv);
 
       nsCOMPtr<nsIConsoleService> consoleService =
           do_GetService(NS_CONSOLESERVICE_CONTRACTID, &rv);
       NS_ENSURE_SUCCESS(rv, rv);
 
       return consoleService->LogMessage(errorObject);
--- a/dom/base/PostMessageEvent.h
+++ b/dom/base/PostMessageEvent.h
@@ -8,16 +8,17 @@
 #define mozilla_dom_PostMessageEvent_h
 
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/ipc/StructuredCloneData.h"
 #include "mozilla/dom/StructuredCloneHolder.h"
 #include "nsCOMPtr.h"
 #include "mozilla/MaybeOneOf.h"
 #include "mozilla/RefPtr.h"
+#include "nsContentUtils.h"
 #include "nsTArray.h"
 #include "nsThreadUtils.h"
 
 class nsGlobalWindowOuter;
 class nsGlobalWindowInner;
 class nsIPrincipal;
 
 namespace mozilla {
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -3729,26 +3729,27 @@ nsresult nsContentUtils::FormatLocalized
   }
   return FormatLocalizedString(aFile, aKey, params.get(), paramsLength,
                                aResult);
 }
 
 /* static */
 void nsContentUtils::LogSimpleConsoleError(const nsAString& aErrorText,
                                            const char* classification,
-                                           bool aFromPrivateWindow) {
+                                           bool aFromPrivateWindow,
+                                           bool aFromChromeContext) {
   nsCOMPtr<nsIScriptError> scriptError =
       do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
   if (scriptError) {
     nsCOMPtr<nsIConsoleService> console =
         do_GetService(NS_CONSOLESERVICE_CONTRACTID);
-    if (console &&
-        NS_SUCCEEDED(scriptError->Init(aErrorText, EmptyString(), EmptyString(),
-                                       0, 0, nsIScriptError::errorFlag,
-                                       classification, aFromPrivateWindow))) {
+    if (console && NS_SUCCEEDED(scriptError->Init(
+                       aErrorText, EmptyString(), EmptyString(), 0, 0,
+                       nsIScriptError::errorFlag, classification,
+                       aFromPrivateWindow, aFromChromeContext))) {
       console->LogMessage(scriptError);
     }
   }
 }
 
 /* static */
 nsresult nsContentUtils::ReportToConsole(
     uint32_t aErrorFlags, const nsACString& aCategory,
@@ -5294,30 +5295,32 @@ nsContentUtils::GetMostRecentNonPBWindow
 
   return pwindow.forget();
 }
 
 /* static */
 void nsContentUtils::WarnScriptWasIgnored(Document* aDocument) {
   nsAutoString msg;
   bool privateBrowsing = false;
+  bool chromeContext = false;
 
   if (aDocument) {
     nsCOMPtr<nsIURI> uri = aDocument->GetDocumentURI();
     if (uri) {
       msg.Append(NS_ConvertUTF8toUTF16(uri->GetSpecOrDefault()));
       msg.AppendLiteral(" : ");
     }
     privateBrowsing =
         !!aDocument->NodePrincipal()->OriginAttributesRef().mPrivateBrowsingId;
+    chromeContext = IsSystemPrincipal(aDocument->NodePrincipal());
   }
 
   msg.AppendLiteral(
       "Unable to run script because scripts are blocked internally.");
-  LogSimpleConsoleError(msg, "DOM", privateBrowsing);
+  LogSimpleConsoleError(msg, "DOM", privateBrowsing, chromeContext);
 }
 
 /* static */
 void nsContentUtils::AddScriptRunner(already_AddRefed<nsIRunnable> aRunnable) {
   nsCOMPtr<nsIRunnable> runnable = aRunnable;
   if (!runnable) {
     return;
   }
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -1020,17 +1020,18 @@ class nsContentUtils {
 
   /**
    * Report simple error message to the browser console
    *   @param aErrorText the error message
    *   @param classification Name of the module reporting error
    */
   static void LogSimpleConsoleError(const nsAString& aErrorText,
                                     const char* classification,
-                                    bool aFromPrivateWindow);
+                                    bool aFromPrivateWindow,
+                                    bool aFromChromeContext);
 
   /**
    * Report a non-localized error message to the error console.
    *   @param aErrorText the error message
    *   @param aErrorFlags See nsIScriptError.
    *   @param aCategory Name of module reporting error.
    *   @param aDocument Reference to the document which triggered the message.
    *   @param [aURI=nullptr] (Optional) URI of resource containing error.
--- a/dom/base/nsFrameMessageManager.cpp
+++ b/dom/base/nsFrameMessageManager.cpp
@@ -404,17 +404,18 @@ bool nsFrameMessageManager::GetParamsFor
     uint32_t lineno = 0, column = 0;
     nsJSUtils::GetCallingLocation(aCx, filename, &lineno, &column);
     nsCOMPtr<nsIScriptError> error(
         do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
     error->Init(NS_LITERAL_STRING("Sending message that cannot be cloned. Are "
                                   "you trying to send an XPCOM object?"),
                 filename, EmptyString(), lineno, column,
                 nsIScriptError::warningFlag, "chrome javascript",
-                false /* from private window */);
+                false /* from private window */,
+                true /* from chrome context */);
     console->LogMessage(error);
   }
 
   // Not clonable, try JSON
   // XXX This is ugly but currently structured cloning doesn't handle
   //    properly cases when interface is implemented in JS and used
   //    as a dictionary.
   nsAutoString json;
@@ -819,17 +820,18 @@ void nsFrameMessageManager::ReceiveMessa
 
           nsCOMPtr<nsIConsoleService> console(
               do_GetService(NS_CONSOLESERVICE_CONTRACTID));
           if (console) {
             nsCOMPtr<nsIScriptError> error(
                 do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
             error->Init(msg, EmptyString(), EmptyString(), 0, 0,
                         nsIScriptError::warningFlag, "chrome javascript",
-                        false /* from private window */);
+                        false /* from private window */,
+                        true /* from chrome context */);
             console->LogMessage(error);
           }
 
           JS_ClearPendingException(cx);
           continue;
         }
       }
     }
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -5946,17 +5946,18 @@ bool nsGlobalWindowOuter::GetPrincipalFo
         }
 
         nsContentUtils::LogSimpleConsoleError(
             NS_ConvertUTF8toUTF16(nsPrintfCString(
                 R"(Attempting to post a message to window with url "%s" and )"
                 R"(origin "%s" from a system principal scope with mismatched )"
                 R"(origin "%s".)",
                 targetURL.get(), targetOrigin.get(), sourceOrigin.get())),
-            "DOM", !!principal->PrivateBrowsingId());
+            "DOM", !!principal->PrivateBrowsingId(),
+            nsContentUtils::IsSystemPrincipal(principal));
 
         attrs = principal->OriginAttributesRef();
       }
     }
 
     // Create a nsIPrincipal inheriting the app/browser attributes from the
     // caller.
     providedPrincipal =
--- a/dom/bindings/nsIScriptError.idl
+++ b/dom/bindings/nsIScriptError.idl
@@ -88,16 +88,18 @@ interface nsIScriptError : nsIConsoleMes
     readonly attribute unsigned long long outerWindowID;
 
     /* Get the inner window id this was initialized with.  Zero will be
        returned if init() was used instead of initWithWindowID(). */
     readonly attribute unsigned long long innerWindowID;
 
     readonly attribute boolean isFromPrivateWindow;
 
+    readonly attribute boolean isFromChromeContext;
+
     attribute jsval stack;
 
     /**
      * If |stack| is an object, then stackGlobal must be a global object that's
      * same-compartment with |stack|. This can be used to enter the correct
      * realm when working with the stack object. We can't use the object itself
      * because it might be a cross-compartment wrapper and CCWs are not
      * associated with a single realm/global.
@@ -126,17 +128,18 @@ interface nsIScriptError : nsIConsoleMes
 
     void init(in AString message,
               in AString sourceName,
               in AString sourceLine,
               in uint32_t lineNumber,
               in uint32_t columnNumber,
               in uint32_t flags,
               in string category,
-              [optional] in bool fromPrivateWindow);
+              [optional] in bool fromPrivateWindow,
+              [optional] in bool fromChromeContext);
 
     /* This should be called instead of nsIScriptError.init to
      * initialize with a window id.  The window id should be for the
      * inner window associated with this error.
      *
      * This function will check whether sourceName is a uri and sanitize it if
      * needed. If you know the source name is sanitized already, use
      * initWithSanitizedSource.
--- a/dom/bindings/nsScriptError.cpp
+++ b/dom/bindings/nsScriptError.cpp
@@ -40,17 +40,18 @@ nsScriptErrorBase::nsScriptErrorBase()
       mColumnNumber(0),
       mFlags(0),
       mCategory(),
       mOuterWindowID(0),
       mInnerWindowID(0),
       mTimeStamp(0),
       mTimeWarpTarget(0),
       mInitializedOnMainThread(false),
-      mIsFromPrivateWindow(false) {}
+      mIsFromPrivateWindow(false),
+      mIsFromChromeContext(false) {}
 
 nsScriptErrorBase::~nsScriptErrorBase() {}
 
 void nsScriptErrorBase::AddNote(nsIScriptErrorNote* note) {
   mNotes.AppendObject(note);
 }
 
 void nsScriptErrorBase::InitializeOnMainThread() {
@@ -58,17 +59,17 @@ void nsScriptErrorBase::InitializeOnMain
   MOZ_ASSERT(!mInitializedOnMainThread);
 
   if (mInnerWindowID) {
     nsGlobalWindowInner* window =
         nsGlobalWindowInner::GetInnerWindowWithId(mInnerWindowID);
     if (window) {
       nsPIDOMWindowOuter* outer = window->GetOuterWindow();
       if (outer) mOuterWindowID = outer->WindowID();
-
+      mIsFromChromeContext = ComputeIsFromChromeContext(window);
       mIsFromPrivateWindow = ComputeIsFromPrivateWindow(window);
     }
   }
 
   mInitializedOnMainThread = true;
 }
 
 NS_IMETHODIMP
@@ -212,23 +213,25 @@ static void AssignSourceNameHelper(nsIUR
     aSourceNameDest.AssignLiteral("[nsIURI::GetSpec failed]");
   }
 }
 
 NS_IMETHODIMP
 nsScriptErrorBase::Init(const nsAString& message, const nsAString& sourceName,
                         const nsAString& sourceLine, uint32_t lineNumber,
                         uint32_t columnNumber, uint32_t flags,
-                        const char* category, bool fromPrivateWindow) {
+                        const char* category, bool fromPrivateWindow,
+                        bool fromChromeContext) {
   InitializationHelper(message, sourceLine, lineNumber, columnNumber, flags,
                        category ? nsDependentCString(category) : EmptyCString(),
                        0 /* inner Window ID */);
   AssignSourceNameHelper(mSourceName, sourceName);
 
   mIsFromPrivateWindow = fromPrivateWindow;
+  mIsFromChromeContext = fromChromeContext;
   return NS_OK;
 }
 
 void nsScriptErrorBase::InitializationHelper(
     const nsAString& message, const nsAString& sourceLine, uint32_t lineNumber,
     uint32_t columnNumber, uint32_t flags, const nsACString& category,
     uint64_t aInnerWindowID) {
   mMessage.Assign(message);
@@ -389,16 +392,28 @@ nsScriptErrorBase::SetTimeWarpTarget(uin
 
 NS_IMETHODIMP
 nsScriptErrorBase::GetTimeWarpTarget(uint64_t* aTarget) {
   *aTarget = mTimeWarpTarget;
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsScriptErrorBase::GetIsFromChromeContext(bool* aIsFromChromeContext) {
+  NS_WARNING_ASSERTION(NS_IsMainThread() || mInitializedOnMainThread,
+                       "This can't be safely determined off the main thread, "
+                       "returning an inaccurate value!");
+  if (!mInitializedOnMainThread && NS_IsMainThread()) {
+    InitializeOnMainThread();
+  }
+  *aIsFromChromeContext = mIsFromChromeContext;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsScriptErrorBase::GetNotes(nsIArray** aNotes) {
   nsresult rv = NS_OK;
   nsCOMPtr<nsIMutableArray> array = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   uint32_t len = mNotes.Length();
   for (uint32_t i = 0; i < len; i++) array->AppendElement(mNotes[i]);
   array.forget(aNotes);
@@ -411,16 +426,23 @@ bool nsScriptErrorBase::ComputeIsFromPri
     nsGlobalWindowInner* aWindow) {
   // Never mark exceptions from chrome windows as having come from private
   // windows, since we always want them to be reported.
   nsIPrincipal* winPrincipal = aWindow->GetPrincipal();
   return aWindow->IsPrivateBrowsing() &&
          !nsContentUtils::IsSystemPrincipal(winPrincipal);
 }
 
+/* static */
+bool nsScriptErrorBase::ComputeIsFromChromeContext(
+    nsGlobalWindowInner* aWindow) {
+  nsIPrincipal* winPrincipal = aWindow->GetPrincipal();
+  return nsContentUtils::IsSystemPrincipal(winPrincipal);
+}
+
 NS_IMPL_ISUPPORTS(nsScriptError, nsIConsoleMessage, nsIScriptError)
 
 nsScriptErrorNote::nsScriptErrorNote()
     : mMessage(),
       mSourceName(),
       mSourceId(0),
       mLineNumber(0),
       mColumnNumber(0) {}
--- a/dom/bindings/nsScriptError.h
+++ b/dom/bindings/nsScriptError.h
@@ -50,16 +50,18 @@ class nsScriptErrorBase : public nsIScri
 
   NS_DECL_NSICONSOLEMESSAGE
   NS_DECL_NSISCRIPTERROR
 
   void AddNote(nsIScriptErrorNote* note);
 
   static bool ComputeIsFromPrivateWindow(nsGlobalWindowInner* aWindow);
 
+  static bool ComputeIsFromChromeContext(nsGlobalWindowInner* aWindow);
+
  protected:
   virtual ~nsScriptErrorBase();
 
   void InitializeOnMainThread();
 
   void InitializationHelper(const nsAString& message,
                             const nsAString& sourceLine, uint32_t lineNumber,
                             uint32_t columnNumber, uint32_t flags,
@@ -77,20 +79,21 @@ class nsScriptErrorBase : public nsIScri
   uint32_t mColumnNumber;
   uint32_t mFlags;
   nsCString mCategory;
   // mOuterWindowID is set on the main thread from InitializeOnMainThread().
   uint64_t mOuterWindowID;
   uint64_t mInnerWindowID;
   int64_t mTimeStamp;
   uint64_t mTimeWarpTarget;
-  // mInitializedOnMainThread and mIsFromPrivateWindow are set on the main
-  // thread from InitializeOnMainThread().
+  // mInitializedOnMainThread, mIsFromPrivateWindow and mIsFromChromeContext are
+  // set on the main thread from InitializeOnMainThread().
   mozilla::Atomic<bool> mInitializedOnMainThread;
   bool mIsFromPrivateWindow;
+  bool mIsFromChromeContext;
 };
 
 class nsScriptError final : public nsScriptErrorBase {
  public:
   nsScriptError() {}
   NS_DECL_THREADSAFE_ISUPPORTS
 
  private:
--- a/dom/console/Console.cpp
+++ b/dom/console/Console.cpp
@@ -1271,16 +1271,17 @@ void Console::ProfileMethodInternal(JSCo
 // static
 void Console::ProfileMethodMainthread(JSContext* aCx, const nsAString& aAction,
                                       const Sequence<JS::Value>& aData) {
   MOZ_ASSERT(NS_IsMainThread());
   ConsoleCommon::ClearException ce(aCx);
 
   RootedDictionary<ConsoleProfileEvent> event(aCx);
   event.mAction = aAction;
+  event.mChromeContext = nsContentUtils::ThreadsafeIsSystemCaller(aCx);
 
   event.mArguments.Construct();
   Sequence<JS::Value>& sequence = event.mArguments.Value();
 
   for (uint32_t i = 0; i < aData.Length(); ++i) {
     if (!sequence.AppendElement(aData[i], fallible)) {
       return;
     }
@@ -1678,16 +1679,18 @@ bool Console::PopulateConsoleNotificatio
   ConsoleCommon::ClearException ce(aCx);
   RootedDictionary<ConsoleEvent> event(aCx);
 
   event.mAddonId = aData->mAddonId;
 
   event.mID.Construct();
   event.mInnerID.Construct();
 
+  event.mChromeContext = nsContentUtils::ThreadsafeIsSystemCaller(aCx);
+
   if (aData->mIDType == ConsoleCallData::eString) {
     event.mID.Value().SetAsString() = aData->mOuterIDString;
     event.mInnerID.Value().SetAsString() = aData->mInnerIDString;
   } else if (aData->mIDType == ConsoleCallData::eNumber) {
     event.mID.Value().SetAsUnsignedLongLong() = aData->mOuterIDNumber;
     event.mInnerID.Value().SetAsUnsignedLongLong() = aData->mInnerIDNumber;
   } else {
     // aData->mIDType can be eUnknown when we dispatch notifications via
--- a/dom/console/ConsoleInstance.cpp
+++ b/dom/console/ConsoleInstance.cpp
@@ -34,28 +34,30 @@ ConsoleLogLevel PrefToValue(const nsAStr
   nsAutoCString value;
   nsresult rv = Preferences::GetCString(pref.get(), value);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     nsString message;
     message.AssignLiteral(
         "Console.maxLogLevelPref used with a non-existing pref: ");
     message.Append(aPref);
 
-    nsContentUtils::LogSimpleConsoleError(message, "chrome", false);
+    nsContentUtils::LogSimpleConsoleError(message, "chrome", false,
+                                          true /* from chrome context*/);
     return ConsoleLogLevel::All;
   }
 
   int index = FindEnumStringIndexImpl(value.get(), value.Length(),
                                       ConsoleLogLevelValues::strings);
   if (NS_WARN_IF(index < 0)) {
     nsString message;
     message.AssignLiteral("Invalid Console.maxLogLevelPref value: ");
     message.Append(NS_ConvertUTF8toUTF16(value));
 
-    nsContentUtils::LogSimpleConsoleError(message, "chrome", false);
+    nsContentUtils::LogSimpleConsoleError(message, "chrome", false,
+                                          true /* from chrome context*/);
     return ConsoleLogLevel::All;
   }
 
   MOZ_ASSERT(index < (int)ConsoleLogLevel::EndGuard_);
   return static_cast<ConsoleLogLevel>(index);
 }
 
 ConsoleUtils::Level WebIDLevelToConsoleUtilsLevel(ConsoleLevel aLevel) {
--- a/dom/console/tests/test_console_binding.html
+++ b/dom/console/tests/test_console_binding.html
@@ -13,16 +13,17 @@ function consoleListener() {
   SpecialPowers.addObserver(this, "console-api-log-event");
 }
 
 var order = 0;
 consoleListener.prototype  = {
   observe(aSubject, aTopic, aData) {
     if (aTopic == "console-api-log-event") {
       var obj = aSubject.wrappedJSObject;
+      ok(!obj.chromeContext, "Thils is not a chrome context");
       if (order + 1 == parseInt(obj.arguments[0])) {
         ok(true, "Message received: " + obj.arguments[0]);
         order++;
       }
 
       if (order == 3) {
         SpecialPowers.removeObserver(this, "console-api-log-event");
         SimpleTest.finish();
--- a/dom/console/tests/test_devtools_pref.html
+++ b/dom/console/tests/test_devtools_pref.html
@@ -10,16 +10,17 @@
   <script type="application/javascript">
 
 function consoleListener(expected) {
   var messages = [];
   return new Promise(done => {
     let observer = {
       observe: function listener(aSubject, aTopic, aData) {
         var obj = aSubject.wrappedJSObject;
+        ok(!obj.chromeContext, "This is not a chrome context");
         messages.push(parseInt(obj.arguments[0]));
         if (messages.length == expected) {
           SpecialPowers.removeObserver(observer, "console-api-log-event");
           SpecialPowers.removeObserver(observer, "console-api-profiler");
           done(messages);
         }
       },
     };
--- a/dom/console/tests/test_jsm.xul
+++ b/dom/console/tests/test_jsm.xul
@@ -29,16 +29,18 @@ function consoleListener() {
 }
 
 consoleListener.prototype  = {
   count: 0,
 
   observe: function(aSubject, aTopic, aData) {
     if (aTopic == "console-api-log-event") {
       var obj = aSubject.wrappedJSObject;
+      ok(obj.chromeContext, "JSM is always a chrome context");
+
       if (obj.innerID == JSM) {
         is(obj.ID, "jsm", "ID and InnerID are correctly set.");
         is(obj.arguments[0], "Hello world!", "Message matches");
         is(obj.consoleID, "", "No consoleID for console API");
         is(obj.prefix, "", "prefix is empty by default");
 
         // We want to see 2 messages from this innerID, the first is generated
         // by console.log, the second one from createInstance().log();
--- a/dom/indexedDB/ReportInternalError.cpp
+++ b/dom/indexedDB/ReportInternalError.cpp
@@ -21,14 +21,15 @@ void ReportInternalError(const char* aFi
     if (*p == '/' && *(p + 1)) {
       aFile = p + 1;
     }
   }
 
   nsContentUtils::LogSimpleConsoleError(
       NS_ConvertUTF8toUTF16(
           nsPrintfCString("IndexedDB %s: %s:%" PRIu32, aStr, aFile, aLine)),
-      "indexedDB", false /* no IDB in private window */);
+      "indexedDB", false /* no IDB in private window */,
+      true /* Internal errors are chrome context only */);
 }
 
 }  // namespace indexedDB
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/indexedDB/ScriptErrorHelper.cpp
+++ b/dom/indexedDB/ScriptErrorHelper.cpp
@@ -106,17 +106,18 @@ class ScriptErrorRunnable final : public
           aMessage, aFilename,
           /* aSourceLine */ EmptyString(), aLineNumber, aColumnNumber,
           aSeverityFlag, category, aInnerWindowID));
     } else {
       MOZ_ALWAYS_SUCCEEDS(scriptError->Init(
           aMessage, aFilename,
           /* aSourceLine */ EmptyString(), aLineNumber, aColumnNumber,
           aSeverityFlag, category.get(),
-          /* IDB doesn't run on Private browsing mode */ false));
+          /* IDB doesn't run on Private browsing mode */ false,
+          /* from chrome context */ aIsChrome));
     }
 
     MOZ_ALWAYS_SUCCEEDS(consoleService->LogMessage(scriptError));
   }
 
   NS_IMETHOD
   Run() override {
     MOZ_ASSERT(NS_IsMainThread());
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -438,17 +438,17 @@ ConsoleListener::Observe(nsIConsoleMessa
     return NS_OK;
   }
 
   nsCOMPtr<nsIScriptError> scriptError = do_QueryInterface(aMessage);
   if (scriptError) {
     nsAutoString msg, sourceName, sourceLine;
     nsCString category;
     uint32_t lineNum, colNum, flags;
-    bool fromPrivateWindow;
+    bool fromPrivateWindow, fromChromeContext;
 
     nsresult rv = scriptError->GetErrorMessage(msg);
     NS_ENSURE_SUCCESS(rv, rv);
     TruncateString(msg);
     rv = scriptError->GetSourceName(sourceName);
     NS_ENSURE_SUCCESS(rv, rv);
     TruncateString(sourceName);
     rv = scriptError->GetSourceLine(sourceLine);
@@ -460,16 +460,18 @@ ConsoleListener::Observe(nsIConsoleMessa
     rv = scriptError->GetLineNumber(&lineNum);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = scriptError->GetColumnNumber(&colNum);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = scriptError->GetFlags(&flags);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = scriptError->GetIsFromPrivateWindow(&fromPrivateWindow);
     NS_ENSURE_SUCCESS(rv, rv);
+    rv = scriptError->GetIsFromChromeContext(&fromChromeContext);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     {
       AutoJSAPI jsapi;
       jsapi.Init();
       JSContext* cx = jsapi.cx();
 
       JS::RootedValue stack(cx);
       rv = scriptError->GetStack(&stack);
@@ -491,25 +493,25 @@ ConsoleListener::Observe(nsIConsoleMessa
           return err.StealNSResult();
         }
 
         ClonedMessageData cloned;
         if (!data.BuildClonedMessageDataForChild(mChild, cloned)) {
           return NS_ERROR_FAILURE;
         }
 
-        mChild->SendScriptErrorWithStack(msg, sourceName, sourceLine, lineNum,
-                                         colNum, flags, category,
-                                         fromPrivateWindow, cloned);
+        mChild->SendScriptErrorWithStack(
+            msg, sourceName, sourceLine, lineNum, colNum, flags, category,
+            fromPrivateWindow, fromChromeContext, cloned);
         return NS_OK;
       }
     }
 
     mChild->SendScriptError(msg, sourceName, sourceLine, lineNum, colNum, flags,
-                            category, fromPrivateWindow);
+                            category, fromPrivateWindow, fromChromeContext);
     return NS_OK;
   }
 
   nsString msg;
   nsresult rv = aMessage->GetMessageMoz(msg);
   NS_ENSURE_SUCCESS(rv, rv);
   mChild->SendConsoleMessage(msg);
   return NS_OK;
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -4095,39 +4095,40 @@ mozilla::ipc::IPCResult ContentParent::R
   consoleService->LogMessageWithMode(msg, nsConsoleService::SuppressLog);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult ContentParent::RecvScriptError(
     const nsString& aMessage, const nsString& aSourceName,
     const nsString& aSourceLine, const uint32_t& aLineNumber,
     const uint32_t& aColNumber, const uint32_t& aFlags,
-    const nsCString& aCategory, const bool& aFromPrivateWindow) {
+    const nsCString& aCategory, const bool& aFromPrivateWindow,
+    const bool& aFromChromeContext) {
   return RecvScriptErrorInternal(aMessage, aSourceName, aSourceLine,
                                  aLineNumber, aColNumber, aFlags, aCategory,
-                                 aFromPrivateWindow);
+                                 aFromPrivateWindow, aFromChromeContext);
 }
 
 mozilla::ipc::IPCResult ContentParent::RecvScriptErrorWithStack(
     const nsString& aMessage, const nsString& aSourceName,
     const nsString& aSourceLine, const uint32_t& aLineNumber,
     const uint32_t& aColNumber, const uint32_t& aFlags,
     const nsCString& aCategory, const bool& aFromPrivateWindow,
-    const ClonedMessageData& aFrame) {
-  return RecvScriptErrorInternal(aMessage, aSourceName, aSourceLine,
-                                 aLineNumber, aColNumber, aFlags, aCategory,
-                                 aFromPrivateWindow, &aFrame);
+    const bool& aFromChromeContext, const ClonedMessageData& aFrame) {
+  return RecvScriptErrorInternal(
+      aMessage, aSourceName, aSourceLine, aLineNumber, aColNumber, aFlags,
+      aCategory, aFromPrivateWindow, aFromChromeContext, &aFrame);
 }
 
 mozilla::ipc::IPCResult ContentParent::RecvScriptErrorInternal(
     const nsString& aMessage, const nsString& aSourceName,
     const nsString& aSourceLine, const uint32_t& aLineNumber,
     const uint32_t& aColNumber, const uint32_t& aFlags,
     const nsCString& aCategory, const bool& aFromPrivateWindow,
-    const ClonedMessageData* aStack) {
+    const bool& aFromChromeContext, const ClonedMessageData* aStack) {
   RefPtr<nsConsoleService> consoleService = GetConsoleService();
   if (!consoleService) {
     return IPC_OK();
   }
 
   nsCOMPtr<nsIScriptError> msg;
 
   if (aStack) {
@@ -4152,19 +4153,19 @@ mozilla::ipc::IPCResult ContentParent::R
     MOZ_ASSERT(JS::IsUnwrappedSavedFrame(stackObj));
 
     JS::RootedObject stackGlobal(cx, JS::GetNonCCWObjectGlobal(stackObj));
     msg = new nsScriptErrorWithStack(stackObj, stackGlobal);
   } else {
     msg = new nsScriptError();
   }
 
-  nsresult rv =
-      msg->Init(aMessage, aSourceName, aSourceLine, aLineNumber, aColNumber,
-                aFlags, aCategory.get(), aFromPrivateWindow);
+  nsresult rv = msg->Init(aMessage, aSourceName, aSourceLine, aLineNumber,
+                          aColNumber, aFlags, aCategory.get(),
+                          aFromPrivateWindow, aFromChromeContext);
   if (NS_FAILED(rv)) return IPC_OK();
 
   consoleService->LogMessageWithMode(msg, nsConsoleService::SuppressLog);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult ContentParent::RecvPrivateDocShellsExist(
     const bool& aExist) {
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -1002,31 +1002,33 @@ class ContentParent final : public PCont
   mozilla::ipc::IPCResult RecvSetGeolocationHigherAccuracy(const bool& aEnable);
 
   mozilla::ipc::IPCResult RecvConsoleMessage(const nsString& aMessage);
 
   mozilla::ipc::IPCResult RecvScriptError(
       const nsString& aMessage, const nsString& aSourceName,
       const nsString& aSourceLine, const uint32_t& aLineNumber,
       const uint32_t& aColNumber, const uint32_t& aFlags,
-      const nsCString& aCategory, const bool& aIsFromPrivateWindow);
+      const nsCString& aCategory, const bool& aIsFromPrivateWindow,
+      const bool& aIsFromChromeContext);
 
   mozilla::ipc::IPCResult RecvScriptErrorWithStack(
       const nsString& aMessage, const nsString& aSourceName,
       const nsString& aSourceLine, const uint32_t& aLineNumber,
       const uint32_t& aColNumber, const uint32_t& aFlags,
       const nsCString& aCategory, const bool& aIsFromPrivateWindow,
-      const ClonedMessageData& aStack);
+      const bool& aIsFromChromeContext, const ClonedMessageData& aStack);
 
  private:
   mozilla::ipc::IPCResult RecvScriptErrorInternal(
       const nsString& aMessage, const nsString& aSourceName,
       const nsString& aSourceLine, const uint32_t& aLineNumber,
       const uint32_t& aColNumber, const uint32_t& aFlags,
       const nsCString& aCategory, const bool& aIsFromPrivateWindow,
+      const bool& aIsFromChromeContext,
       const ClonedMessageData* aStack = nullptr);
 
  public:
   mozilla::ipc::IPCResult RecvPrivateDocShellsExist(const bool& aExist);
 
   mozilla::ipc::IPCResult RecvCommitBrowsingContextTransaction(
       BrowsingContext* aContext, BrowsingContext::Transaction&& aTransaction,
       BrowsingContext::FieldEpochs&& aEpochs);
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -931,21 +931,22 @@ parent:
 
     async AddGeolocationListener(Principal principal, bool highAccuracy);
     async RemoveGeolocationListener();
     async SetGeolocationHigherAccuracy(bool enable);
 
     async ConsoleMessage(nsString message);
     async ScriptError(nsString message, nsString sourceName, nsString sourceLine,
                       uint32_t lineNumber, uint32_t colNumber, uint32_t flags,
-                      nsCString category, bool privateWindow);
+                      nsCString category, bool privateWindow,
+                      bool fromChromeContext);
     async ScriptErrorWithStack(nsString message, nsString sourceName, nsString sourceLine,
                                uint32_t lineNumber, uint32_t colNumber, uint32_t flags,
                                nsCString category, bool privateWindow,
-                               ClonedMessageData stack);
+                               bool fromChromeContext, ClonedMessageData stack);
 
     // Places the items within dataTransfer on the clipboard.
     async SetClipboard(IPCDataTransfer aDataTransfer,
                        bool aIsPrivateData,
                        Principal aRequestingPrincipal,
                        uint32_t aContentPolicyType,
                        int32_t aWhichClipboard);
 
--- a/dom/localstorage/ReportInternalError.cpp
+++ b/dom/localstorage/ReportInternalError.cpp
@@ -21,14 +21,14 @@ void ReportInternalError(const char* aFi
     if (*p == '/' && *(p + 1)) {
       aFile = p + 1;
     }
   }
 
   nsContentUtils::LogSimpleConsoleError(
       NS_ConvertUTF8toUTF16(
           nsPrintfCString("LocalStorage %s: %s:%" PRIu32, aStr, aFile, aLine)),
-      "localstorage", false);
+      "localstorage", false, true /* Internal errors are chrome context only*/);
 }
 
 }  // namespace localstorage
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/quota/ActorsParent.cpp
+++ b/dom/quota/ActorsParent.cpp
@@ -1363,18 +1363,18 @@ void ReportInternalError(const char* aFi
     if (*p == '/' && *(p + 1)) {
       aFile = p + 1;
     }
   }
 
   nsContentUtils::LogSimpleConsoleError(
       NS_ConvertUTF8toUTF16(
           nsPrintfCString("Quota %s: %s:%" PRIu32, aStr, aFile, aLine)),
-      "quota",
-      false /* Quota Manager is not active in private browsing mode */);
+      "quota", false /* Quota Manager is not active in private browsing mode */,
+      true /* Quota Manager runs always in a chrome context */);
 }
 
 namespace {
 
 StaticAutoPtr<nsString> gBaseDirPath;
 
 #ifdef DEBUG
 bool gQuotaManagerInitialized = false;
--- a/dom/security/nsCSPUtils.cpp
+++ b/dom/security/nsCSPUtils.cpp
@@ -154,17 +154,18 @@ void CSP_LogMessage(const nsAString& aMe
 
   nsresult rv;
   if (aInnerWindowID > 0) {
     rv = error->InitWithWindowID(cspMsg, aSourceName, aSourceLine, aLineNumber,
                                  aColumnNumber, aFlags, category,
                                  aInnerWindowID);
   } else {
     rv = error->Init(cspMsg, aSourceName, aSourceLine, aLineNumber,
-                     aColumnNumber, aFlags, category.get(), aFromPrivateWindow);
+                     aColumnNumber, aFlags, category.get(), aFromPrivateWindow,
+                     true /* from chrome context */);
   }
   if (NS_FAILED(rv)) {
     return;
   }
   console->LogMessage(error);
 }
 
 /**
--- a/dom/webidl/Console.webidl
+++ b/dom/webidl/Console.webidl
@@ -102,22 +102,24 @@ dictionary ConsoleEvent {
   // consumers expect to see own properties on it, which would mean making the
   // props unforgeable, which means lots of JSFunction allocations.  Maybe we
   // should fix those consumers, of course....
   // sequence<ConsoleStackEntry> stacktrace;
   DOMString groupName = "";
   any timer = null;
   any counter = null;
   DOMString prefix = "";
+  boolean chromeContext = false;
 };
 
 // Event for profile operations
 dictionary ConsoleProfileEvent {
   DOMString action = "";
   sequence<any> arguments;
+  boolean chromeContext = false;
 };
 
 // This dictionary is used to manage stack trace data.
 dictionary ConsoleStackEntry {
   DOMString filename = "";
   // Unique identifier within the process for the script source this entry is
   // associated with, or zero.
   unsigned long sourceId = 0;
--- a/dom/websocket/WebSocket.cpp
+++ b/dom/websocket/WebSocket.cpp
@@ -97,16 +97,17 @@ class WebSocketImpl final : public nsIIn
         mDisconnectingOrDisconnected(false),
         mCloseEventWasClean(false),
         mCloseEventCode(nsIWebSocketChannel::CLOSE_ABNORMAL),
         mPort(0),
         mScriptLine(0),
         mScriptColumn(0),
         mInnerWindowID(0),
         mPrivateBrowsing(false),
+        mIsChromeContext(false),
         mIsMainThread(true),
         mMutex("WebSocketImpl::mMutex"),
         mWorkerShuttingDown(false) {
     if (!NS_IsMainThread()) {
       mIsMainThread = false;
     }
   }
 
@@ -196,16 +197,17 @@ class WebSocketImpl final : public nsIIn
   // - the ID of the inner window where the script lives. Note that this may not
   //   be the same as the Web Socket owner window.
   // These attributes are used for error reporting.
   nsCString mScriptFile;
   uint32_t mScriptLine;
   uint32_t mScriptColumn;
   uint64_t mInnerWindowID;
   bool mPrivateBrowsing;
+  bool mIsChromeContext;
 
   RefPtr<ThreadSafeWorkerRef> mWorkerRef;
 
   nsWeakPtr mWeakLoadGroup;
 
   bool mIsMainThread;
 
   // This mutex protects mWorkerShuttingDown.
@@ -339,17 +341,17 @@ void WebSocketImpl::PrintErrorOnConsole(
   if (mInnerWindowID) {
     rv = errorObject->InitWithWindowID(
         message, NS_ConvertUTF8toUTF16(mScriptFile), EmptyString(), mScriptLine,
         mScriptColumn, nsIScriptError::errorFlag, "Web Socket", mInnerWindowID);
   } else {
     rv = errorObject->Init(message, NS_ConvertUTF8toUTF16(mScriptFile),
                            EmptyString(), mScriptLine, mScriptColumn,
                            nsIScriptError::errorFlag, "Web Socket",
-                           mPrivateBrowsing);
+                           mPrivateBrowsing, mIsChromeContext);
   }
 
   NS_ENSURE_SUCCESS_VOID(rv);
 
   // print the error message directly to the JS console
   rv = console->LogMessage(errorObject);
   NS_ENSURE_SUCCESS_VOID(rv);
 }
@@ -1500,16 +1502,17 @@ nsresult WebSocketImpl::Init(JSContext* 
   // If we don't have aCx, we are window-less, so we don't have a
   // inner-windowID. This can happen in sharedWorkers and ServiceWorkers or in
   // DedicateWorkers created by JSM.
   if (aCx) {
     mInnerWindowID = nsJSUtils::GetCurrentlyRunningCodeInnerWindowID(aCx);
   }
 
   mPrivateBrowsing = !!aPrincipal->OriginAttributesRef().mPrivateBrowsingId;
+  mIsChromeContext = nsContentUtils::IsSystemPrincipal(aPrincipal);
 
   // parses the url
   rv = ParseURL(aURL);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<Document> originDoc = mWebSocket->GetDocumentIfCurrent();
   if (!originDoc) {
     rv = mWebSocket->CheckCurrentGlobalCorrectness();
--- a/js/ipc/JavaScriptParent.cpp
+++ b/js/ipc/JavaScriptParent.cpp
@@ -93,17 +93,18 @@ bool JavaScriptParent::allowMessage(JSCo
     if (console) {
       nsAutoString filename;
       uint32_t lineno = 0, column = 0;
       nsJSUtils::GetCallingLocation(cx, filename, &lineno, &column);
       nsCOMPtr<nsIScriptError> error(
           do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
       error->Init(NS_LITERAL_STRING("unsafe/forbidden CPOW usage"), filename,
                   EmptyString(), lineno, column, nsIScriptError::warningFlag,
-                  "chrome javascript", false /* from private window */);
+                  "chrome javascript", false /* from private window */,
+                  true /* from chrome context */);
       console->LogMessage(error);
     } else {
       NS_WARNING("Unsafe synchronous IPC message");
     }
   }
 
   return true;
 }
--- a/js/xpconnect/src/XPCWrappedNativeInfo.cpp
+++ b/js/xpconnect/src/XPCWrappedNativeInfo.cpp
@@ -235,17 +235,18 @@ already_AddRefed<XPCNativeInterface> XPC
 
       nsAutoString filename;
       uint32_t lineno = 0, column = 0;
       nsJSUtils::GetCallingLocation(cx, filename, &lineno, &column);
       nsCOMPtr<nsIScriptError> error(
           do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
       error->Init(NS_ConvertUTF8toUTF16(errorMsg), filename, EmptyString(),
                   lineno, column, nsIScriptError::warningFlag,
-                  "chrome javascript", false /* from private window */);
+                  "chrome javascript", false /* from private window */,
+                  true /* from chrome context */);
       console->LogMessage(error);
     }
   }
 
   uint16_t methodCount = aInfo->MethodCount();
   uint16_t constCount = aInfo->ConstantCount();
 
   // If the interface does not have nsISupports in its inheritance chain
--- a/netwerk/protocol/http/HttpChannelChild.cpp
+++ b/netwerk/protocol/http/HttpChannelChild.cpp
@@ -3857,18 +3857,20 @@ mozilla::ipc::IPCResult HttpChannelChild
 
 NS_IMETHODIMP
 HttpChannelChild::LogBlockedCORSRequest(const nsAString& aMessage,
                                         const nsACString& aCategory) {
   if (mLoadInfo) {
     uint64_t innerWindowID = mLoadInfo->GetInnerWindowID();
     bool privateBrowsing =
         !!mLoadInfo->GetOriginAttributes().mPrivateBrowsingId;
-    nsCORSListenerProxy::LogBlockedCORSRequest(innerWindowID, privateBrowsing,
-                                               aMessage, aCategory);
+    bool fromChromeContext =
+        nsContentUtils::IsSystemPrincipal(mLoadInfo->TriggeringPrincipal());
+    nsCORSListenerProxy::LogBlockedCORSRequest(
+        innerWindowID, privateBrowsing, fromChromeContext, aMessage, aCategory);
   }
   return NS_OK;
 }
 
 mozilla::ipc::IPCResult HttpChannelChild::RecvLogMimeTypeMismatch(
     const nsCString& aMessageName, const bool& aWarning, const nsString& aURL,
     const nsString& aContentType) {
   Unused << LogMimeTypeMismatch(aMessageName, aWarning, aURL, aContentType);
--- a/netwerk/protocol/http/nsCORSListenerProxy.cpp
+++ b/netwerk/protocol/http/nsCORSListenerProxy.cpp
@@ -98,30 +98,37 @@ static void LogBlockedRequest(nsIRequest
   bool privateBrowsing = false;
   if (aRequest) {
     nsCOMPtr<nsILoadGroup> loadGroup;
     rv = aRequest->GetLoadGroup(getter_AddRefs(loadGroup));
     NS_ENSURE_SUCCESS_VOID(rv);
     privateBrowsing = nsContentUtils::IsInPrivateBrowsing(loadGroup);
   }
 
+  bool fromChromeContext = false;
+  if (channel) {
+    nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
+    fromChromeContext =
+        nsContentUtils::IsSystemPrincipal(loadInfo->TriggeringPrincipal());
+  }
+
   // we are passing aProperty as the category so we can link to the
   // appropriate MDN docs depending on the specific error.
   uint64_t innerWindowID = nsContentUtils::GetInnerWindowID(aRequest);
   // The |innerWindowID| could be 0 if this request is created from script.
   // We can always try top level content window id in this case,
   // since the window id can lead to current top level window's web console.
   if (!innerWindowID) {
     nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aRequest);
     if (httpChannel) {
       Unused << httpChannel->GetTopLevelContentWindowId(&innerWindowID);
     }
   }
   nsCORSListenerProxy::LogBlockedCORSRequest(innerWindowID, privateBrowsing,
-                                             msg, category);
+                                             fromChromeContext, msg, category);
 }
 
 //////////////////////////////////////////////////////////////////////////
 // Preflight cache
 
 class nsPreflightCache {
  public:
   struct TokenTime {
@@ -1513,16 +1520,17 @@ nsresult nsCORSListenerProxy::StartCORSP
   preflightChannel.forget(aPreflightChannel);
 
   return NS_OK;
 }
 
 // static
 void nsCORSListenerProxy::LogBlockedCORSRequest(uint64_t aInnerWindowID,
                                                 bool aPrivateBrowsing,
+                                                bool aFromChromeContext,
                                                 const nsAString& aMessage,
                                                 const nsACString& aCategory) {
   nsresult rv = NS_OK;
 
   // Build the error object and log it to the console
   nsCOMPtr<nsIConsoleService> console(
       do_GetService(NS_CONSOLESERVICE_CONTRACTID, &rv));
   if (NS_FAILED(rv)) {
@@ -1550,17 +1558,18 @@ void nsCORSListenerProxy::LogBlockedCORS
   } else {
     nsCString category = PromiseFlatCString(aCategory);
     rv = scriptError->Init(aMessage,
                            EmptyString(),  // sourceName
                            EmptyString(),  // sourceLine
                            0,              // lineNumber
                            0,              // columnNumber
                            nsIScriptError::warningFlag, category.get(),
-                           aPrivateBrowsing);
+                           aPrivateBrowsing,
+                           aFromChromeContext);  // From chrome context
   }
   if (NS_FAILED(rv)) {
     NS_WARNING(
         "Failed to log blocked cross-site request (scriptError init failed)");
     return;
   }
   console->LogMessage(scriptError);
 }
--- a/netwerk/protocol/http/nsCORSListenerProxy.h
+++ b/netwerk/protocol/http/nsCORSListenerProxy.h
@@ -63,16 +63,17 @@ class nsCORSListenerProxy final : public
 
   void SetInterceptController(
       nsINetworkInterceptController* aInterceptController);
 
   // When CORS blocks a request, log the message to the web console, or the
   // browser console if no valid inner window ID is found.
   static void LogBlockedCORSRequest(uint64_t aInnerWindowID,
                                     bool aPrivateBrowsing,
+                                    bool aFromChromeContext,
                                     const nsAString& aMessage,
                                     const nsACString& aCategory);
 
  private:
   // Only HttpChannelParent can call RemoveFromCorsPreflightCache
   friend class mozilla::net::HttpChannelParent;
   // Only nsHttpChannel can invoke CORS preflights
   friend class mozilla::net::nsHttpChannel;
--- a/security/manager/ssl/nsNSSCallbacks.cpp
+++ b/security/manager/ssl/nsNSSCallbacks.cpp
@@ -1325,14 +1325,15 @@ void HandshakeCallback(PRFileDesc* fd, v
   // to log the warning. In particular, these warnings should go to the web
   // console instead of to the error console. Also, the warning is not
   // localized.
   if (!siteSupportsSafeRenego) {
     NS_ConvertASCIItoUTF16 msg(infoObject->GetHostName());
     msg.AppendLiteral(" : server does not support RFC 5746, see CVE-2009-3555");
 
     nsContentUtils::LogSimpleConsoleError(
-        msg, "SSL", !!infoObject->GetOriginAttributes().mPrivateBrowsingId);
+        msg, "SSL", !!infoObject->GetOriginAttributes().mPrivateBrowsingId,
+        true /* from chrome context */);
   }
 
   infoObject->NoteTimeUntilReady();
   infoObject->SetHandshakeCompleted();
 }
--- a/toolkit/components/telemetry/core/TelemetryCommon.cpp
+++ b/toolkit/components/telemetry/core/TelemetryCommon.cpp
@@ -109,17 +109,18 @@ void LogToBrowserConsole(uint32_t aLogLe
       do_GetService("@mozilla.org/consoleservice;1"));
   if (!console) {
     NS_WARNING("Failed to log message to console.");
     return;
   }
 
   nsCOMPtr<nsIScriptError> error(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
   error->Init(aMsg, EmptyString(), EmptyString(), 0, 0, aLogLevel,
-              "chrome javascript", false /* from private window */);
+              "chrome javascript", false /* from private window */,
+              true /* from chrome context */);
   console->LogMessage(error);
 }
 
 const char* GetNameForProcessID(ProcessID process) {
   MOZ_ASSERT(process < ProcessID::Count);
   return ProcessIDToString[static_cast<uint32_t>(process)];
 }
 
--- a/toolkit/modules/Console.jsm
+++ b/toolkit/modules/Console.jsm
@@ -535,16 +535,17 @@ function sendConsoleAPIMessage(aConsole,
     consoleID: aConsole.consoleID,
     level: aLevel,
     filename: aFrame.filename,
     lineNumber: aFrame.lineNumber,
     functionName: aFrame.functionName,
     timeStamp: Date.now(),
     arguments: aArgs,
     prefix: aConsole.prefix,
+    chromeContext: true,
   };
 
   consoleEvent.wrappedJSObject = consoleEvent;
 
   switch (aLevel) {
     case "trace":
       consoleEvent.stacktrace = aOptions.stacktrace;
       break;
@@ -693,29 +694,31 @@ ConsoleAPI.prototype = {
   profile(profileName) {
     if (!shouldLog("profile", this.maxLogLevel)) {
       return;
     }
     Services.obs.notifyObservers({
       wrappedJSObject: {
         action: "profile",
         arguments: [ profileName ],
+        chromeContext: true,
       },
     }, "console-api-profiler");
     dumpMessage(this, "profile", `'${profileName}'`);
   },
 
   profileEnd(profileName) {
     if (!shouldLog("profileEnd", this.maxLogLevel)) {
       return;
     }
     Services.obs.notifyObservers({
       wrappedJSObject: {
         action: "profileEnd",
         arguments: [ profileName ],
+        chromeContext: true,
       },
     }, "console-api-profiler");
     dumpMessage(this, "profileEnd", `'${profileName}'`);
   },
 
   get maxLogLevel() {
     return this._maxLogLevel || "all";
   },
--- a/xpcom/components/ManifestParser.cpp
+++ b/xpcom/components/ManifestParser.cpp
@@ -153,17 +153,18 @@ void LogMessageWithContext(FileLocation&
       do_GetService(NS_CONSOLESERVICE_CONTRACTID);
   if (!console) {
     return;
   }
 
   nsresult rv = error->Init(
       NS_ConvertUTF8toUTF16(formatted.get()), NS_ConvertUTF8toUTF16(file),
       EmptyString(), aLineNumber, 0, nsIScriptError::warningFlag,
-      "chrome registration", false /* from private window */);
+      "chrome registration", false /* from private window */,
+      true /* from chrome context */);
   if (NS_FAILED(rv)) {
     return;
   }
 
   console->LogMessage(error);
 }
 
 /**
--- a/xpcom/ds/nsObserverService.cpp
+++ b/xpcom/ds/nsObserverService.cpp
@@ -190,17 +190,18 @@ nsresult nsObserverService::FilterHttpOn
       strcmp(aTopic, "http-on-stop-request")) {
     nsCOMPtr<nsIConsoleService> console(
         do_GetService(NS_CONSOLESERVICE_CONTRACTID));
     nsCOMPtr<nsIScriptError> error(
         do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
     error->Init(NS_LITERAL_STRING(
                     "http-on-* observers only work in the parent process"),
                 EmptyString(), EmptyString(), 0, 0, nsIScriptError::warningFlag,
-                "chrome javascript", false /* from private window */);
+                "chrome javascript", false /* from private window */,
+                true /* from chrome context */);
     console->LogMessage(error);
 
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   return NS_OK;
 }