@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,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = openDebuggerMiddleware;
|
|
7
|
+
var _getDevToolsFrontendUrl = _interopRequireDefault(
|
|
8
|
+
require("../utils/getDevToolsFrontendUrl"),
|
|
9
|
+
);
|
|
10
|
+
var _crypto = require("crypto");
|
|
11
|
+
var _url = _interopRequireDefault(require("url"));
|
|
12
|
+
function _interopRequireDefault(e) {
|
|
13
|
+
return e && e.__esModule ? e : { default: e };
|
|
14
|
+
}
|
|
15
|
+
const LEGACY_SYNTHETIC_PAGE_TITLE =
|
|
16
|
+
"React Native Experimental (Improved Chrome Reloads)";
|
|
17
|
+
function openDebuggerMiddleware({
|
|
18
|
+
serverBaseUrl,
|
|
19
|
+
logger,
|
|
20
|
+
browserLauncher,
|
|
21
|
+
eventReporter,
|
|
22
|
+
experiments,
|
|
23
|
+
inspectorProxy,
|
|
24
|
+
}) {
|
|
25
|
+
let shellPreparationPromise;
|
|
26
|
+
if (experiments.enableStandaloneFuseboxShell) {
|
|
27
|
+
shellPreparationPromise =
|
|
28
|
+
browserLauncher?.unstable_prepareFuseboxShell?.() ??
|
|
29
|
+
Promise.resolve({
|
|
30
|
+
code: "not_implemented",
|
|
31
|
+
});
|
|
32
|
+
shellPreparationPromise = shellPreparationPromise.then((result) => {
|
|
33
|
+
eventReporter?.logEvent({
|
|
34
|
+
type: "fusebox_shell_preparation_attempt",
|
|
35
|
+
result,
|
|
36
|
+
});
|
|
37
|
+
return result;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return async (req, res, next) => {
|
|
41
|
+
if (
|
|
42
|
+
req.method === "POST" ||
|
|
43
|
+
(experiments.enableOpenDebuggerRedirect && req.method === "GET")
|
|
44
|
+
) {
|
|
45
|
+
const parsedUrl = _url.default.parse(req.url, true);
|
|
46
|
+
const query = parsedUrl.query;
|
|
47
|
+
const targets = inspectorProxy
|
|
48
|
+
.getPageDescriptions({
|
|
49
|
+
requestorRelativeBaseUrl: new URL(serverBaseUrl),
|
|
50
|
+
})
|
|
51
|
+
.filter((app) => {
|
|
52
|
+
const betterReloadingSupport =
|
|
53
|
+
app.title === LEGACY_SYNTHETIC_PAGE_TITLE ||
|
|
54
|
+
app.reactNative.capabilities?.nativePageReloads === true;
|
|
55
|
+
if (!betterReloadingSupport) {
|
|
56
|
+
logger?.warn(
|
|
57
|
+
"Ignoring DevTools app debug target for '%s' with title '%s' and 'nativePageReloads' capability set to '%s'. ",
|
|
58
|
+
app.appId,
|
|
59
|
+
app.title,
|
|
60
|
+
String(app.reactNative.capabilities?.nativePageReloads),
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
return betterReloadingSupport;
|
|
64
|
+
});
|
|
65
|
+
let target;
|
|
66
|
+
const launchType = req.method === "POST" ? "launch" : "redirect";
|
|
67
|
+
if (
|
|
68
|
+
typeof query.target === "string" ||
|
|
69
|
+
typeof query.appId === "string" ||
|
|
70
|
+
typeof query.device === "string"
|
|
71
|
+
) {
|
|
72
|
+
logger?.info(
|
|
73
|
+
(launchType === "launch" ? "Launching" : "Redirecting to") +
|
|
74
|
+
" DevTools...",
|
|
75
|
+
);
|
|
76
|
+
target = targets.find(
|
|
77
|
+
(_target) =>
|
|
78
|
+
(query.target == null || _target.id === query.target) &&
|
|
79
|
+
(query.appId == null ||
|
|
80
|
+
(_target.appId === query.appId &&
|
|
81
|
+
_target.title === LEGACY_SYNTHETIC_PAGE_TITLE)) &&
|
|
82
|
+
(query.device == null ||
|
|
83
|
+
_target.reactNative.logicalDeviceId === query.device),
|
|
84
|
+
);
|
|
85
|
+
} else if (targets.length > 0) {
|
|
86
|
+
logger?.info(
|
|
87
|
+
(launchType === "launch" ? "Launching" : "Redirecting to") +
|
|
88
|
+
` DevTools${targets.length === 1 ? "" : " for most recently connected target"}...`,
|
|
89
|
+
);
|
|
90
|
+
target = targets[targets.length - 1];
|
|
91
|
+
}
|
|
92
|
+
if (!target) {
|
|
93
|
+
res.writeHead(404);
|
|
94
|
+
res.end("Unable to find debugger target");
|
|
95
|
+
logger?.warn(
|
|
96
|
+
"No compatible apps connected. React Native DevTools can only be used with the Hermes engine.",
|
|
97
|
+
);
|
|
98
|
+
eventReporter?.logEvent({
|
|
99
|
+
type: "launch_debugger_frontend",
|
|
100
|
+
launchType,
|
|
101
|
+
status: "coded_error",
|
|
102
|
+
errorCode: "NO_APPS_FOUND",
|
|
103
|
+
});
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const useFuseboxEntryPoint =
|
|
107
|
+
target.reactNative.capabilities?.prefersFuseboxFrontend ?? false;
|
|
108
|
+
try {
|
|
109
|
+
switch (launchType) {
|
|
110
|
+
case "launch": {
|
|
111
|
+
const frontendUrl = (0, _getDevToolsFrontendUrl.default)(
|
|
112
|
+
experiments,
|
|
113
|
+
target.webSocketDebuggerUrl,
|
|
114
|
+
serverBaseUrl,
|
|
115
|
+
{
|
|
116
|
+
launchId: query.launchId,
|
|
117
|
+
telemetryInfo: query.telemetryInfo,
|
|
118
|
+
appId: target.appId,
|
|
119
|
+
useFuseboxEntryPoint,
|
|
120
|
+
panel: query.panel,
|
|
121
|
+
},
|
|
122
|
+
);
|
|
123
|
+
let shouldUseStandaloneFuseboxShell =
|
|
124
|
+
useFuseboxEntryPoint && experiments.enableStandaloneFuseboxShell;
|
|
125
|
+
if (shouldUseStandaloneFuseboxShell) {
|
|
126
|
+
const shellPreparationResult = await shellPreparationPromise;
|
|
127
|
+
switch (shellPreparationResult.code) {
|
|
128
|
+
case "success":
|
|
129
|
+
case "not_implemented":
|
|
130
|
+
break;
|
|
131
|
+
case "platform_not_supported":
|
|
132
|
+
case "possible_corruption":
|
|
133
|
+
case "likely_offline":
|
|
134
|
+
case "unexpected_error":
|
|
135
|
+
shouldUseStandaloneFuseboxShell = false;
|
|
136
|
+
break;
|
|
137
|
+
default:
|
|
138
|
+
shellPreparationResult.code;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (shouldUseStandaloneFuseboxShell) {
|
|
142
|
+
const windowKey = (0, _crypto.createHash)("sha256")
|
|
143
|
+
.update(
|
|
144
|
+
[
|
|
145
|
+
serverBaseUrl,
|
|
146
|
+
target.webSocketDebuggerUrl,
|
|
147
|
+
target.appId,
|
|
148
|
+
].join("-"),
|
|
149
|
+
)
|
|
150
|
+
.digest("hex");
|
|
151
|
+
if (!browserLauncher.unstable_showFuseboxShell) {
|
|
152
|
+
throw new Error(
|
|
153
|
+
"Fusebox shell is not supported by the current browser launcher",
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
await browserLauncher.unstable_showFuseboxShell(
|
|
157
|
+
frontendUrl,
|
|
158
|
+
windowKey,
|
|
159
|
+
);
|
|
160
|
+
} else {
|
|
161
|
+
await browserLauncher.launchDebuggerAppWindow(frontendUrl);
|
|
162
|
+
}
|
|
163
|
+
res.writeHead(200);
|
|
164
|
+
res.end();
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
case "redirect":
|
|
168
|
+
res.writeHead(302, {
|
|
169
|
+
Location: (0, _getDevToolsFrontendUrl.default)(
|
|
170
|
+
experiments,
|
|
171
|
+
target.webSocketDebuggerUrl,
|
|
172
|
+
serverBaseUrl,
|
|
173
|
+
{
|
|
174
|
+
relative: true,
|
|
175
|
+
launchId: query.launchId,
|
|
176
|
+
telemetryInfo: query.telemetryInfo,
|
|
177
|
+
appId: target.appId,
|
|
178
|
+
useFuseboxEntryPoint,
|
|
179
|
+
},
|
|
180
|
+
),
|
|
181
|
+
});
|
|
182
|
+
res.end();
|
|
183
|
+
break;
|
|
184
|
+
default:
|
|
185
|
+
}
|
|
186
|
+
eventReporter?.logEvent({
|
|
187
|
+
type: "launch_debugger_frontend",
|
|
188
|
+
launchType,
|
|
189
|
+
status: "success",
|
|
190
|
+
appId: target.appId,
|
|
191
|
+
deviceId: target.reactNative.logicalDeviceId,
|
|
192
|
+
pageId: target.id,
|
|
193
|
+
deviceName: target.deviceName,
|
|
194
|
+
targetDescription: target.description,
|
|
195
|
+
prefersFuseboxFrontend: useFuseboxEntryPoint,
|
|
196
|
+
});
|
|
197
|
+
return;
|
|
198
|
+
} catch (e) {
|
|
199
|
+
logger?.error(
|
|
200
|
+
"Error launching DevTools: " + e.message ?? "Unknown error",
|
|
201
|
+
);
|
|
202
|
+
res.writeHead(500);
|
|
203
|
+
res.end();
|
|
204
|
+
eventReporter?.logEvent({
|
|
205
|
+
type: "launch_debugger_frontend",
|
|
206
|
+
launchType,
|
|
207
|
+
status: "error",
|
|
208
|
+
error: e,
|
|
209
|
+
prefersFuseboxFrontend: useFuseboxEntryPoint,
|
|
210
|
+
});
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
next();
|
|
215
|
+
};
|
|
216
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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 { InspectorProxyQueries } from "../inspector-proxy/InspectorProxy";
|
|
12
|
+
import type { BrowserLauncher } from "../types/BrowserLauncher";
|
|
13
|
+
import type { EventReporter } from "../types/EventReporter";
|
|
14
|
+
import type { Experiments } from "../types/Experiments";
|
|
15
|
+
import type { Logger } from "../types/Logger";
|
|
16
|
+
import type { NextHandleFunction } from "connect";
|
|
17
|
+
type Options = $ReadOnly<{
|
|
18
|
+
serverBaseUrl: string,
|
|
19
|
+
logger?: Logger,
|
|
20
|
+
browserLauncher: BrowserLauncher,
|
|
21
|
+
eventReporter?: EventReporter,
|
|
22
|
+
experiments: Experiments,
|
|
23
|
+
inspectorProxy: InspectorProxyQueries,
|
|
24
|
+
}>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Open the debugger frontend for a given CDP target.
|
|
28
|
+
*
|
|
29
|
+
* Currently supports React Native DevTools (rn_fusebox.html) and legacy Hermes
|
|
30
|
+
* (rn_inspector.html) targets.
|
|
31
|
+
*
|
|
32
|
+
* @see https://chromedevtools.github.io/devtools-protocol/
|
|
33
|
+
*/
|
|
34
|
+
declare export default function openDebuggerMiddleware(
|
|
35
|
+
$$PARAM_0$$: Options,
|
|
36
|
+
): NextHandleFunction;
|
|
@@ -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
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { DebuggerShellPreparationResult } from "@react-native/debugger-shell";
|
|
12
|
+
export type { DebuggerShellPreparationResult };
|
|
13
|
+
/**
|
|
14
|
+
* An interface for integrators to provide a custom implementation for
|
|
15
|
+
* opening URLs in a web browser.
|
|
16
|
+
*/
|
|
17
|
+
export interface BrowserLauncher {
|
|
18
|
+
/**
|
|
19
|
+
* Attempt to open a debugger frontend URL in a browser app window,
|
|
20
|
+
* optionally returning an object to control the launched browser instance.
|
|
21
|
+
* The browser used should be capable of running Chrome DevTools.
|
|
22
|
+
*
|
|
23
|
+
* The provided URL is based on serverBaseUrl, and therefore reachable from
|
|
24
|
+
* the host of dev-middleware. Implementations are responsible for rewriting
|
|
25
|
+
* this as necessary where the server is remote.
|
|
26
|
+
*/
|
|
27
|
+
launchDebuggerAppWindow: (url: string) => Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Attempt to open a debugger frontend URL in a standalone shell window
|
|
30
|
+
* designed specifically for React Native DevTools. The provided windowKey
|
|
31
|
+
* should be used to identify an existing window that can be reused instead
|
|
32
|
+
* of opening a new one.
|
|
33
|
+
*
|
|
34
|
+
* Implementations SHOULD treat an existing session with the same windowKey
|
|
35
|
+
* (as long as it's still connected and healthy) as equaivalent to a new
|
|
36
|
+
* session with the new URL, even if the launch URLs for the two sessions are
|
|
37
|
+
* not identical. Implementations SHOULD NOT unnecessarily close and reopen
|
|
38
|
+
* the connection when reusing a session. Implementations SHOULD process any
|
|
39
|
+
* changed/new parameters in the URL and update the session accordingly (e.g.
|
|
40
|
+
* to preserve telemetry data that may have changed).
|
|
41
|
+
*
|
|
42
|
+
* The provided URL is based on serverBaseUrl, and therefore reachable from
|
|
43
|
+
* the host of dev-middleware. Implementations are responsible for rewriting
|
|
44
|
+
* this as necessary where the server is remote.
|
|
45
|
+
*/
|
|
46
|
+
readonly unstable_showFuseboxShell?: (
|
|
47
|
+
url: string,
|
|
48
|
+
windowKey: string,
|
|
49
|
+
) => Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Attempt to prepare the debugger shell for use and returns a coded result
|
|
52
|
+
* that can be used to advise the user on how to proceed in case of failure.
|
|
53
|
+
*
|
|
54
|
+
* This function MAY be called multiple times or not at all. Implementers
|
|
55
|
+
* SHOULD use the opportunity to prefetch and cache any expensive resources (e.g
|
|
56
|
+
* platform-specific binaries needed in order to show the Fusebox shell). After a
|
|
57
|
+
* successful call, subsequent calls SHOULD complete quickly. The implementation
|
|
58
|
+
* SHOULD NOT return a rejecting promise in any case, and instead SHOULD report
|
|
59
|
+
* errors via the returned result object.
|
|
60
|
+
*/
|
|
61
|
+
readonly unstable_prepareFuseboxShell?: () => Promise<DebuggerShellPreparationResult>;
|
|
62
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,66 @@
|
|
|
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 { DebuggerShellPreparationResult } from "@react-native/debugger-shell";
|
|
12
|
+
|
|
13
|
+
export type { DebuggerShellPreparationResult };
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* An interface for integrators to provide a custom implementation for
|
|
17
|
+
* opening URLs in a web browser.
|
|
18
|
+
*/
|
|
19
|
+
export interface BrowserLauncher {
|
|
20
|
+
/**
|
|
21
|
+
* Attempt to open a debugger frontend URL in a browser app window,
|
|
22
|
+
* optionally returning an object to control the launched browser instance.
|
|
23
|
+
* The browser used should be capable of running Chrome DevTools.
|
|
24
|
+
*
|
|
25
|
+
* The provided URL is based on serverBaseUrl, and therefore reachable from
|
|
26
|
+
* the host of dev-middleware. Implementations are responsible for rewriting
|
|
27
|
+
* this as necessary where the server is remote.
|
|
28
|
+
*/
|
|
29
|
+
launchDebuggerAppWindow: (url: string) => Promise<void>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Attempt to open a debugger frontend URL in a standalone shell window
|
|
33
|
+
* designed specifically for React Native DevTools. The provided windowKey
|
|
34
|
+
* should be used to identify an existing window that can be reused instead
|
|
35
|
+
* of opening a new one.
|
|
36
|
+
*
|
|
37
|
+
* Implementations SHOULD treat an existing session with the same windowKey
|
|
38
|
+
* (as long as it's still connected and healthy) as equaivalent to a new
|
|
39
|
+
* session with the new URL, even if the launch URLs for the two sessions are
|
|
40
|
+
* not identical. Implementations SHOULD NOT unnecessarily close and reopen
|
|
41
|
+
* the connection when reusing a session. Implementations SHOULD process any
|
|
42
|
+
* changed/new parameters in the URL and update the session accordingly (e.g.
|
|
43
|
+
* to preserve telemetry data that may have changed).
|
|
44
|
+
*
|
|
45
|
+
* The provided URL is based on serverBaseUrl, and therefore reachable from
|
|
46
|
+
* the host of dev-middleware. Implementations are responsible for rewriting
|
|
47
|
+
* this as necessary where the server is remote.
|
|
48
|
+
*/
|
|
49
|
+
+unstable_showFuseboxShell?: (
|
|
50
|
+
url: string,
|
|
51
|
+
windowKey: string,
|
|
52
|
+
) => Promise<void>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Attempt to prepare the debugger shell for use and returns a coded result
|
|
56
|
+
* that can be used to advise the user on how to proceed in case of failure.
|
|
57
|
+
*
|
|
58
|
+
* This function MAY be called multiple times or not at all. Implementers
|
|
59
|
+
* SHOULD use the opportunity to prefetch and cache any expensive resources (e.g
|
|
60
|
+
* platform-specific binaries needed in order to show the Fusebox shell). After a
|
|
61
|
+
* successful call, subsequent calls SHOULD complete quickly. The implementation
|
|
62
|
+
* SHOULD NOT return a rejecting promise in any case, and instead SHOULD report
|
|
63
|
+
* errors via the returned result object.
|
|
64
|
+
*/
|
|
65
|
+
+unstable_prepareFuseboxShell?: () => Promise<DebuggerShellPreparationResult>;
|
|
66
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
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 { DebuggerShellPreparationResult } from "./BrowserLauncher";
|
|
12
|
+
type SuccessResult<Props extends {} | void = {}> =
|
|
13
|
+
/**
|
|
14
|
+
* > 15 | ...Props,
|
|
15
|
+
* | ^^^^^^^^ Unsupported feature: Translating "object types with spreads in the middle or at the end" is currently not supported.
|
|
16
|
+
**/
|
|
17
|
+
any;
|
|
18
|
+
type ErrorResult<ErrorT = unknown, Props extends {} | void = {}> =
|
|
19
|
+
/**
|
|
20
|
+
* > 22 | ...Props,
|
|
21
|
+
* | ^^^^^^^^ Unsupported feature: Translating "object types with spreads in the middle or at the end" is currently not supported.
|
|
22
|
+
**/
|
|
23
|
+
any;
|
|
24
|
+
type CodedErrorResult<ErrorCode extends string> = {
|
|
25
|
+
status: "coded_error";
|
|
26
|
+
errorCode: ErrorCode;
|
|
27
|
+
errorDetails?: string;
|
|
28
|
+
};
|
|
29
|
+
export type DebuggerSessionIDs = {
|
|
30
|
+
appId: string | null;
|
|
31
|
+
deviceName: string | null;
|
|
32
|
+
deviceId: string | null;
|
|
33
|
+
pageId: string | null;
|
|
34
|
+
};
|
|
35
|
+
export type ConnectionUptime = { connectionUptime: number };
|
|
36
|
+
export type ReportableEvent =
|
|
37
|
+
| /**
|
|
38
|
+
* > 46 | ...
|
|
39
|
+
* | ^^^
|
|
40
|
+
* > 47 | | SuccessResult<{
|
|
41
|
+
* | ^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
42
|
+
* > 48 | targetDescription: string,
|
|
43
|
+
* | ^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
44
|
+
* > 49 | prefersFuseboxFrontend: boolean,
|
|
45
|
+
* | ^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
46
|
+
* > 50 | ...DebuggerSessionIDs,
|
|
47
|
+
* | ^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
48
|
+
* > 51 | }>
|
|
49
|
+
* | ^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
50
|
+
* > 52 | | ErrorResult<unknown>
|
|
51
|
+
* | ^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
52
|
+
* > 53 | | CodedErrorResult<"NO_APPS_FOUND">,
|
|
53
|
+
* | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Unsupported feature: Translating "object types with spreads in the middle or at the end" is currently not supported.
|
|
54
|
+
**/
|
|
55
|
+
any
|
|
56
|
+
| /**
|
|
57
|
+
* > 57 | ...
|
|
58
|
+
* | ^^^
|
|
59
|
+
* > 58 | | SuccessResult<{
|
|
60
|
+
* | ^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
61
|
+
* > 59 | ...DebuggerSessionIDs,
|
|
62
|
+
* | ^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
63
|
+
* > 60 | frontendUserAgent: string | null,
|
|
64
|
+
* | ^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
65
|
+
* > 61 | }>
|
|
66
|
+
* | ^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
67
|
+
* > 62 | | ErrorResult<unknown, DebuggerSessionIDs>,
|
|
68
|
+
* | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Unsupported feature: Translating "object types with spreads in the middle or at the end" is currently not supported.
|
|
69
|
+
**/
|
|
70
|
+
any
|
|
71
|
+
| /**
|
|
72
|
+
* > 72 | ...DebuggerSessionIDs,
|
|
73
|
+
* | ^^^^^^^^^^^^^^^^^^^^^ Unsupported feature: Translating "object types with spreads in the middle or at the end" is currently not supported.
|
|
74
|
+
**/
|
|
75
|
+
any
|
|
76
|
+
| /**
|
|
77
|
+
* > 89 | ...DebuggerSessionIDs,
|
|
78
|
+
* | ^^^^^^^^^^^^^^^^^^^^^ Unsupported feature: Translating "object types with spreads in the middle or at the end" is currently not supported.
|
|
79
|
+
**/
|
|
80
|
+
any
|
|
81
|
+
| { type: "fusebox_console_notice" }
|
|
82
|
+
| /**
|
|
83
|
+
* > 96 | ...DebuggerSessionIDs,
|
|
84
|
+
* | ^^^^^^^^^^^^^^^^^^^^^ Unsupported feature: Translating "object types with spreads in the middle or at the end" is currently not supported.
|
|
85
|
+
**/
|
|
86
|
+
any
|
|
87
|
+
| /**
|
|
88
|
+
* > 105 | ...ConnectionUptime,
|
|
89
|
+
* | ^^^^^^^^^^^^^^^^^^^ Unsupported feature: Translating "object types with spreads in the middle or at the end" is currently not supported.
|
|
90
|
+
**/
|
|
91
|
+
any
|
|
92
|
+
| /**
|
|
93
|
+
* > 112 | ...ConnectionUptime,
|
|
94
|
+
* | ^^^^^^^^^^^^^^^^^^^ Unsupported feature: Translating "object types with spreads in the middle or at the end" is currently not supported.
|
|
95
|
+
**/
|
|
96
|
+
any
|
|
97
|
+
| /**
|
|
98
|
+
* > 119 | ...ConnectionUptime,
|
|
99
|
+
* | ^^^^^^^^^^^^^^^^^^^ Unsupported feature: Translating "object types with spreads in the middle or at the end" is currently not supported.
|
|
100
|
+
**/
|
|
101
|
+
any
|
|
102
|
+
| /**
|
|
103
|
+
* > 127 | ...ConnectionUptime,
|
|
104
|
+
* | ^^^^^^^^^^^^^^^^^^^ Unsupported feature: Translating "object types with spreads in the middle or at the end" is currently not supported.
|
|
105
|
+
**/
|
|
106
|
+
any
|
|
107
|
+
| /**
|
|
108
|
+
* > 135 | ...ConnectionUptime,
|
|
109
|
+
* | ^^^^^^^^^^^^^^^^^^^ Unsupported feature: Translating "object types with spreads in the middle or at the end" is currently not supported.
|
|
110
|
+
**/
|
|
111
|
+
any
|
|
112
|
+
| {
|
|
113
|
+
type: "fusebox_shell_preparation_attempt";
|
|
114
|
+
result: DebuggerShellPreparationResult;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* A simple interface for logging events, to be implemented by integrators of
|
|
118
|
+
* `dev-middleware`.
|
|
119
|
+
*
|
|
120
|
+
* This is an unstable API with no semver guarantees.
|
|
121
|
+
*/
|
|
122
|
+
export interface EventReporter {
|
|
123
|
+
logEvent(event: ReportableEvent): void;
|
|
124
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,151 @@
|
|
|
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 { DebuggerShellPreparationResult } from "./BrowserLauncher";
|
|
12
|
+
|
|
13
|
+
type SuccessResult<Props: { ... } | void = {}> = {
|
|
14
|
+
status: "success",
|
|
15
|
+
...Props,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type ErrorResult<ErrorT = unknown, Props: { ... } | void = {}> = {
|
|
19
|
+
status: "error",
|
|
20
|
+
error: ErrorT,
|
|
21
|
+
prefersFuseboxFrontend?: ?boolean,
|
|
22
|
+
...Props,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type CodedErrorResult<ErrorCode: string> = {
|
|
26
|
+
status: "coded_error",
|
|
27
|
+
errorCode: ErrorCode,
|
|
28
|
+
errorDetails?: string,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type DebuggerSessionIDs = {
|
|
32
|
+
appId: string | null,
|
|
33
|
+
deviceName: string | null,
|
|
34
|
+
deviceId: string | null,
|
|
35
|
+
pageId: string | null,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type ConnectionUptime = {
|
|
39
|
+
connectionUptime: number,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type ReportableEvent =
|
|
43
|
+
| {
|
|
44
|
+
type: "launch_debugger_frontend",
|
|
45
|
+
launchType: "launch" | "redirect",
|
|
46
|
+
...
|
|
47
|
+
| SuccessResult<{
|
|
48
|
+
targetDescription: string,
|
|
49
|
+
prefersFuseboxFrontend: boolean,
|
|
50
|
+
...DebuggerSessionIDs,
|
|
51
|
+
}>
|
|
52
|
+
| ErrorResult<unknown>
|
|
53
|
+
| CodedErrorResult<"NO_APPS_FOUND">,
|
|
54
|
+
}
|
|
55
|
+
| {
|
|
56
|
+
type: "connect_debugger_frontend",
|
|
57
|
+
...
|
|
58
|
+
| SuccessResult<{
|
|
59
|
+
...DebuggerSessionIDs,
|
|
60
|
+
frontendUserAgent: string | null,
|
|
61
|
+
}>
|
|
62
|
+
| ErrorResult<unknown, DebuggerSessionIDs>,
|
|
63
|
+
}
|
|
64
|
+
| {
|
|
65
|
+
type: "debugger_command",
|
|
66
|
+
protocol: "CDP",
|
|
67
|
+
// With some errors, the method might not be known
|
|
68
|
+
method: string | null,
|
|
69
|
+
requestOrigin: "proxy" | "debugger" | null,
|
|
70
|
+
responseOrigin: "proxy" | "device",
|
|
71
|
+
timeSinceStart: number | null,
|
|
72
|
+
...DebuggerSessionIDs,
|
|
73
|
+
...ConnectionUptime,
|
|
74
|
+
frontendUserAgent: string | null,
|
|
75
|
+
prefersFuseboxFrontend: boolean | null,
|
|
76
|
+
...
|
|
77
|
+
| SuccessResult<void>
|
|
78
|
+
| CodedErrorResult<
|
|
79
|
+
| "TIMED_OUT"
|
|
80
|
+
| "DEVICE_DISCONNECTED"
|
|
81
|
+
| "DEBUGGER_DISCONNECTED"
|
|
82
|
+
| "UNMATCHED_REQUEST_ID"
|
|
83
|
+
| "PROTOCOL_ERROR",
|
|
84
|
+
>,
|
|
85
|
+
}
|
|
86
|
+
| {
|
|
87
|
+
type: "profiling_target_registered",
|
|
88
|
+
status: "success",
|
|
89
|
+
...DebuggerSessionIDs,
|
|
90
|
+
}
|
|
91
|
+
| {
|
|
92
|
+
type: "fusebox_console_notice",
|
|
93
|
+
}
|
|
94
|
+
| {
|
|
95
|
+
type: "no_debug_pages_for_device",
|
|
96
|
+
...DebuggerSessionIDs,
|
|
97
|
+
}
|
|
98
|
+
| {
|
|
99
|
+
type: "proxy_error",
|
|
100
|
+
status: "error",
|
|
101
|
+
messageOrigin: "debugger" | "device",
|
|
102
|
+
message: string,
|
|
103
|
+
error: string,
|
|
104
|
+
errorStack: string,
|
|
105
|
+
...ConnectionUptime,
|
|
106
|
+
...DebuggerSessionIDs,
|
|
107
|
+
}
|
|
108
|
+
| {
|
|
109
|
+
type: "debugger_high_ping" | "device_high_ping",
|
|
110
|
+
duration: number,
|
|
111
|
+
timeSinceLastCommunication: number | null,
|
|
112
|
+
...ConnectionUptime,
|
|
113
|
+
...DebuggerSessionIDs,
|
|
114
|
+
}
|
|
115
|
+
| {
|
|
116
|
+
type: "debugger_timeout" | "device_timeout",
|
|
117
|
+
duration: number,
|
|
118
|
+
timeSinceLastCommunication: number | null,
|
|
119
|
+
...ConnectionUptime,
|
|
120
|
+
...DebuggerSessionIDs,
|
|
121
|
+
}
|
|
122
|
+
| {
|
|
123
|
+
type: "debugger_connection_closed" | "device_connection_closed",
|
|
124
|
+
code: number,
|
|
125
|
+
reason: string,
|
|
126
|
+
timeSinceLastCommunication: number | null,
|
|
127
|
+
...ConnectionUptime,
|
|
128
|
+
...DebuggerSessionIDs,
|
|
129
|
+
}
|
|
130
|
+
| {
|
|
131
|
+
type: "high_event_loop_delay",
|
|
132
|
+
eventLoopUtilization: number,
|
|
133
|
+
maxEventLoopDelayPercent: number,
|
|
134
|
+
duration: number,
|
|
135
|
+
...ConnectionUptime,
|
|
136
|
+
...DebuggerSessionIDs,
|
|
137
|
+
}
|
|
138
|
+
| {
|
|
139
|
+
type: "fusebox_shell_preparation_attempt",
|
|
140
|
+
result: DebuggerShellPreparationResult,
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* A simple interface for logging events, to be implemented by integrators of
|
|
145
|
+
* `dev-middleware`.
|
|
146
|
+
*
|
|
147
|
+
* This is an unstable API with no semver guarantees.
|
|
148
|
+
*/
|
|
149
|
+
export interface EventReporter {
|
|
150
|
+
logEvent(event: ReportableEvent): void;
|
|
151
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
export type Experiments = Readonly<{
|
|
12
|
+
/**
|
|
13
|
+
* Enables the handling of GET requests in the /open-debugger endpoint,
|
|
14
|
+
* in addition to POST requests. GET requests respond by redirecting to
|
|
15
|
+
* the debugger frontend, instead of opening it using the BrowserLauncher
|
|
16
|
+
* interface.
|
|
17
|
+
*/
|
|
18
|
+
enableOpenDebuggerRedirect: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Enables the Network panel in the debugger frontend.
|
|
21
|
+
*/
|
|
22
|
+
enableNetworkInspector: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Launch the Fusebox frontend in a standalone shell instead of a browser.
|
|
25
|
+
* When this is enabled, we will use the optional unstable_showFuseboxShell
|
|
26
|
+
* method on the BrowserLauncher, or throw an error if the method is missing.
|
|
27
|
+
*/
|
|
28
|
+
enableStandaloneFuseboxShell: boolean;
|
|
29
|
+
}>;
|
|
30
|
+
export type ExperimentsConfig = Partial<Experiments>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|