mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 1767260 - [bidi] Add support for source to log.entryAdded event. r=webdriver-reviewers,jdescottes,whimboo
Depends on D150107 Differential Revision: https://phabricator.services.mozilla.com/D150405
This commit is contained in:
parent
147e207e97
commit
d47145fdcc
@ -101,6 +101,10 @@ class MessageHandler extends EventEmitter {
|
||||
this._eventsDispatcher = new lazy.EventsDispatcher(this);
|
||||
}
|
||||
|
||||
get context() {
|
||||
return this._context;
|
||||
}
|
||||
|
||||
get contextId() {
|
||||
return this._contextId;
|
||||
}
|
||||
|
@ -6,13 +6,31 @@
|
||||
|
||||
const EXPORTED_SYMBOLS = ["log"];
|
||||
|
||||
const { XPCOMUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
||||
const { Module } = ChromeUtils.import(
|
||||
"chrome://remote/content/shared/messagehandler/Module.jsm"
|
||||
);
|
||||
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
TabManager: "chrome://remote/content/shared/TabManager.jsm",
|
||||
});
|
||||
|
||||
class LogModule extends Module {
|
||||
destroy() {}
|
||||
|
||||
interceptEvent(name, payload) {
|
||||
if (name == "log.entryAdded") {
|
||||
// Resolve browsing context to a TabManager id.
|
||||
payload.source.context = lazy.TabManager.getIdForBrowsingContext(
|
||||
payload.source.context
|
||||
);
|
||||
}
|
||||
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,13 @@ class LogModule extends Module {
|
||||
this.#consoleMessageListener.destroy();
|
||||
}
|
||||
|
||||
#buildSource() {
|
||||
return {
|
||||
realm: this.messageHandler.window.windowGlobalChild?.innerWindowId.toString(),
|
||||
context: this.messageHandler.context,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Map the internal stacktrace representation to a WebDriver BiDi
|
||||
* compatible one.
|
||||
@ -113,44 +120,45 @@ class LogModule extends Module {
|
||||
// Step numbers below refer to the specifications at
|
||||
// https://w3c.github.io/webdriver-bidi/#event-log-entryAdded
|
||||
|
||||
// 1. Translate the console message method to a log.LogEntry level
|
||||
// Translate the console message method to a log.LogEntry level
|
||||
const logEntrylevel = this.#getLogEntryLevelFromConsoleMethod(method);
|
||||
|
||||
// 2. Use the message's timeStamp or fallback on the current time value.
|
||||
// Use the message's timeStamp or fallback on the current time value.
|
||||
const timestamp = timeStamp || Date.now();
|
||||
|
||||
// 3. Start assembling the text representation of the message.
|
||||
// Start assembling the text representation of the message.
|
||||
let text = "";
|
||||
|
||||
// 4. Formatters have already been applied at this points.
|
||||
// Formatters have already been applied at this points.
|
||||
// message.arguments corresponds to the "formatted args" from the
|
||||
// specifications.
|
||||
|
||||
// 5. Concatenate all formatted arguments in text
|
||||
// Concatenate all formatted arguments in text
|
||||
// TODO: For m1 we only support string arguments, so we rely on the builtin
|
||||
// toString for each argument which will be available in message.arguments.
|
||||
const args = messageArguments || [];
|
||||
text += args.map(String).join(" ");
|
||||
|
||||
// Step 6 and 7: Serialize each arg as remote value.
|
||||
// Serialize each arg as remote value.
|
||||
const serializedArgs = [];
|
||||
for (const arg of args) {
|
||||
serializedArgs.push(lazy.serialize(arg /*, null, true, new Set() */));
|
||||
}
|
||||
|
||||
// 8. Bug 1742589: set realm to the current realm id.
|
||||
// Set source to an object which contains realm and browsing context.
|
||||
const source = this.#buildSource();
|
||||
|
||||
// 9. Set stack trace only for certain methods.
|
||||
// Set stack trace only for certain methods.
|
||||
let stackTrace;
|
||||
if (["assert", "error", "trace", "warn"].includes(method)) {
|
||||
stackTrace = this.#buildStackTrace(stacktrace);
|
||||
}
|
||||
|
||||
// 10. Build the ConsoleLogEntry
|
||||
// Build the ConsoleLogEntry
|
||||
const entry = {
|
||||
type: "console",
|
||||
method,
|
||||
realm: null,
|
||||
source,
|
||||
args: serializedArgs,
|
||||
level: logEntrylevel,
|
||||
text,
|
||||
@ -158,7 +166,7 @@ class LogModule extends Module {
|
||||
stackTrace,
|
||||
};
|
||||
|
||||
// TODO: steps 11. to 15. Those steps relate to:
|
||||
// TODO: Those steps relate to:
|
||||
// - emitting associated BrowsingContext. See log.entryAdded full support
|
||||
// in https://bugzilla.mozilla.org/show_bug.cgi?id=1724669#c0
|
||||
// - handling cases where session doesn't exist or the event is not
|
||||
@ -176,6 +184,7 @@ class LogModule extends Module {
|
||||
const entry = {
|
||||
type: "javascript",
|
||||
level,
|
||||
source: this.#buildSource(),
|
||||
text: message,
|
||||
timestamp: timeStamp || Date.now(),
|
||||
stackTrace: this.#buildStackTrace(stacktrace),
|
||||
|
Loading…
Reference in New Issue
Block a user