From c62be78d99939e33b5b2bc3cee5be2a030f0640b Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Tue, 12 Mar 2024 09:39:00 -0700 Subject: [PATCH] feature(dev-middleware): use `userAgent` query parameter as fallback when header is unset (#43364) Summary: At Expo, we use [Expo Tools](https://github.com/expo/vscode-expo/blob/main/src/expoDebuggers.ts) to connect the [built-in vscode-js-debug](https://github.com/microsoft/vscode-js-debug) to Hermes. Since there are a few differences in vscode vs chrome devtools, we need to enable a couple of modifications through the [`customMessageHandler` API](https://github.com/facebook/react-native/pull/43291). Unfortunately, vscode itself doesn't set the `user-agent` header when connecting to the inspector proxy. Becuase of that, we'd need a fallback to "manually" mark the debugger as being vscode ([we use this query parameter here](https://github.com/expo/vscode-expo/blob/main/src/expoDebuggers.ts#L208)). This PR supports setting the `user-agent` through `?userAgent=` when the header is not set. ## Changelog: [GENERAL] [ADDED] - Fallback to query parameter based `user-agent` when header is unset Pull Request resolved: https://github.com/facebook/react-native/pull/43364 Test Plan: - Install [Expo Tools](https://marketplace.visualstudio.com/items?itemName=expo.vscode-expo-tools) - Start Metro with this change. - Connect a device. - Run the vscode command `"Expo: Debug Expo app ..."` - Debugger should connect, and have it's user-agent marked as: `vscode/1.87.0 vscode-expo-tools/1.3.0` Reviewed By: huntie Differential Revision: D54804556 Pulled By: motiz88 fbshipit-source-id: 1ff558ba5350811ad042d08a713438e046759feb --- packages/dev-middleware/src/inspector-proxy/InspectorProxy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js b/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js index 0f4146d5e01884..532bf06c0b457c 100644 --- a/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js +++ b/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js @@ -258,7 +258,7 @@ export default class InspectorProxy implements InspectorProxyQueries { } device.handleDebuggerConnection(socket, pageId, { - userAgent: req.headers['user-agent'] ?? null, + userAgent: req.headers['user-agent'] ?? query.userAgent ?? null, }); } catch (e) { console.error(e);