diff --git a/devtools/server/actors/target-configuration.js b/devtools/server/actors/target-configuration.js index ca1f4ad75027..ca80b9e4d859 100644 --- a/devtools/server/actors/target-configuration.js +++ b/devtools/server/actors/target-configuration.js @@ -104,6 +104,9 @@ class TargetConfigurationActor extends Actor { this._browsingContext = this.watcherActor.browserElement?.browsingContext; } + // Value of `logging.console` pref, before starting recording JS Traces + #consolePrefValue; + form() { return { actor: this.actorID, @@ -234,6 +237,11 @@ class TargetConfigurationActor extends Actor { * @param {Object} configuration: See `updateConfiguration` */ _updateParentProcessConfiguration(configuration) { + // Process "tracerOptions" for all session types, as this isn't specific to tab debugging + if ("tracerOptions" in configuration) { + this._setTracerOptions(configuration.tracerOptions); + } + if (!this._shouldHandleConfigurationInParentProcess()) { return; } @@ -290,6 +298,11 @@ class TargetConfigurationActor extends Actor { } _restoreParentProcessConfiguration() { + // Always process tracer options as this isn't specific to tab debugging + if (this.#consolePrefValue !== undefined) { + this._setTracerOptions(); + } + if (!this._shouldHandleConfigurationInParentProcess()) { return; } @@ -495,6 +508,37 @@ class TargetConfigurationActor extends Actor { } super.destroy(); } + + /** + * Called when the tracer is toggled on/off by the frontend. + * Note that when `options` is defined, it is meant to be enabled. + * It may not actually be tracing yet depending on the passed options. + * + * @param {Object} options + */ + _setTracerOptions(options) { + if (!options) { + if (this.#consolePrefValue === -1) { + Services.prefs.clearUserPref("logging.console"); + } else { + Services.prefs.setIntPref("logging.console", this.#consolePrefValue); + } + this.#consolePrefValue = undefined; + return; + } + // Enable `MOZ_LOG=console:5` via the logging.console so that all console API calls + // are stored in the profiler when recording JS Traces via the profiler. + // + // We do this from here as TargetConfiguration runs in the parent process, + // where we can set preferences. Whereas the profiler tracer actor runs in the content process. + const LOG_DISABLED = -1; + const LOG_VERBOSE = 5; + this.#consolePrefValue = Services.prefs.getIntPref( + "logging.console", + LOG_DISABLED + ); + Services.prefs.setIntPref("logging.console", LOG_VERBOSE); + } } exports.TargetConfigurationActor = TargetConfigurationActor;