Bug 1438482 - logErrorInPage should produce an error log; r=bgrins
MozReview-Commit-ID: Ly9kDNwGthG
--- a/devtools/client/framework/target.js
+++ b/devtools/client/framework/target.js
@@ -717,20 +717,44 @@ TabTarget.prototype = {
* Log an error of some kind to the tab's console.
*
* @param {String} text
* The text to log.
* @param {String} category
* The category of the message. @see nsIScriptError.
*/
logErrorInPage: function (text, category) {
- if (this.activeTab && this.activeTab.traits.logErrorInPage) {
+ if (this.activeTab && this.activeTab.traits.logInPage) {
+ const errorFlag = 0;
let packet = {
to: this.form.actor,
- type: "logErrorInPage",
+ type: "logInPage",
+ flags: errorFlag,
+ text,
+ category,
+ };
+ this.client.request(packet);
+ }
+ },
+
+ /**
+ * Log a warning of some kind to the tab's console.
+ *
+ * @param {String} text
+ * The text to log.
+ * @param {String} category
+ * The category of the message. @see nsIScriptError.
+ */
+ logWarningInPage: function (text, category) {
+ if (this.activeTab && this.activeTab.traits.logInPage) {
+ const warningFlag = 1;
+ let packet = {
+ to: this.form.actor,
+ type: "logInPage",
+ flags: warningFlag,
text,
category,
};
this.client.request(packet);
}
},
};
@@ -882,9 +906,13 @@ WorkerTarget.prototype = {
makeRemote: function () {
return Promise.resolve();
},
logErrorInPage: function () {
// No-op. See bug 1368680.
},
+
+ logWarningInPage: function () {
+ // No-op. See bug 1368680.
+ },
};
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -604,30 +604,30 @@ Toolbox.prototype = {
switch (name) {
case "getOriginalURLs":
return (urlInfo) => {
return target.getOriginalURLs(urlInfo)
.catch(text => {
let message = L10N.getFormatStr("toolbox.sourceMapFailure",
text, urlInfo.url,
urlInfo.sourceMapURL);
- this.target.logErrorInPage(message, "source map");
+ this.target.logWarningInPage(message, "source map");
// It's ok to swallow errors here, because a null
// result just means that no source map was found.
return null;
});
};
case "getOriginalSourceText":
return (originalSource) => {
return target.getOriginalSourceText(originalSource)
.catch(text => {
let message = L10N.getFormatStr("toolbox.sourceMapSourceFailure",
text, originalSource.url);
- this.target.logErrorInPage(message, "source map");
+ this.target.logWarningInPage(message, "source map");
// Also replace the result with the error text.
// Note that this result has to have the same form
// as whatever the upstream getOriginalSourceText
// returns.
return {
text: message,
contentType: "text/plain",
};
@@ -3077,17 +3077,17 @@ Toolbox.prototype = {
* as first argument.
*/
addRequestFinishedListener: function (listener) {
// Log console message informing the extension developer
// that the Network panel needs to be selected at least
// once in order to receive `onRequestFinished` events.
let message = "The Network panel needs to be selected at least" +
" once in order to receive 'onRequestFinished' events.";
- this.target.logErrorInPage(message, "har");
+ this.target.logWarningInPage(message, "har");
// Add the listener into internal list.
this._requestFinishedListeners.add(listener);
},
removeRequestFinishedListener: function (listener) {
this._requestFinishedListeners.delete(listener);
},
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
@@ -304,16 +304,17 @@ skip-if = true # Bug 1405343
[browser_webconsole_inspect_cross_domain_object.js]
[browser_webconsole_js_input_expansion.js]
[browser_webconsole_keyboard_accessibility.js]
[browser_webconsole_location_debugger_link.js]
[browser_webconsole_location_scratchpad_link.js]
[browser_webconsole_location_styleeditor_link.js]
[browser_webconsole_logErrorInPage.js]
[browser_webconsole_loglimit.js]
+[browser_webconsole_logWarningInPage.js]
[browser_webconsole_longstring_expand.js]
skip-if = true # Bug 1403448
[browser_webconsole_longstring_hang.js]
skip-if = true # Bug 1403448
[browser_webconsole_message_categories.js]
[browser_webconsole_multiple_windows_and_tabs.js]
[browser_webconsole_network_attach.js]
[browser_webconsole_network_exceptions.js]
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_logErrorInPage.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_logErrorInPage.js
@@ -12,9 +12,10 @@ const TEST_URI = "data:text/html;charset
add_task(async function () {
const hud = await openNewTabAndConsole(TEST_URI);
const toolbox = hud.ui.newConsoleOutput.toolbox;
toolbox.target.logErrorInPage("beware the octopus", "content javascript");
const node = await waitFor(() => findMessage(hud, "octopus"));
ok(node, "text is displayed in web console");
+ ok(node.classList.contains("error"), "the log represents an error");
});
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_logWarningInPage.js
@@ -0,0 +1,21 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Test that we can log warning message to the web console from the toolbox.
+
+const TEST_URI = "data:text/html;charset=utf-8,<p>test logErrorInPage";
+
+add_task(async function () {
+ const hud = await openNewTabAndConsole(TEST_URI);
+ const toolbox = hud.ui.newConsoleOutput.toolbox;
+
+ toolbox.target.logWarningInPage("beware the octopus", "content javascript");
+
+ const node = await waitFor(() => findMessage(hud, "octopus"));
+ ok(node, "text is displayed in web console");
+ ok(node.classList.contains("warn"), "the log represents a warning");
+});
--- a/devtools/client/webconsole/new-webconsole.js
+++ b/devtools/client/webconsole/new-webconsole.js
@@ -127,17 +127,17 @@ NewWebConsoleFrame.prototype = {
return this._destroyer.promise;
},
_onUpdateListeners() {
},
logWarningAboutReplacedAPI() {
- this.owner.target.logErrorInPage(l10n.getStr("ConsoleAPIDisabled"),
+ this.owner.target.logWarningInPage(l10n.getStr("ConsoleAPIDisabled"),
"ConsoleAPIDisabled");
},
handleNetworkEventUpdate() {
},
/**
--- a/devtools/server/actors/tab.js
+++ b/devtools/server/actors/tab.js
@@ -223,18 +223,18 @@ function TabActor(connection) {
this.traits = {
reconfigure: true,
// Supports frame listing via `listFrames` request and `frameUpdate` events
// as well as frame switching via `switchToFrame` request
frames: true,
// Do not require to send reconfigure request to reset the document state
// to what it was before using the TabActor
noTabReconfigureOnClose: true,
- // Supports the logErrorInPage request.
- logErrorInPage: true,
+ // Supports the logInPage request.
+ logInPage: true,
};
this._workerActorList = null;
this._workerActorPool = null;
this._onWorkerActorListChanged = this._onWorkerActorListChanged.bind(this);
}
TabActor.prototype = {
@@ -651,21 +651,21 @@ TabActor.prototype = {
return {
"from": this.actorID,
"workers": actors.map((actor) => actor.form())
};
});
},
- onLogErrorInPage(request) {
- let {text, category} = request;
+ onLogInPage(request) {
+ let {text, category, flags} = request;
let scriptErrorClass = Cc["@mozilla.org/scripterror;1"];
let scriptError = scriptErrorClass.createInstance(Ci.nsIScriptError);
- scriptError.initWithWindowID(text, null, null, 0, 0, 1,
+ scriptError.initWithWindowID(text, null, null, 0, 0, flags,
category, getInnerId(this.window));
Services.console.logMessage(scriptError);
return {};
},
_onWorkerActorListChanged() {
this._workerActorList.onListChanged = null;
this.conn.sendActorEvent(this.actorID, "workerListChanged");
@@ -1428,17 +1428,17 @@ TabActor.prototype.requestTypes = {
"detach": TabActor.prototype.onDetach,
"focus": TabActor.prototype.onFocus,
"reload": TabActor.prototype.onReload,
"navigateTo": TabActor.prototype.onNavigateTo,
"reconfigure": TabActor.prototype.onReconfigure,
"switchToFrame": TabActor.prototype.onSwitchToFrame,
"listFrames": TabActor.prototype.onListFrames,
"listWorkers": TabActor.prototype.onListWorkers,
- "logErrorInPage": TabActor.prototype.onLogErrorInPage,
+ "logInPage": TabActor.prototype.onLogInPage,
};
exports.TabActor = TabActor;
/**
* The DebuggerProgressListener object is an nsIWebProgressListener which
* handles onStateChange events for the inspected browser. If the user tries to
* navigate away from a paused page, the listener makes sure that the debuggee