@react-native/dev-middleware 0.74.2 → 0.75.0-main
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/dist/createDevMiddleware.d.ts +4 -3
- package/dist/createDevMiddleware.js +4 -4
- package/dist/createDevMiddleware.js.flow +4 -3
- package/dist/index.flow.d.ts +5 -2
- package/dist/index.flow.js +0 -16
- package/dist/index.flow.js.flow +5 -3
- 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 +3 -1
- package/dist/inspector-proxy/Device.js +74 -7
- package/dist/inspector-proxy/Device.js.flow +3 -1
- package/dist/inspector-proxy/InspectorProxy.d.ts +3 -1
- package/dist/inspector-proxy/InspectorProxy.js +14 -3
- package/dist/inspector-proxy/InspectorProxy.js.flow +3 -1
- package/dist/inspector-proxy/types.d.ts +6 -0
- package/dist/inspector-proxy/types.js.flow +7 -0
- package/dist/middleware/openDebuggerMiddleware.js +4 -2
- package/dist/utils/getDevToolsFrontendUrl.d.ts +2 -1
- package/dist/utils/getDevToolsFrontendUrl.js +29 -12
- package/dist/utils/getDevToolsFrontendUrl.js.flow +4 -1
- package/package.json +16 -6
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import type { CreateCustomMessageHandlerFn } from "./inspector-proxy/CustomMessageHandler";
|
|
12
13
|
import type { BrowserLauncher } from "./types/BrowserLauncher";
|
|
13
14
|
import type { EventReporter } from "./types/EventReporter";
|
|
14
15
|
import type { ExperimentsConfig } from "./types/Experiments";
|
|
15
16
|
import type { Logger } from "./types/Logger";
|
|
16
17
|
import type { NextHandleFunction } from "connect";
|
|
17
|
-
import InspectorProxy from "./inspector-proxy/InspectorProxy";
|
|
18
18
|
type Options = Readonly<{
|
|
19
19
|
projectRoot: string;
|
|
20
20
|
/**
|
|
@@ -46,11 +46,12 @@ type Options = Readonly<{
|
|
|
46
46
|
*/
|
|
47
47
|
unstable_experiments?: ExperimentsConfig;
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
49
|
+
* Create custom handler to add support for unsupported CDP events, or debuggers.
|
|
50
|
+
* This handler is instantiated per logical device and debugger pair.
|
|
50
51
|
*
|
|
51
52
|
* This is an unstable API with no semver guarantees.
|
|
52
53
|
*/
|
|
53
|
-
|
|
54
|
+
unstable_customInspectorMessageHandler?: CreateCustomMessageHandlerFn;
|
|
54
55
|
}>;
|
|
55
56
|
type DevMiddlewareAPI = Readonly<{
|
|
56
57
|
middleware: NextHandleFunction;
|
|
@@ -43,15 +43,15 @@ function createDevMiddleware({
|
|
|
43
43
|
unstable_browserLauncher = _DefaultBrowserLauncher.default,
|
|
44
44
|
unstable_eventReporter,
|
|
45
45
|
unstable_experiments: experimentConfig = {},
|
|
46
|
-
|
|
46
|
+
unstable_customInspectorMessageHandler,
|
|
47
47
|
}) {
|
|
48
48
|
const experiments = getExperiments(experimentConfig);
|
|
49
|
-
const inspectorProxy = new (
|
|
50
|
-
_InspectorProxy.default)(
|
|
49
|
+
const inspectorProxy = new _InspectorProxy.default(
|
|
51
50
|
projectRoot,
|
|
52
51
|
serverBaseUrl,
|
|
53
52
|
unstable_eventReporter,
|
|
54
|
-
experiments
|
|
53
|
+
experiments,
|
|
54
|
+
unstable_customInspectorMessageHandler
|
|
55
55
|
);
|
|
56
56
|
const middleware = (0, _connect.default)()
|
|
57
57
|
.use(
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import type { CreateCustomMessageHandlerFn } from "./inspector-proxy/CustomMessageHandler";
|
|
12
13
|
import type { BrowserLauncher } from "./types/BrowserLauncher";
|
|
13
14
|
import type { EventReporter } from "./types/EventReporter";
|
|
14
15
|
import type { ExperimentsConfig } from "./types/Experiments";
|
|
15
16
|
import type { Logger } from "./types/Logger";
|
|
16
17
|
import type { NextHandleFunction } from "connect";
|
|
17
18
|
|
|
18
|
-
import InspectorProxy from "./inspector-proxy/InspectorProxy";
|
|
19
19
|
type Options = $ReadOnly<{
|
|
20
20
|
projectRoot: string,
|
|
21
21
|
|
|
@@ -53,11 +53,12 @@ type Options = $ReadOnly<{
|
|
|
53
53
|
unstable_experiments?: ExperimentsConfig,
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
56
|
+
* Create custom handler to add support for unsupported CDP events, or debuggers.
|
|
57
|
+
* This handler is instantiated per logical device and debugger pair.
|
|
57
58
|
*
|
|
58
59
|
* This is an unstable API with no semver guarantees.
|
|
59
60
|
*/
|
|
60
|
-
|
|
61
|
+
unstable_customInspectorMessageHandler?: CreateCustomMessageHandlerFn,
|
|
61
62
|
}>;
|
|
62
63
|
|
|
63
64
|
type DevMiddlewareAPI = $ReadOnly<{
|
package/dist/index.flow.d.ts
CHANGED
|
@@ -12,5 +12,8 @@
|
|
|
12
12
|
export { default as createDevMiddleware } from "./createDevMiddleware";
|
|
13
13
|
export type { BrowserLauncher, LaunchedBrowser } from "./types/BrowserLauncher";
|
|
14
14
|
export type { EventReporter, ReportableEvent } from "./types/EventReporter";
|
|
15
|
-
export {
|
|
16
|
-
|
|
15
|
+
export type {
|
|
16
|
+
CustomMessageHandler,
|
|
17
|
+
CustomMessageHandlerConnection,
|
|
18
|
+
CreateCustomMessageHandlerFn,
|
|
19
|
+
} from "./inspector-proxy/CustomMessageHandler";
|
package/dist/index.flow.js
CHANGED
|
@@ -9,25 +9,9 @@ Object.defineProperty(exports, "createDevMiddleware", {
|
|
|
9
9
|
return _createDevMiddleware.default;
|
|
10
10
|
},
|
|
11
11
|
});
|
|
12
|
-
Object.defineProperty(exports, "unstable_Device", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _Device.default;
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(exports, "unstable_InspectorProxy", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _InspectorProxy.default;
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
12
|
var _createDevMiddleware = _interopRequireDefault(
|
|
25
13
|
require("./createDevMiddleware")
|
|
26
14
|
);
|
|
27
|
-
var _InspectorProxy = _interopRequireDefault(
|
|
28
|
-
require("./inspector-proxy/InspectorProxy")
|
|
29
|
-
);
|
|
30
|
-
var _Device = _interopRequireDefault(require("./inspector-proxy/Device"));
|
|
31
15
|
function _interopRequireDefault(obj) {
|
|
32
16
|
return obj && obj.__esModule ? obj : { default: obj };
|
|
33
17
|
}
|
package/dist/index.flow.js.flow
CHANGED
|
@@ -13,6 +13,8 @@ export { default as createDevMiddleware } from "./createDevMiddleware";
|
|
|
13
13
|
|
|
14
14
|
export type { BrowserLauncher, LaunchedBrowser } from "./types/BrowserLauncher";
|
|
15
15
|
export type { EventReporter, ReportableEvent } from "./types/EventReporter";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
export type {
|
|
17
|
+
CustomMessageHandler,
|
|
18
|
+
CustomMessageHandlerConnection,
|
|
19
|
+
CreateCustomMessageHandlerFn,
|
|
20
|
+
} from "./inspector-proxy/CustomMessageHandler";
|
|
@@ -0,0 +1,48 @@
|
|
|
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 { JSONSerializable, Page } from "./types";
|
|
12
|
+
type ExposedDevice = Readonly<{
|
|
13
|
+
appId: string;
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
sendMessage: (message: JSONSerializable) => void;
|
|
17
|
+
}>;
|
|
18
|
+
type ExposedDebugger = Readonly<{
|
|
19
|
+
userAgent: string | null;
|
|
20
|
+
sendMessage: (message: JSONSerializable) => void;
|
|
21
|
+
}>;
|
|
22
|
+
export type CustomMessageHandlerConnection = Readonly<{
|
|
23
|
+
page: Page;
|
|
24
|
+
device: ExposedDevice;
|
|
25
|
+
debugger: ExposedDebugger;
|
|
26
|
+
}>;
|
|
27
|
+
export type CreateCustomMessageHandlerFn = (
|
|
28
|
+
connection: CustomMessageHandlerConnection
|
|
29
|
+
) => null | undefined | CustomMessageHandler;
|
|
30
|
+
/**
|
|
31
|
+
* The device message middleware allows implementers to handle unsupported CDP messages.
|
|
32
|
+
* It is instantiated per device and may contain state that is specific to that device.
|
|
33
|
+
* The middleware can also mark messages from the device or debugger as handled, which stops propagating.
|
|
34
|
+
*/
|
|
35
|
+
export interface CustomMessageHandler {
|
|
36
|
+
/**
|
|
37
|
+
* Handle a CDP message coming from the device.
|
|
38
|
+
* This is invoked before the message is sent to the debugger.
|
|
39
|
+
* When returning true, the message is considered handled and will not be sent to the debugger.
|
|
40
|
+
*/
|
|
41
|
+
handleDeviceMessage(message: JSONSerializable): true | void;
|
|
42
|
+
/**
|
|
43
|
+
* Handle a CDP message coming from the debugger.
|
|
44
|
+
* This is invoked before the message is sent to the device.
|
|
45
|
+
* When returning true, the message is considered handled and will not be sent to the device.
|
|
46
|
+
*/
|
|
47
|
+
handleDebuggerMessage(message: JSONSerializable): true | void;
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -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
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { JSONSerializable, Page } from "./types";
|
|
12
|
+
|
|
13
|
+
type ExposedDevice = $ReadOnly<{
|
|
14
|
+
appId: string,
|
|
15
|
+
id: string,
|
|
16
|
+
name: string,
|
|
17
|
+
sendMessage: (message: JSONSerializable) => void,
|
|
18
|
+
}>;
|
|
19
|
+
|
|
20
|
+
type ExposedDebugger = $ReadOnly<{
|
|
21
|
+
userAgent: string | null,
|
|
22
|
+
sendMessage: (message: JSONSerializable) => void,
|
|
23
|
+
}>;
|
|
24
|
+
|
|
25
|
+
export type CustomMessageHandlerConnection = $ReadOnly<{
|
|
26
|
+
page: Page,
|
|
27
|
+
device: ExposedDevice,
|
|
28
|
+
debugger: ExposedDebugger,
|
|
29
|
+
}>;
|
|
30
|
+
|
|
31
|
+
export type CreateCustomMessageHandlerFn = (
|
|
32
|
+
connection: CustomMessageHandlerConnection
|
|
33
|
+
) => ?CustomMessageHandler;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The device message middleware allows implementers to handle unsupported CDP messages.
|
|
37
|
+
* It is instantiated per device and may contain state that is specific to that device.
|
|
38
|
+
* The middleware can also mark messages from the device or debugger as handled, which stops propagating.
|
|
39
|
+
*/
|
|
40
|
+
export interface CustomMessageHandler {
|
|
41
|
+
/**
|
|
42
|
+
* Handle a CDP message coming from the device.
|
|
43
|
+
* This is invoked before the message is sent to the debugger.
|
|
44
|
+
* When returning true, the message is considered handled and will not be sent to the debugger.
|
|
45
|
+
*/
|
|
46
|
+
handleDeviceMessage(message: JSONSerializable): true | void;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Handle a CDP message coming from the debugger.
|
|
50
|
+
* This is invoked before the message is sent to the device.
|
|
51
|
+
* When returning true, the message is considered handled and will not be sent to the device.
|
|
52
|
+
*/
|
|
53
|
+
handleDebuggerMessage(message: JSONSerializable): true | void;
|
|
54
|
+
}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import type { EventReporter } from "../types/EventReporter";
|
|
13
|
+
import type { CreateCustomMessageHandlerFn } from "./CustomMessageHandler";
|
|
13
14
|
import type { Page } from "./types";
|
|
14
15
|
import WS from "ws";
|
|
15
16
|
/**
|
|
@@ -23,7 +24,8 @@ declare class Device {
|
|
|
23
24
|
app: string,
|
|
24
25
|
socket: WS,
|
|
25
26
|
projectRoot: string,
|
|
26
|
-
eventReporter: null | undefined | EventReporter
|
|
27
|
+
eventReporter: null | undefined | EventReporter,
|
|
28
|
+
createMessageMiddleware: null | undefined | CreateCustomMessageHandlerFn
|
|
27
29
|
);
|
|
28
30
|
getName(): string;
|
|
29
31
|
getApp(): string;
|
|
@@ -117,7 +117,18 @@ class Device {
|
|
|
117
117
|
#projectRoot;
|
|
118
118
|
#deviceEventReporter;
|
|
119
119
|
#pagesPollingIntervalId;
|
|
120
|
-
|
|
120
|
+
|
|
121
|
+
// The device message middleware factory function allowing implementers to handle unsupported CDP messages.
|
|
122
|
+
#createCustomMessageHandler;
|
|
123
|
+
constructor(
|
|
124
|
+
id,
|
|
125
|
+
name,
|
|
126
|
+
app,
|
|
127
|
+
socket,
|
|
128
|
+
projectRoot,
|
|
129
|
+
eventReporter,
|
|
130
|
+
createMessageMiddleware
|
|
131
|
+
) {
|
|
121
132
|
this.#id = id;
|
|
122
133
|
this.#name = name;
|
|
123
134
|
this.#app = app;
|
|
@@ -131,6 +142,7 @@ class Device {
|
|
|
131
142
|
appId: app,
|
|
132
143
|
})
|
|
133
144
|
: null;
|
|
145
|
+
this.#createCustomMessageHandler = createMessageMiddleware;
|
|
134
146
|
|
|
135
147
|
// $FlowFixMe[incompatible-call]
|
|
136
148
|
this.#deviceSocket.on("message", (message) => {
|
|
@@ -210,6 +222,7 @@ class Device {
|
|
|
210
222
|
prependedFilePrefix: false,
|
|
211
223
|
pageId,
|
|
212
224
|
userAgent: metadata.userAgent,
|
|
225
|
+
customHandler: null,
|
|
213
226
|
};
|
|
214
227
|
|
|
215
228
|
// TODO(moti): Handle null case explicitly, e.g. refuse to connect to
|
|
@@ -217,6 +230,48 @@ class Device {
|
|
|
217
230
|
const page = this.#pages.get(pageId);
|
|
218
231
|
this.#debuggerConnection = debuggerInfo;
|
|
219
232
|
debug(`Got new debugger connection for page ${pageId} of ${this.#name}`);
|
|
233
|
+
if (page && this.#debuggerConnection && this.#createCustomMessageHandler) {
|
|
234
|
+
this.#debuggerConnection.customHandler = this.#createCustomMessageHandler(
|
|
235
|
+
{
|
|
236
|
+
page,
|
|
237
|
+
debugger: {
|
|
238
|
+
userAgent: debuggerInfo.userAgent,
|
|
239
|
+
sendMessage: (message) => {
|
|
240
|
+
try {
|
|
241
|
+
const payload = JSON.stringify(message);
|
|
242
|
+
debug("(Debugger) <- (Proxy) (Device): " + payload);
|
|
243
|
+
socket.send(payload);
|
|
244
|
+
} catch {}
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
device: {
|
|
248
|
+
appId: this.#app,
|
|
249
|
+
id: this.#id,
|
|
250
|
+
name: this.#name,
|
|
251
|
+
sendMessage: (message) => {
|
|
252
|
+
try {
|
|
253
|
+
const payload = JSON.stringify({
|
|
254
|
+
event: "wrappedEvent",
|
|
255
|
+
payload: {
|
|
256
|
+
pageId: this.#mapToDevicePageId(pageId),
|
|
257
|
+
wrappedEvent: JSON.stringify(message),
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
debug("(Debugger) -> (Proxy) (Device): " + payload);
|
|
261
|
+
this.#deviceSocket.send(payload);
|
|
262
|
+
} catch {}
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
}
|
|
266
|
+
);
|
|
267
|
+
if (this.#debuggerConnection.customHandler) {
|
|
268
|
+
debug("Created new custom message handler for debugger connection");
|
|
269
|
+
} else {
|
|
270
|
+
debug(
|
|
271
|
+
"Skipping new custom message handler for debugger connection, factory function returned null"
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
220
275
|
this.#sendMessageToDevice({
|
|
221
276
|
event: "connect",
|
|
222
277
|
payload: {
|
|
@@ -233,6 +288,13 @@ class Device {
|
|
|
233
288
|
frontendUserAgent: metadata.userAgent,
|
|
234
289
|
});
|
|
235
290
|
let processedReq = debuggerRequest;
|
|
291
|
+
if (
|
|
292
|
+
this.#debuggerConnection?.customHandler?.handleDebuggerMessage(
|
|
293
|
+
debuggerRequest
|
|
294
|
+
) === true
|
|
295
|
+
) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
236
298
|
if (!page || !this.#pageHasCapability(page, "nativeSourceCodeFetching")) {
|
|
237
299
|
processedReq = this.#interceptClientMessageForSourceFetching(
|
|
238
300
|
debuggerRequest,
|
|
@@ -412,12 +474,21 @@ class Device {
|
|
|
412
474
|
frontendUserAgent: this.#debuggerConnection?.userAgent ?? null,
|
|
413
475
|
});
|
|
414
476
|
}
|
|
415
|
-
|
|
477
|
+
const debuggerConnection = this.#debuggerConnection;
|
|
478
|
+
if (debuggerConnection != null) {
|
|
479
|
+
if (
|
|
480
|
+
debuggerConnection.customHandler?.handleDeviceMessage(
|
|
481
|
+
parsedPayload
|
|
482
|
+
) === true
|
|
483
|
+
) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
|
|
416
487
|
// Wrapping just to make flow happy :)
|
|
417
488
|
// $FlowFixMe[unused-promise]
|
|
418
489
|
this.#processMessageFromDeviceLegacy(
|
|
419
490
|
parsedPayload,
|
|
420
|
-
|
|
491
|
+
debuggerConnection,
|
|
421
492
|
pageId
|
|
422
493
|
).then(() => {
|
|
423
494
|
const messageToSend = JSON.stringify(parsedPayload);
|
|
@@ -755,10 +826,6 @@ class Device {
|
|
|
755
826
|
// Fetch text, raising an exception if the text could not be fetched,
|
|
756
827
|
// or is too large.
|
|
757
828
|
async #fetchText(url) {
|
|
758
|
-
if (!["localhost", "127.0.0.1"].includes(url.hostname)) {
|
|
759
|
-
throw new Error("remote fetches not permitted");
|
|
760
|
-
}
|
|
761
|
-
|
|
762
829
|
// $FlowFixMe[incompatible-call] Suppress arvr node-fetch flow error
|
|
763
830
|
const response = await (0, _nodeFetch.default)(url);
|
|
764
831
|
if (!response.ok) {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import type { EventReporter } from "../types/EventReporter";
|
|
13
|
+
import type { CreateCustomMessageHandlerFn } from "./CustomMessageHandler";
|
|
13
14
|
import type { Page } from "./types";
|
|
14
15
|
|
|
15
16
|
import WS from "ws";
|
|
@@ -25,7 +26,8 @@ declare export default class Device {
|
|
|
25
26
|
app: string,
|
|
26
27
|
socket: WS,
|
|
27
28
|
projectRoot: string,
|
|
28
|
-
eventReporter: ?EventReporter
|
|
29
|
+
eventReporter: ?EventReporter,
|
|
30
|
+
createMessageMiddleware: ?CreateCustomMessageHandlerFn
|
|
29
31
|
): void;
|
|
30
32
|
getName(): string;
|
|
31
33
|
getApp(): string;
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
import type { EventReporter } from "../types/EventReporter";
|
|
13
13
|
import type { Experiments } from "../types/Experiments";
|
|
14
|
+
import type { CreateCustomMessageHandlerFn } from "./CustomMessageHandler";
|
|
14
15
|
import type { PageDescription } from "./types";
|
|
15
16
|
import type { IncomingMessage, ServerResponse } from "http";
|
|
16
17
|
import WS from "ws";
|
|
@@ -25,7 +26,8 @@ declare class InspectorProxy implements InspectorProxyQueries {
|
|
|
25
26
|
projectRoot: string,
|
|
26
27
|
serverBaseUrl: string,
|
|
27
28
|
eventReporter: null | undefined | EventReporter,
|
|
28
|
-
experiments: Experiments
|
|
29
|
+
experiments: Experiments,
|
|
30
|
+
customMessageHandler: null | undefined | CreateCustomMessageHandlerFn
|
|
29
31
|
);
|
|
30
32
|
getPageDescriptions(): Array<PageDescription>;
|
|
31
33
|
processRequest(
|
|
@@ -46,12 +46,22 @@ class InspectorProxy {
|
|
|
46
46
|
#deviceCounter = 0;
|
|
47
47
|
#eventReporter;
|
|
48
48
|
#experiments;
|
|
49
|
-
|
|
49
|
+
|
|
50
|
+
// custom message handler factory allowing implementers to handle unsupported CDP messages.
|
|
51
|
+
#customMessageHandler;
|
|
52
|
+
constructor(
|
|
53
|
+
projectRoot,
|
|
54
|
+
serverBaseUrl,
|
|
55
|
+
eventReporter,
|
|
56
|
+
experiments,
|
|
57
|
+
customMessageHandler
|
|
58
|
+
) {
|
|
50
59
|
this.#projectRoot = projectRoot;
|
|
51
60
|
this.#serverBaseUrl = serverBaseUrl;
|
|
52
61
|
this.#devices = new Map();
|
|
53
62
|
this.#eventReporter = eventReporter;
|
|
54
63
|
this.#experiments = experiments;
|
|
64
|
+
this.#customMessageHandler = customMessageHandler;
|
|
55
65
|
}
|
|
56
66
|
getPageDescriptions() {
|
|
57
67
|
// Build list of pages from all devices.
|
|
@@ -163,7 +173,8 @@ class InspectorProxy {
|
|
|
163
173
|
appName,
|
|
164
174
|
socket,
|
|
165
175
|
this.#projectRoot,
|
|
166
|
-
this.#eventReporter
|
|
176
|
+
this.#eventReporter,
|
|
177
|
+
this.#customMessageHandler
|
|
167
178
|
);
|
|
168
179
|
if (oldDevice) {
|
|
169
180
|
oldDevice.handleDuplicateDeviceConnection(newDevice);
|
|
@@ -211,7 +222,7 @@ class InspectorProxy {
|
|
|
211
222
|
throw new Error("Unknown device with ID " + deviceId);
|
|
212
223
|
}
|
|
213
224
|
device.handleDebuggerConnection(socket, pageId, {
|
|
214
|
-
userAgent: req.headers["user-agent"] ?? null,
|
|
225
|
+
userAgent: req.headers["user-agent"] ?? query.userAgent ?? null,
|
|
215
226
|
});
|
|
216
227
|
} catch (e) {
|
|
217
228
|
console.error(e);
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
import type { EventReporter } from "../types/EventReporter";
|
|
13
13
|
import type { Experiments } from "../types/Experiments";
|
|
14
|
+
import type { CreateCustomMessageHandlerFn } from "./CustomMessageHandler";
|
|
14
15
|
import type { PageDescription } from "./types";
|
|
15
16
|
import type { IncomingMessage, ServerResponse } from "http";
|
|
16
17
|
|
|
@@ -28,7 +29,8 @@ declare export default class InspectorProxy implements InspectorProxyQueries {
|
|
|
28
29
|
projectRoot: string,
|
|
29
30
|
serverBaseUrl: string,
|
|
30
31
|
eventReporter: ?EventReporter,
|
|
31
|
-
experiments: Experiments
|
|
32
|
+
experiments: Experiments,
|
|
33
|
+
customMessageHandler: ?CreateCustomMessageHandlerFn
|
|
32
34
|
): void;
|
|
33
35
|
getPageDescriptions(): Array<PageDescription>;
|
|
34
36
|
processRequest(
|
|
@@ -29,6 +29,12 @@ export type TargetCapabilityFlags = Readonly<{
|
|
|
29
29
|
* In the proxy, this disables source fetching emulation and host rewrites.
|
|
30
30
|
*/
|
|
31
31
|
nativeSourceCodeFetching?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* The target supports native network inspection.
|
|
34
|
+
*
|
|
35
|
+
* In the proxy, this disables intercepting and storing network requests.
|
|
36
|
+
*/
|
|
37
|
+
nativeNetworkInspection?: boolean;
|
|
32
38
|
}>;
|
|
33
39
|
export type PageFromDevice = Readonly<{
|
|
34
40
|
id: string;
|
|
@@ -30,6 +30,13 @@ export type TargetCapabilityFlags = $ReadOnly<{
|
|
|
30
30
|
* In the proxy, this disables source fetching emulation and host rewrites.
|
|
31
31
|
*/
|
|
32
32
|
nativeSourceCodeFetching?: boolean,
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The target supports native network inspection.
|
|
36
|
+
*
|
|
37
|
+
* In the proxy, this disables intercepting and storing network requests.
|
|
38
|
+
*/
|
|
39
|
+
nativeNetworkInspection?: boolean,
|
|
33
40
|
}>;
|
|
34
41
|
|
|
35
42
|
// Page information received from the device. New page is created for
|
|
@@ -113,8 +113,10 @@ function openDebuggerMiddleware({
|
|
|
113
113
|
Location: (0, _getDevToolsFrontendUrl.default)(
|
|
114
114
|
experiments,
|
|
115
115
|
target.webSocketDebuggerUrl,
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
serverBaseUrl,
|
|
117
|
+
{
|
|
118
|
+
relative: true,
|
|
119
|
+
}
|
|
118
120
|
),
|
|
119
121
|
});
|
|
120
122
|
res.end();
|
|
@@ -16,6 +16,7 @@ import type { Experiments } from "../types/Experiments";
|
|
|
16
16
|
declare function getDevToolsFrontendUrl(
|
|
17
17
|
experiments: Experiments,
|
|
18
18
|
webSocketDebuggerUrl: string,
|
|
19
|
-
devServerUrl: string
|
|
19
|
+
devServerUrl: string,
|
|
20
|
+
options?: Readonly<{ relative?: boolean }>
|
|
20
21
|
): string;
|
|
21
22
|
export default getDevToolsFrontendUrl;
|
|
@@ -21,23 +21,40 @@ exports.default = getDevToolsFrontendUrl;
|
|
|
21
21
|
function getDevToolsFrontendUrl(
|
|
22
22
|
experiments,
|
|
23
23
|
webSocketDebuggerUrl,
|
|
24
|
-
devServerUrl
|
|
24
|
+
devServerUrl,
|
|
25
|
+
options
|
|
25
26
|
) {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const wsParam = getWsParam({
|
|
28
|
+
webSocketDebuggerUrl,
|
|
29
|
+
devServerUrl,
|
|
30
|
+
});
|
|
31
|
+
const appUrl =
|
|
32
|
+
(options?.relative === true ? "" : devServerUrl) +
|
|
33
|
+
"/debugger-frontend/rn_inspector.html";
|
|
31
34
|
const searchParams = new URLSearchParams([
|
|
32
|
-
[
|
|
35
|
+
[wsParam.key, wsParam.value],
|
|
33
36
|
["sources.hide_add_folder", "true"],
|
|
34
37
|
]);
|
|
35
38
|
if (experiments.enableNetworkInspector) {
|
|
36
39
|
searchParams.append("unstable_enableNetworkPanel", "true");
|
|
37
40
|
}
|
|
38
|
-
return (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
);
|
|
41
|
+
return appUrl + "?" + searchParams.toString();
|
|
42
|
+
}
|
|
43
|
+
function getWsParam({ webSocketDebuggerUrl, devServerUrl }) {
|
|
44
|
+
const wsUrl = new URL(webSocketDebuggerUrl);
|
|
45
|
+
const serverHost = new URL(devServerUrl).host;
|
|
46
|
+
let value;
|
|
47
|
+
if (wsUrl.host === serverHost) {
|
|
48
|
+
// Use a path-absolute (host-relative) URL
|
|
49
|
+
// Depends on https://github.com/facebookexperimental/rn-chrome-devtools-frontend/pull/4
|
|
50
|
+
value = wsUrl.pathname + wsUrl.search + wsUrl.hash;
|
|
51
|
+
} else {
|
|
52
|
+
// Standard URL format accepted by the DevTools frontend
|
|
53
|
+
value = wsUrl.host + wsUrl.pathname + wsUrl.search + wsUrl.hash;
|
|
54
|
+
}
|
|
55
|
+
const key = wsUrl.protocol.slice(0, -1);
|
|
56
|
+
return {
|
|
57
|
+
key,
|
|
58
|
+
value,
|
|
59
|
+
};
|
|
43
60
|
}
|
|
@@ -17,5 +17,8 @@ import type { Experiments } from "../types/Experiments";
|
|
|
17
17
|
declare export default function getDevToolsFrontendUrl(
|
|
18
18
|
experiments: Experiments,
|
|
19
19
|
webSocketDebuggerUrl: string,
|
|
20
|
-
devServerUrl: string
|
|
20
|
+
devServerUrl: string,
|
|
21
|
+
options?: $ReadOnly<{
|
|
22
|
+
relative?: boolean,
|
|
23
|
+
}>
|
|
21
24
|
): string;
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native/dev-middleware",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.75.0-main",
|
|
4
4
|
"description": "Dev server middleware for React Native",
|
|
5
|
-
"keywords": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react-native",
|
|
7
|
+
"tools"
|
|
8
|
+
],
|
|
6
9
|
"homepage": "https://github.com/facebook/react-native/tree/HEAD/packages/dev-middleware#readme",
|
|
7
10
|
"bugs": "https://github.com/facebook/react-native/issues",
|
|
8
11
|
"repository": {
|
|
@@ -11,11 +14,16 @@
|
|
|
11
14
|
"directory": "packages/dev-middleware"
|
|
12
15
|
},
|
|
13
16
|
"license": "MIT",
|
|
14
|
-
"exports": {
|
|
15
|
-
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./dist/index.js",
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
16
24
|
"dependencies": {
|
|
17
25
|
"@isaacs/ttlcache": "^1.4.1",
|
|
18
|
-
"@react-native/debugger-frontend": "0.
|
|
26
|
+
"@react-native/debugger-frontend": "0.75.0-main",
|
|
19
27
|
"@rnx-kit/chromium-edge-launcher": "^1.0.0",
|
|
20
28
|
"chrome-launcher": "^0.15.2",
|
|
21
29
|
"connect": "^3.6.5",
|
|
@@ -28,7 +36,9 @@
|
|
|
28
36
|
"temp-dir": "^2.0.0",
|
|
29
37
|
"ws": "^6.2.2"
|
|
30
38
|
},
|
|
31
|
-
"engines": {
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=18"
|
|
41
|
+
},
|
|
32
42
|
"devDependencies": {
|
|
33
43
|
"data-uri-to-buffer": "^6.0.1",
|
|
34
44
|
"undici": "^5.27.2",
|