diff --git a/front_end/core/sdk/BUILD.gn b/front_end/core/sdk/BUILD.gn index 9d2ba99eef85..fbb4ef85b4d3 100644 --- a/front_end/core/sdk/BUILD.gn +++ b/front_end/core/sdk/BUILD.gn @@ -44,6 +44,7 @@ devtools_module("sdk") { "EventBreakpointsModel.ts", "FrameAssociated.ts", "FrameManager.ts", + "FuseboxClientMetadataModel.ts", "HeapProfilerModel.ts", "HttpReasonPhraseStrings.ts", "IOModel.ts", diff --git a/front_end/core/sdk/FuseboxClientMetadataModel.ts b/front_end/core/sdk/FuseboxClientMetadataModel.ts new file mode 100644 index 000000000000..8644d3f79e93 --- /dev/null +++ b/front_end/core/sdk/FuseboxClientMetadataModel.ts @@ -0,0 +1,27 @@ +// Copyright (c) Meta Platforms, Inc. and affiliates. +// Copyright 2024 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import * as Host from '../host/host.js'; + +import {SDKModel} from './SDKModel.js'; +import {type Target} from './Target.js'; + +export class FuseboxClientMetadataModel extends SDKModel { + constructor(target: Target) { + super(target); + Host.rnPerfMetrics.fuseboxSetClientMetadataStarted(); + target.fuseboxClientAgent() + .invoke_setClientMetadata() + .then(result => { + const maybeError = result.getError(); + const success = !maybeError; + Host.rnPerfMetrics.fuseboxSetClientMetadataFinished(success, maybeError); + }) + .catch(reason => { + const success = false; + Host.rnPerfMetrics.fuseboxSetClientMetadataFinished(success, reason); + }); + } +} diff --git a/front_end/core/sdk/sdk.ts b/front_end/core/sdk/sdk.ts index 16420f9bf669..bac30afaffa4 100644 --- a/front_end/core/sdk/sdk.ts +++ b/front_end/core/sdk/sdk.ts @@ -45,6 +45,7 @@ import * as EmulationModel from './EmulationModel.js'; import * as EventBreakpointsModel from './EventBreakpointsModel.js'; import * as FrameAssociated from './FrameAssociated.js'; import * as FrameManager from './FrameManager.js'; +import * as FuseboxClientMetadataModel from './FuseboxClientMetadataModel.js'; import * as HeapProfilerModel from './HeapProfilerModel.js'; import * as IOModel from './IOModel.js'; import * as IsolateManager from './IsolateManager.js'; @@ -120,6 +121,7 @@ export { EventBreakpointsModel, FrameAssociated, FrameManager, + FuseboxClientMetadataModel, HeapProfilerModel, IOModel, IsolateManager, diff --git a/front_end/entrypoints/rn_fusebox/rn_fusebox.ts b/front_end/entrypoints/rn_fusebox/rn_fusebox.ts index 8e3affb2193f..e61b6f371e71 100644 --- a/front_end/entrypoints/rn_fusebox/rn_fusebox.ts +++ b/front_end/entrypoints/rn_fusebox/rn_fusebox.ts @@ -91,37 +91,19 @@ document.addEventListener('visibilitychange', () => { Host.rnPerfMetrics.browserVisibilityChanged(document.visibilityState); }); -class FuseboxClientMetadataModel extends SDK.SDKModel.SDKModel { - constructor(target: SDK.Target.Target) { - super(target); - Host.rnPerfMetrics.fuseboxSetClientMetadataStarted(); - target.fuseboxClientAgent() - .invoke_setClientMetadata() - .then(result => { - const maybeError = result.getError(); - const success = !maybeError; - Host.rnPerfMetrics.fuseboxSetClientMetadataFinished(success, maybeError); - }) - .catch(reason => { - const success = false; - Host.rnPerfMetrics.fuseboxSetClientMetadataFinished(success, reason); - }); - } -} - SDK.SDKModel.SDKModel.register( - FuseboxClientMetadataModel, - { - capabilities: SDK.Target.Capability.None, - autostart: true, - // Ensure FuseboxClient.setClientMetadata is sent before most other CDP domains - // are initialised. This allows the backend to confidently detect non-Fusebox - // clients by the fact that they send e.g. Runtime.enable without sending any - // Fusebox-specific messages first. - // TODO: Explicitly depend on this model in RuntimeModel and LogModel, and - // remove the `early` and `autostart` flags. - early: true, - }, + SDK.FuseboxClientMetadataModel.FuseboxClientMetadataModel, + { + capabilities: SDK.Target.Capability.None, + autostart: true, + // Ensure FuseboxClient.setClientMetadata is sent before most other CDP domains + // are initialised. This allows the backend to confidently detect non-Fusebox + // clients by the fact that they send e.g. Runtime.enable without sending any + // Fusebox-specific messages first. + // TODO: Explicitly depend on this model in RuntimeModel and LogModel, and + // remove the `early` and `autostart` flags. + early: true, + }, ); let loadedSourcesModule: (typeof Sources|undefined); diff --git a/front_end/panels/console/ConsoleView.ts b/front_end/panels/console/ConsoleView.ts index 2b36b6c37ca0..f9a6e55580e4 100644 --- a/front_end/panels/console/ConsoleView.ts +++ b/front_end/panels/console/ConsoleView.ts @@ -628,14 +628,16 @@ export class ConsoleView extends UI.Widget.VBox implements if (!Common.Settings.Settings.instance().moduleSetting('preserve-console-log').get() && model.target().outermostTarget() === model.target()) { this.consoleCleared(); - this.addConsoleMessage(new SDK.ConsoleModel.ConsoleMessage( - model.target().model(SDK.RuntimeModel.RuntimeModel), Protocol.Log.LogEntrySource.Recommendation, - Protocol.Log.LogEntryLevel.Info, - '[React Native] Console messages are currently cleared upon DevTools disconnection. You can preserve logs in settings: ', - { - type: SDK.ConsoleModel.FrontendMessageType.System, - context: 'fusebox_preserve_log_rec', - })); + if (model.target().model(SDK.FuseboxClientMetadataModel.FuseboxClientMetadataModel)) { + this.addConsoleMessage(new SDK.ConsoleModel.ConsoleMessage( + model.target().model(SDK.RuntimeModel.RuntimeModel), Protocol.Log.LogEntrySource.Recommendation, + Protocol.Log.LogEntryLevel.Info, + '[React Native] Console messages are currently cleared upon DevTools disconnection. You can preserve logs in settings: ', + { + type: SDK.ConsoleModel.FrontendMessageType.System, + context: 'fusebox_preserve_log_rec', + })); + } } } diff --git a/scripts/eslint_rules/lib/check_license_header.js b/scripts/eslint_rules/lib/check_license_header.js index b6e72c4d6db7..3e4bb5695b16 100644 --- a/scripts/eslint_rules/lib/check_license_header.js +++ b/scripts/eslint_rules/lib/check_license_header.js @@ -69,6 +69,7 @@ const EXCLUDED_FILES = [ const META_CODE_PATHS = [ 'core/host/RNPerfMetrics.ts', 'core/rn_experiments', + 'core/sdk/FuseboxClientMetadataModel.ts', 'core/sdk/ReactNativeApplicationModel.ts', 'entrypoints/rn_fusebox', 'entrypoints/rn_inspector',