Bug 1385032 - add logErrorInPage to tab target in devtools; r=bgrins

This adds a method that can be called by the toolbox to log something to
the web console.

MozReview-Commit-ID: GpZtWwNVVGO

--HG--
extra : rebase_source : 37d2336bc1dbf5a8fd35d280c349044f1d06cd4c
This commit is contained in:
Tom Tromey 2017-07-07 12:53:32 -06:00
Родитель 804a36e668
Коммит 9160711a92
4 изменённых файлов: 62 добавлений и 3 удалений

Просмотреть файл

@ -712,6 +712,26 @@ TabTarget.prototype = {
let id = this._tab ? this._tab : (this._form && this._form.actor);
return `TabTarget:${id}`;
},
/**
* 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) {
let packet = {
to: this.form.actor,
type: "logErrorInPage",
text,
category,
};
this.client.request(packet);
}
},
};
/**
@ -862,5 +882,9 @@ WorkerTarget.prototype = {
makeRemote: function () {
return Promise.resolve();
}
},
logErrorInPage: function () {
// No-op. See bug 1368680.
},
};

Просмотреть файл

@ -40,6 +40,7 @@ skip-if = (os == 'linux' && bits == 32 && debug) # bug 1328915, disable linux32
[browser_webconsole_location_debugger_link.js]
[browser_webconsole_location_scratchpad_link.js]
[browser_webconsole_location_styleeditor_link.js]
[browser_webconsole_logErrorInPage.js]
[browser_webconsole_network_messages_click.js]
[browser_webconsole_nodes_highlight.js]
[browser_webconsole_nodes_select.js]

Просмотреть файл

@ -0,0 +1,20 @@
/* -*- 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 a 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.logErrorInPage("beware the octopus", "content javascript");
const node = await waitFor(() => findMessage(hud, "octopus"));
ok(node, "text is displayed in web console");
});

Просмотреть файл

@ -12,7 +12,7 @@
// document process. For example, it shouldn't be evaluated in the parent
// process until we try to debug a document living in the parent process.
var { Ci, Cu, Cr } = require("chrome");
var { Ci, Cu, Cr, Cc } = require("chrome");
var Services = require("Services");
var { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
var promise = require("promise");
@ -226,7 +226,9 @@ function TabActor(connection) {
frames: true,
// Do not require to send reconfigure request to reset the document state
// to what it was before using the TabActor
noTabReconfigureOnClose: true
noTabReconfigureOnClose: true,
// Supports the logErrorInPage request.
logErrorInPage: true,
};
this._workerActorList = null;
@ -661,6 +663,17 @@ TabActor.prototype = {
});
},
onLogErrorInPage(request) {
let {text, category} = request;
let scriptErrorClass = Cc["@mozilla.org/scripterror;1"];
let scriptError = scriptErrorClass.createInstance(Ci.nsIScriptError);
scriptError.initWithWindowID(text, null, null, 0, 0, 1,
category, getInnerId(this.window));
let console = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
console.logMessage(scriptError);
return {};
},
_onWorkerActorListChanged() {
this._workerActorList.onListChanged = null;
this.conn.sendActorEvent(this.actorID, "workerListChanged");
@ -1426,6 +1439,7 @@ TabActor.prototype.requestTypes = {
"switchToFrame": TabActor.prototype.onSwitchToFrame,
"listFrames": TabActor.prototype.onListFrames,
"listWorkers": TabActor.prototype.onListWorkers,
"logErrorInPage": TabActor.prototype.onLogErrorInPage,
};
exports.TabActor = TabActor;