Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Fusebox setClientMetadata handshake with ReactNativeApplicationModel #139

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions front_end/core/protocol_client/InspectorBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,10 +672,6 @@ export class TargetBase {
return this.getAgent('Fetch');
}

fuseboxClientAgent(): ProtocolProxyApi.FuseboxClientApi {
return this.getAgent('FuseboxClient');
}

heapProfilerAgent(): ProtocolProxyApi.HeapProfilerApi {
return this.getAgent('HeapProfiler');
}
Expand Down
23 changes: 14 additions & 9 deletions front_end/core/sdk/ReactNativeApplicationModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import type * as ProtocolProxyApi from '../../generated/protocol-proxy-api.js';
import type * as Protocol from '../../generated/protocol.js';

import * as Host from '../../core/host/host.js';
import {Capability, type Target} from './Target.js';
import {SDKModel} from './SDKModel.js';

Expand All @@ -21,14 +22,26 @@ export class ReactNativeApplicationModel extends SDKModel<EventTypes> implements
this.#enabled = false;
this.#agent = target.reactNativeApplicationAgent();
target.registerReactNativeApplicationDispatcher(this);

// Auto-init. Paired with registering this model immediately in rn_fusebox.ts.
this.ensureEnabled();
}

ensureEnabled(): void {
if (this.#enabled) {
return;
}

void this.#agent.invoke_enable();
void this.#agent.invoke_enable()
.then(result => {
const maybeError = result.getError();
const success = !maybeError;
Host.rnPerfMetrics.fuseboxSetClientMetadataFinished(success, maybeError);
})
.catch(reason => {
const success = false;
Host.rnPerfMetrics.fuseboxSetClientMetadataFinished(success, reason);
});
this.#enabled = true;
}

Expand All @@ -45,11 +58,3 @@ export const enum Events {
export type EventTypes = {
[Events.MetadataUpdated]: Protocol.ReactNativeApplication.MetadataUpdatedEvent,
};

SDKModel.register(
ReactNativeApplicationModel,
{
capabilities: Capability.None,
autostart: true,
},
);
22 changes: 2 additions & 20 deletions front_end/entrypoints/rn_fusebox/rn_fusebox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,12 @@ document.addEventListener('visibilitychange', () => {
Host.rnPerfMetrics.browserVisibilityChanged(document.visibilityState);
});

class FuseboxClientMetadataModel extends SDK.SDKModel.SDKModel<void> {
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,
SDK.ReactNativeApplicationModel.ReactNativeApplicationModel,
{
capabilities: SDK.Target.Capability.None,
autostart: true,
// Ensure FuseboxClient.setClientMetadata is sent before most other CDP domains
// Ensure ReactNativeApplication.enable 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.
Expand Down
3 changes: 0 additions & 3 deletions front_end/generated/InspectorBackendCommands.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions front_end/generated/protocol-mapping.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,17 +765,6 @@ export namespace ProtocolMapping {
}

export interface Commands {
/**
* Identifies the current client as being Fusebox.
*
* The Fusebox backend may use this knowledge to print an informational
* message to the console, etc. The client should send this before enabling
* the Runtime and Log domains.
*/
'FuseboxClient.setClientMetadata': {
paramsType: [];
returnType: void;
};
/**
* Disables events from backend.
*/
Expand Down
19 changes: 0 additions & 19 deletions front_end/generated/protocol-proxy-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ declare namespace ProtocolProxyApi {
export type ProtocolDomainName = keyof ProtocolApi;

export interface ProtocolApi {
FuseboxClient: FuseboxClientApi;

ReactNativeApplication: ReactNativeApplicationApi;

Accessibility: AccessibilityApi;
Expand Down Expand Up @@ -123,8 +121,6 @@ declare namespace ProtocolProxyApi {
}

export interface ProtocolDispatchers {
FuseboxClient: FuseboxClientDispatcher;

ReactNativeApplication: ReactNativeApplicationDispatcher;

Accessibility: AccessibilityDispatcher;
Expand Down Expand Up @@ -227,21 +223,6 @@ declare namespace ProtocolProxyApi {

}


export interface FuseboxClientApi {
/**
* Identifies the current client as being Fusebox.
*
* The Fusebox backend may use this knowledge to print an informational
* message to the console, etc. The client should send this before enabling
* the Runtime and Log domains.
*/
invoke_setClientMetadata(): Promise<Protocol.ProtocolResponseWithError>;

}
export interface FuseboxClientDispatcher {
}

export interface ReactNativeApplicationApi {
/**
* Disables events from backend.
Expand Down
7 changes: 0 additions & 7 deletions front_end/generated/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ export interface ProtocolResponseWithError {
type OpaqueType<Tag extends string> = {protocolOpaqueTypeTag: Tag};
type OpaqueIdentifier<RepresentationType, Tag extends string> = RepresentationType&OpaqueType<Tag>;

/**
* A React Native-specific domain pertaining to the Fusebox (React Native
* DevTools) client.
*/
export namespace FuseboxClient {
}

/**
* A React Native-specific domain for interacting with React Native application
* features.
Expand Down
11 changes: 0 additions & 11 deletions third_party/blink/public/devtools_protocol/browser_protocol.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@
"minor": "3"
},
"domains": [
{
"domain": "FuseboxClient",
"description": "A React Native-specific domain pertaining to the Fusebox (React Native\nDevTools) client.",
"experimental": true,
"commands": [
{
"name": "setClientMetadata",
"description": "Identifies the current client as being Fusebox.\n\nThe Fusebox backend may use this knowledge to print an informational\nmessage to the console, etc. The client should send this before enabling\nthe Runtime and Log domains."
}
]
},
{
"domain": "ReactNativeApplication",
"description": "A React Native-specific domain for interacting with React Native application\nfeatures.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.

# A React Native-specific domain pertaining to the Fusebox (React Native
# DevTools) client.
experimental domain FuseboxClient

# Identifies the current client as being Fusebox.
#
# The Fusebox backend may use this knowledge to print an informational
# message to the console, etc. The client should send this before enabling
# the Runtime and Log domains.
command setClientMetadata

# A React Native-specific domain for interacting with React Native application
# features.
experimental domain ReactNativeApplication
Expand Down