@depup/react-native__dev-middleware 0.84.1-depup.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/changes.json +38 -0
- package/dist/createDevMiddleware.d.ts +62 -0
- package/dist/createDevMiddleware.js +140 -0
- package/dist/createDevMiddleware.js.flow +72 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +26 -0
- package/dist/index.js.flow +24 -0
- package/dist/inspector-proxy/CdpDebugLogging.d.ts +20 -0
- package/dist/inspector-proxy/CdpDebugLogging.js +117 -0
- package/dist/inspector-proxy/CdpDebugLogging.js.flow +20 -0
- package/dist/inspector-proxy/CustomMessageHandler.d.ts +48 -0
- package/dist/inspector-proxy/CustomMessageHandler.js +1 -0
- package/dist/inspector-proxy/CustomMessageHandler.js.flow +54 -0
- package/dist/inspector-proxy/Device.d.ts +62 -0
- package/dist/inspector-proxy/Device.js +810 -0
- package/dist/inspector-proxy/Device.js.flow +70 -0
- package/dist/inspector-proxy/DeviceEventReporter.d.ts +54 -0
- package/dist/inspector-proxy/DeviceEventReporter.js +194 -0
- package/dist/inspector-proxy/DeviceEventReporter.js.flow +62 -0
- package/dist/inspector-proxy/EventLoopPerfTracker.d.ts +31 -0
- package/dist/inspector-proxy/EventLoopPerfTracker.js +50 -0
- package/dist/inspector-proxy/EventLoopPerfTracker.js.flow +34 -0
- package/dist/inspector-proxy/InspectorProxy.d.ts +53 -0
- package/dist/inspector-proxy/InspectorProxy.js +477 -0
- package/dist/inspector-proxy/InspectorProxy.js.flow +62 -0
- package/dist/inspector-proxy/InspectorProxyHeartbeat.d.ts +24 -0
- package/dist/inspector-proxy/InspectorProxyHeartbeat.js +64 -0
- package/dist/inspector-proxy/InspectorProxyHeartbeat.js.flow +25 -0
- package/dist/inspector-proxy/cdp-types/messages.d.ts +41 -0
- package/dist/inspector-proxy/cdp-types/messages.js +1 -0
- package/dist/inspector-proxy/cdp-types/messages.js.flow +54 -0
- package/dist/inspector-proxy/cdp-types/protocol.d.ts +106 -0
- package/dist/inspector-proxy/cdp-types/protocol.js +1 -0
- package/dist/inspector-proxy/cdp-types/protocol.js.flow +124 -0
- package/dist/inspector-proxy/types.d.ts +115 -0
- package/dist/inspector-proxy/types.js +1 -0
- package/dist/inspector-proxy/types.js.flow +152 -0
- package/dist/middleware/openDebuggerMiddleware.d.ts +36 -0
- package/dist/middleware/openDebuggerMiddleware.js +216 -0
- package/dist/middleware/openDebuggerMiddleware.js.flow +36 -0
- package/dist/types/BrowserLauncher.d.ts +62 -0
- package/dist/types/BrowserLauncher.js +1 -0
- package/dist/types/BrowserLauncher.js.flow +66 -0
- package/dist/types/EventReporter.d.ts +124 -0
- package/dist/types/EventReporter.js +1 -0
- package/dist/types/EventReporter.js.flow +151 -0
- package/dist/types/Experiments.d.ts +30 -0
- package/dist/types/Experiments.js +1 -0
- package/dist/types/Experiments.js.flow +34 -0
- package/dist/types/Logger.d.ts +15 -0
- package/dist/types/Logger.js +1 -0
- package/dist/types/Logger.js.flow +16 -0
- package/dist/utils/DefaultBrowserLauncher.d.ts +30 -0
- package/dist/utils/DefaultBrowserLauncher.js +57 -0
- package/dist/utils/DefaultBrowserLauncher.js.flow +29 -0
- package/dist/utils/getBaseUrlFromRequest.d.ts +14 -0
- package/dist/utils/getBaseUrlFromRequest.js +19 -0
- package/dist/utils/getBaseUrlFromRequest.js.flow +17 -0
- package/dist/utils/getDevToolsFrontendUrl.d.ts +29 -0
- package/dist/utils/getDevToolsFrontendUrl.js +58 -0
- package/dist/utils/getDevToolsFrontendUrl.js.flow +29 -0
- package/package.json +97 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { EventReporter } from "../types/EventReporter";
|
|
12
|
+
import type { CreateCustomMessageHandlerFn } from "./CustomMessageHandler";
|
|
13
|
+
import type { Page } from "./types";
|
|
14
|
+
|
|
15
|
+
import WS from "ws";
|
|
16
|
+
|
|
17
|
+
// should be aligned with
|
|
18
|
+
// https://github.com/facebook/react-native-devtools-frontend/blob/3d17e0fd462dc698db34586697cce2371b25e0d3/front_end/ui/legacy/components/utils/TargetDetachedDialog.ts#L50-L64
|
|
19
|
+
declare export const WS_CLOSE_REASON: {
|
|
20
|
+
PAGE_NOT_FOUND: "[PAGE_NOT_FOUND] Debugger page not found",
|
|
21
|
+
CONNECTION_LOST: "[CONNECTION_LOST] Connection lost to corresponding device",
|
|
22
|
+
RECREATING_DEVICE: "[RECREATING_DEVICE] Recreating device connection",
|
|
23
|
+
NEW_DEBUGGER_OPENED: "[NEW_DEBUGGER_OPENED] New debugger opened for the same app instance",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type DeviceOptions = $ReadOnly<{
|
|
27
|
+
id: string,
|
|
28
|
+
name: string,
|
|
29
|
+
app: string,
|
|
30
|
+
socket: WS,
|
|
31
|
+
eventReporter: ?EventReporter,
|
|
32
|
+
createMessageMiddleware: ?CreateCustomMessageHandlerFn,
|
|
33
|
+
deviceRelativeBaseUrl: URL,
|
|
34
|
+
serverRelativeBaseUrl: URL,
|
|
35
|
+
isProfilingBuild: boolean,
|
|
36
|
+
}>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Device class represents single device connection to Inspector Proxy. Each device
|
|
40
|
+
* can have multiple inspectable pages.
|
|
41
|
+
*/
|
|
42
|
+
declare export default class Device {
|
|
43
|
+
constructor(deviceOptions: DeviceOptions): void;
|
|
44
|
+
/**
|
|
45
|
+
* Used to recreate the device connection if there is a device ID collision.
|
|
46
|
+
* 1. Checks if the same device is attempting to reconnect for the same app.
|
|
47
|
+
* 2. If not, close both the device and debugger socket.
|
|
48
|
+
* 3. If the debugger connection can be reused, close the device socket only.
|
|
49
|
+
*
|
|
50
|
+
* This hack attempts to allow users to reload the app, either as result of a
|
|
51
|
+
* crash, or manually reloading, without having to restart the debugger.
|
|
52
|
+
*/
|
|
53
|
+
dangerouslyRecreateDevice(deviceOptions: DeviceOptions): void;
|
|
54
|
+
getName(): string;
|
|
55
|
+
getApp(): string;
|
|
56
|
+
getPagesList(): $ReadOnlyArray<Page>;
|
|
57
|
+
// Handles new debugger connection to this device:
|
|
58
|
+
// 1. Sends connect event to device
|
|
59
|
+
// 2. Forwards all messages from the debugger to device as wrappedEvent
|
|
60
|
+
// 3. Sends disconnect event to device when debugger connection socket closes.
|
|
61
|
+
handleDebuggerConnection(
|
|
62
|
+
socket: WS,
|
|
63
|
+
pageId: string,
|
|
64
|
+
$$PARAM_2$$: $ReadOnly<{
|
|
65
|
+
debuggerRelativeBaseUrl: URL,
|
|
66
|
+
userAgent: string | null,
|
|
67
|
+
}>,
|
|
68
|
+
): void;
|
|
69
|
+
dangerouslyGetSocket(): WS;
|
|
70
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { EventReporter } from "../types/EventReporter";
|
|
12
|
+
import type { CDPResponse } from "./cdp-types/messages";
|
|
13
|
+
import type { DeepReadOnly } from "./types";
|
|
14
|
+
type DeviceMetadata = Readonly<{
|
|
15
|
+
appId: string;
|
|
16
|
+
deviceId: string;
|
|
17
|
+
deviceName: string;
|
|
18
|
+
}>;
|
|
19
|
+
type RequestMetadata = Readonly<{
|
|
20
|
+
pageId: string | null;
|
|
21
|
+
frontendUserAgent: string | null;
|
|
22
|
+
prefersFuseboxFrontend: boolean | null;
|
|
23
|
+
}>;
|
|
24
|
+
type ResponseMetadata = Readonly<{
|
|
25
|
+
pageId: string | null;
|
|
26
|
+
frontendUserAgent: string | null;
|
|
27
|
+
prefersFuseboxFrontend: boolean | null;
|
|
28
|
+
}>;
|
|
29
|
+
declare class DeviceEventReporter {
|
|
30
|
+
constructor(eventReporter: EventReporter, metadata: DeviceMetadata);
|
|
31
|
+
logRequest(
|
|
32
|
+
req: Readonly<{ id: number; method: string }>,
|
|
33
|
+
origin: "debugger" | "proxy",
|
|
34
|
+
metadata: RequestMetadata,
|
|
35
|
+
): void;
|
|
36
|
+
logResponse(
|
|
37
|
+
res: DeepReadOnly<CDPResponse>,
|
|
38
|
+
origin: "device" | "proxy",
|
|
39
|
+
metadata: ResponseMetadata,
|
|
40
|
+
): void;
|
|
41
|
+
logProfilingTargetRegistered(): void;
|
|
42
|
+
logConnection(
|
|
43
|
+
connectedEntity: "debugger",
|
|
44
|
+
metadata: Readonly<{ pageId: string; frontendUserAgent: string | null }>,
|
|
45
|
+
): void;
|
|
46
|
+
logDisconnection(disconnectedEntity: "device" | "debugger"): void;
|
|
47
|
+
logProxyMessageHandlingError(
|
|
48
|
+
messageOrigin: "device" | "debugger",
|
|
49
|
+
error: Error,
|
|
50
|
+
message: string,
|
|
51
|
+
): void;
|
|
52
|
+
logFuseboxConsoleNotice(): void;
|
|
53
|
+
}
|
|
54
|
+
export default DeviceEventReporter;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _ttlcache = _interopRequireDefault(require("@isaacs/ttlcache"));
|
|
8
|
+
function _interopRequireDefault(e) {
|
|
9
|
+
return e && e.__esModule ? e : { default: e };
|
|
10
|
+
}
|
|
11
|
+
class DeviceEventReporter {
|
|
12
|
+
#eventReporter;
|
|
13
|
+
#pendingCommands = new _ttlcache.default({
|
|
14
|
+
ttl: 10000,
|
|
15
|
+
dispose: (command, id, reason) => {
|
|
16
|
+
if (reason === "delete" || reason === "set") {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
this.#logExpiredCommand(command);
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
#metadata;
|
|
23
|
+
#deviceConnectedTimestamp;
|
|
24
|
+
constructor(eventReporter, metadata) {
|
|
25
|
+
this.#eventReporter = eventReporter;
|
|
26
|
+
this.#metadata = metadata;
|
|
27
|
+
this.#deviceConnectedTimestamp = Date.now();
|
|
28
|
+
}
|
|
29
|
+
logRequest(req, origin, metadata) {
|
|
30
|
+
this.#pendingCommands.set(req.id, {
|
|
31
|
+
method: req.method,
|
|
32
|
+
requestOrigin: origin,
|
|
33
|
+
requestTime: Date.now(),
|
|
34
|
+
metadata,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
logResponse(res, origin, metadata) {
|
|
38
|
+
const pendingCommand = this.#pendingCommands.get(res.id);
|
|
39
|
+
if (!pendingCommand) {
|
|
40
|
+
this.#eventReporter.logEvent({
|
|
41
|
+
type: "debugger_command",
|
|
42
|
+
protocol: "CDP",
|
|
43
|
+
requestOrigin: null,
|
|
44
|
+
method: null,
|
|
45
|
+
status: "coded_error",
|
|
46
|
+
errorCode: "UNMATCHED_REQUEST_ID",
|
|
47
|
+
responseOrigin: "proxy",
|
|
48
|
+
timeSinceStart: null,
|
|
49
|
+
appId: this.#metadata.appId,
|
|
50
|
+
deviceId: this.#metadata.deviceId,
|
|
51
|
+
deviceName: this.#metadata.deviceName,
|
|
52
|
+
pageId: metadata.pageId,
|
|
53
|
+
frontendUserAgent: metadata.frontendUserAgent,
|
|
54
|
+
prefersFuseboxFrontend: metadata.prefersFuseboxFrontend,
|
|
55
|
+
connectionUptime: this.#deviceConnectedTimestamp - Date.now(),
|
|
56
|
+
});
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const timeSinceStart = Date.now() - pendingCommand.requestTime;
|
|
60
|
+
this.#pendingCommands.delete(res.id);
|
|
61
|
+
if (res.error) {
|
|
62
|
+
let { message } = res.error;
|
|
63
|
+
if ("data" in res.error) {
|
|
64
|
+
message += ` (${String(res.error.data)})`;
|
|
65
|
+
}
|
|
66
|
+
this.#eventReporter.logEvent({
|
|
67
|
+
type: "debugger_command",
|
|
68
|
+
requestOrigin: pendingCommand.requestOrigin,
|
|
69
|
+
method: pendingCommand.method,
|
|
70
|
+
protocol: "CDP",
|
|
71
|
+
status: "coded_error",
|
|
72
|
+
errorCode: "PROTOCOL_ERROR",
|
|
73
|
+
errorDetails: message,
|
|
74
|
+
responseOrigin: origin,
|
|
75
|
+
timeSinceStart,
|
|
76
|
+
appId: this.#metadata.appId,
|
|
77
|
+
deviceId: this.#metadata.deviceId,
|
|
78
|
+
deviceName: this.#metadata.deviceName,
|
|
79
|
+
pageId: pendingCommand.metadata.pageId,
|
|
80
|
+
frontendUserAgent: pendingCommand.metadata.frontendUserAgent,
|
|
81
|
+
prefersFuseboxFrontend: metadata.prefersFuseboxFrontend,
|
|
82
|
+
connectionUptime: this.#deviceConnectedTimestamp - Date.now(),
|
|
83
|
+
});
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.#eventReporter.logEvent({
|
|
87
|
+
type: "debugger_command",
|
|
88
|
+
protocol: "CDP",
|
|
89
|
+
requestOrigin: pendingCommand.requestOrigin,
|
|
90
|
+
method: pendingCommand.method,
|
|
91
|
+
status: "success",
|
|
92
|
+
responseOrigin: origin,
|
|
93
|
+
timeSinceStart,
|
|
94
|
+
appId: this.#metadata.appId,
|
|
95
|
+
deviceId: this.#metadata.deviceId,
|
|
96
|
+
deviceName: this.#metadata.deviceName,
|
|
97
|
+
pageId: pendingCommand.metadata.pageId,
|
|
98
|
+
frontendUserAgent: pendingCommand.metadata.frontendUserAgent,
|
|
99
|
+
prefersFuseboxFrontend: metadata.prefersFuseboxFrontend,
|
|
100
|
+
connectionUptime: this.#deviceConnectedTimestamp - Date.now(),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
logProfilingTargetRegistered() {
|
|
104
|
+
this.#eventReporter.logEvent({
|
|
105
|
+
type: "profiling_target_registered",
|
|
106
|
+
status: "success",
|
|
107
|
+
appId: this.#metadata.appId,
|
|
108
|
+
deviceName: this.#metadata.deviceName,
|
|
109
|
+
deviceId: this.#metadata.deviceId,
|
|
110
|
+
pageId: null,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
logConnection(connectedEntity, metadata) {
|
|
114
|
+
this.#eventReporter.logEvent({
|
|
115
|
+
type: "connect_debugger_frontend",
|
|
116
|
+
status: "success",
|
|
117
|
+
appId: this.#metadata.appId,
|
|
118
|
+
deviceName: this.#metadata.deviceName,
|
|
119
|
+
deviceId: this.#metadata.deviceId,
|
|
120
|
+
pageId: metadata.pageId,
|
|
121
|
+
frontendUserAgent: metadata.frontendUserAgent,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
logDisconnection(disconnectedEntity) {
|
|
125
|
+
const eventReporter = this.#eventReporter;
|
|
126
|
+
if (!eventReporter) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const errorCode =
|
|
130
|
+
disconnectedEntity === "device"
|
|
131
|
+
? "DEVICE_DISCONNECTED"
|
|
132
|
+
: "DEBUGGER_DISCONNECTED";
|
|
133
|
+
for (const pendingCommand of this.#pendingCommands.values()) {
|
|
134
|
+
this.#eventReporter.logEvent({
|
|
135
|
+
type: "debugger_command",
|
|
136
|
+
protocol: "CDP",
|
|
137
|
+
requestOrigin: pendingCommand.requestOrigin,
|
|
138
|
+
method: pendingCommand.method,
|
|
139
|
+
status: "coded_error",
|
|
140
|
+
errorCode,
|
|
141
|
+
responseOrigin: "proxy",
|
|
142
|
+
timeSinceStart: Date.now() - pendingCommand.requestTime,
|
|
143
|
+
appId: this.#metadata.appId,
|
|
144
|
+
deviceId: this.#metadata.deviceId,
|
|
145
|
+
deviceName: this.#metadata.deviceName,
|
|
146
|
+
pageId: pendingCommand.metadata.pageId,
|
|
147
|
+
frontendUserAgent: pendingCommand.metadata.frontendUserAgent,
|
|
148
|
+
prefersFuseboxFrontend: pendingCommand.metadata.prefersFuseboxFrontend,
|
|
149
|
+
connectionUptime: this.#deviceConnectedTimestamp - Date.now(),
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
this.#pendingCommands.clear();
|
|
153
|
+
}
|
|
154
|
+
logProxyMessageHandlingError(messageOrigin, error, message) {
|
|
155
|
+
this.#eventReporter.logEvent({
|
|
156
|
+
type: "proxy_error",
|
|
157
|
+
status: "error",
|
|
158
|
+
messageOrigin,
|
|
159
|
+
message,
|
|
160
|
+
error: error.message,
|
|
161
|
+
errorStack: error.stack,
|
|
162
|
+
appId: this.#metadata.appId,
|
|
163
|
+
deviceId: this.#metadata.deviceId,
|
|
164
|
+
deviceName: this.#metadata.deviceName,
|
|
165
|
+
pageId: null,
|
|
166
|
+
connectionUptime: this.#deviceConnectedTimestamp - Date.now(),
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
logFuseboxConsoleNotice() {
|
|
170
|
+
this.#eventReporter.logEvent({
|
|
171
|
+
type: "fusebox_console_notice",
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
#logExpiredCommand(pendingCommand) {
|
|
175
|
+
this.#eventReporter.logEvent({
|
|
176
|
+
type: "debugger_command",
|
|
177
|
+
protocol: "CDP",
|
|
178
|
+
requestOrigin: pendingCommand.requestOrigin,
|
|
179
|
+
method: pendingCommand.method,
|
|
180
|
+
status: "coded_error",
|
|
181
|
+
errorCode: "TIMED_OUT",
|
|
182
|
+
responseOrigin: "proxy",
|
|
183
|
+
timeSinceStart: Date.now() - pendingCommand.requestTime,
|
|
184
|
+
appId: this.#metadata.appId,
|
|
185
|
+
deviceId: this.#metadata.deviceId,
|
|
186
|
+
deviceName: this.#metadata.deviceName,
|
|
187
|
+
pageId: pendingCommand.metadata.pageId,
|
|
188
|
+
frontendUserAgent: pendingCommand.metadata.frontendUserAgent,
|
|
189
|
+
prefersFuseboxFrontend: pendingCommand.metadata.prefersFuseboxFrontend,
|
|
190
|
+
connectionUptime: this.#deviceConnectedTimestamp - Date.now(),
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
var _default = (exports.default = DeviceEventReporter);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { EventReporter } from "../types/EventReporter";
|
|
12
|
+
import type { CDPResponse } from "./cdp-types/messages";
|
|
13
|
+
import type { DeepReadOnly } from "./types";
|
|
14
|
+
|
|
15
|
+
type DeviceMetadata = $ReadOnly<{
|
|
16
|
+
appId: string,
|
|
17
|
+
deviceId: string,
|
|
18
|
+
deviceName: string,
|
|
19
|
+
}>;
|
|
20
|
+
|
|
21
|
+
type RequestMetadata = $ReadOnly<{
|
|
22
|
+
pageId: string | null,
|
|
23
|
+
frontendUserAgent: string | null,
|
|
24
|
+
prefersFuseboxFrontend: boolean | null,
|
|
25
|
+
}>;
|
|
26
|
+
|
|
27
|
+
type ResponseMetadata = $ReadOnly<{
|
|
28
|
+
pageId: string | null,
|
|
29
|
+
frontendUserAgent: string | null,
|
|
30
|
+
prefersFuseboxFrontend: boolean | null,
|
|
31
|
+
}>;
|
|
32
|
+
|
|
33
|
+
declare class DeviceEventReporter {
|
|
34
|
+
constructor(eventReporter: EventReporter, metadata: DeviceMetadata): void;
|
|
35
|
+
logRequest(
|
|
36
|
+
req: $ReadOnly<{ id: number, method: string, ... }>,
|
|
37
|
+
origin: "debugger" | "proxy",
|
|
38
|
+
metadata: RequestMetadata,
|
|
39
|
+
): void;
|
|
40
|
+
logResponse(
|
|
41
|
+
res: DeepReadOnly<CDPResponse<>>,
|
|
42
|
+
origin: "device" | "proxy",
|
|
43
|
+
metadata: ResponseMetadata,
|
|
44
|
+
): void;
|
|
45
|
+
logProfilingTargetRegistered(): void;
|
|
46
|
+
logConnection(
|
|
47
|
+
connectedEntity: "debugger",
|
|
48
|
+
metadata: $ReadOnly<{
|
|
49
|
+
pageId: string,
|
|
50
|
+
frontendUserAgent: string | null,
|
|
51
|
+
}>,
|
|
52
|
+
): void;
|
|
53
|
+
logDisconnection(disconnectedEntity: "device" | "debugger"): void;
|
|
54
|
+
logProxyMessageHandlingError(
|
|
55
|
+
messageOrigin: "device" | "debugger",
|
|
56
|
+
error: Error,
|
|
57
|
+
message: string,
|
|
58
|
+
): void;
|
|
59
|
+
logFuseboxConsoleNotice(): void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
declare export default typeof DeviceEventReporter;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { DebuggerSessionIDs } from "../types/EventReporter";
|
|
12
|
+
export type EventLoopPerfTrackerArgs = {
|
|
13
|
+
perfMeasurementDuration: number;
|
|
14
|
+
minDelayPercentToReport: number;
|
|
15
|
+
onHighDelay: (args: OnHighDelayArgs) => void;
|
|
16
|
+
};
|
|
17
|
+
export type OnHighDelayArgs = {
|
|
18
|
+
eventLoopUtilization: number;
|
|
19
|
+
maxEventLoopDelayPercent: number;
|
|
20
|
+
duration: number;
|
|
21
|
+
debuggerSessionIDs: DebuggerSessionIDs;
|
|
22
|
+
connectionUptime: number;
|
|
23
|
+
};
|
|
24
|
+
declare class EventLoopPerfTracker {
|
|
25
|
+
constructor(args: EventLoopPerfTrackerArgs);
|
|
26
|
+
trackPerfThrottled(
|
|
27
|
+
debuggerSessionIDs: DebuggerSessionIDs,
|
|
28
|
+
connectionUptime: number,
|
|
29
|
+
): void;
|
|
30
|
+
}
|
|
31
|
+
export default EventLoopPerfTracker;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _perf_hooks = require("perf_hooks");
|
|
8
|
+
var _timers = require("timers");
|
|
9
|
+
class EventLoopPerfTracker {
|
|
10
|
+
#perfMeasurementDuration;
|
|
11
|
+
#minDelayPercentToReport;
|
|
12
|
+
#onHighDelay;
|
|
13
|
+
#eventLoopPerfMeasurementOngoing;
|
|
14
|
+
constructor(args) {
|
|
15
|
+
this.#perfMeasurementDuration = args.perfMeasurementDuration;
|
|
16
|
+
this.#minDelayPercentToReport = args.minDelayPercentToReport;
|
|
17
|
+
this.#onHighDelay = args.onHighDelay;
|
|
18
|
+
this.#eventLoopPerfMeasurementOngoing = false;
|
|
19
|
+
}
|
|
20
|
+
trackPerfThrottled(debuggerSessionIDs, connectionUptime) {
|
|
21
|
+
if (this.#eventLoopPerfMeasurementOngoing) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
this.#eventLoopPerfMeasurementOngoing = true;
|
|
25
|
+
const eluStart = _perf_hooks.performance.eventLoopUtilization();
|
|
26
|
+
const h = (0, _perf_hooks.monitorEventLoopDelay)({
|
|
27
|
+
resolution: 20,
|
|
28
|
+
});
|
|
29
|
+
h.enable();
|
|
30
|
+
(0, _timers.setTimeout)(() => {
|
|
31
|
+
const eluEnd = _perf_hooks.performance.eventLoopUtilization(eluStart);
|
|
32
|
+
h.disable();
|
|
33
|
+
const eventLoopUtilization = Math.floor(eluEnd.utilization * 100);
|
|
34
|
+
const maxEventLoopDelayPercent = Math.floor(
|
|
35
|
+
(h.max / 1e6 / this.#perfMeasurementDuration) * 100,
|
|
36
|
+
);
|
|
37
|
+
if (maxEventLoopDelayPercent >= this.#minDelayPercentToReport) {
|
|
38
|
+
this.#onHighDelay({
|
|
39
|
+
eventLoopUtilization,
|
|
40
|
+
maxEventLoopDelayPercent,
|
|
41
|
+
duration: this.#perfMeasurementDuration,
|
|
42
|
+
debuggerSessionIDs,
|
|
43
|
+
connectionUptime,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
this.#eventLoopPerfMeasurementOngoing = false;
|
|
47
|
+
}, this.#perfMeasurementDuration).unref();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.default = EventLoopPerfTracker;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// $FlowFixMe[cannot-resolve-module] libdef missing in RN OSS
|
|
12
|
+
import type { DebuggerSessionIDs } from "../types/EventReporter";
|
|
13
|
+
|
|
14
|
+
export type EventLoopPerfTrackerArgs = {
|
|
15
|
+
perfMeasurementDuration: number,
|
|
16
|
+
minDelayPercentToReport: number,
|
|
17
|
+
onHighDelay: (args: OnHighDelayArgs) => void,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type OnHighDelayArgs = {
|
|
21
|
+
eventLoopUtilization: number,
|
|
22
|
+
maxEventLoopDelayPercent: number,
|
|
23
|
+
duration: number,
|
|
24
|
+
debuggerSessionIDs: DebuggerSessionIDs,
|
|
25
|
+
connectionUptime: number,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
declare export default class EventLoopPerfTracker {
|
|
29
|
+
constructor(args: EventLoopPerfTrackerArgs): void;
|
|
30
|
+
trackPerfThrottled(
|
|
31
|
+
debuggerSessionIDs: DebuggerSessionIDs,
|
|
32
|
+
connectionUptime: number,
|
|
33
|
+
): void;
|
|
34
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { EventReporter } from "../types/EventReporter";
|
|
12
|
+
import type { Experiments } from "../types/Experiments";
|
|
13
|
+
import type { Logger } from "../types/Logger";
|
|
14
|
+
import type { CreateCustomMessageHandlerFn } from "./CustomMessageHandler";
|
|
15
|
+
import type { PageDescription } from "./types";
|
|
16
|
+
import type { IncomingMessage, ServerResponse } from "http";
|
|
17
|
+
import WS from "ws";
|
|
18
|
+
export type GetPageDescriptionsConfig = {
|
|
19
|
+
requestorRelativeBaseUrl: URL;
|
|
20
|
+
logNoPagesForConnectedDevice?: boolean;
|
|
21
|
+
};
|
|
22
|
+
export interface InspectorProxyQueries {
|
|
23
|
+
/**
|
|
24
|
+
* Returns list of page descriptions ordered by device connection order, then
|
|
25
|
+
* page addition order.
|
|
26
|
+
*/
|
|
27
|
+
getPageDescriptions(
|
|
28
|
+
config: GetPageDescriptionsConfig,
|
|
29
|
+
): Array<PageDescription>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Main Inspector Proxy class that connects JavaScript VM inside Android/iOS apps and JS debugger.
|
|
33
|
+
*/
|
|
34
|
+
declare class InspectorProxy implements InspectorProxyQueries {
|
|
35
|
+
constructor(
|
|
36
|
+
serverBaseUrl: string,
|
|
37
|
+
eventReporter: null | undefined | EventReporter,
|
|
38
|
+
experiments: Experiments,
|
|
39
|
+
logger?: Logger,
|
|
40
|
+
customMessageHandler: null | undefined | CreateCustomMessageHandlerFn,
|
|
41
|
+
trackEventLoopPerf?: boolean,
|
|
42
|
+
);
|
|
43
|
+
getPageDescriptions(
|
|
44
|
+
$$PARAM_0$$: GetPageDescriptionsConfig,
|
|
45
|
+
): Array<PageDescription>;
|
|
46
|
+
processRequest(
|
|
47
|
+
request: IncomingMessage,
|
|
48
|
+
response: ServerResponse,
|
|
49
|
+
next: ($$PARAM_0$$: null | undefined | Error) => unknown,
|
|
50
|
+
): void;
|
|
51
|
+
createWebSocketListeners(): { [path: string]: WS.Server };
|
|
52
|
+
}
|
|
53
|
+
export default InspectorProxy;
|