From ab81c16b6507000139d1af52c622e320629750ec Mon Sep 17 00:00:00 2001 From: 116-7 <1167@local> Date: Tue, 17 Oct 2023 10:08:05 -0700 Subject: [PATCH] =?UTF-8?q?Refactors=20InspectorProxy=20to=20compare=20pat?= =?UTF-8?q?hname=20portion=20of=20url=20passed=20in=E2=80=A6=20(#41005)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: … request to local pathname comparator variables to fix issue with other rightward elements of url such as query or fragment entering the comparison and causing 404 errors for key debugging routes. A change in Chromium appended the query "?for_tabs" to the /json/list request made by Chrome DevTools to find remote debugger targets. The current comparison in InspectorProxy.js compares the entire node IncomingMessage url field to the local pathname constants. The issue arises as url can also contain the query and fragment portions so the original comparison of "/json/list" === "/json/list" which resolved as true would become "/json/list?for_tabs" === "/json/list" and evaluate to false ultimately resulting in a 404 for the request. In summary, all these changes/issues caused remote debugging of Hermes code in React Native apps to become unavailable, greatly impacting developer experience. ## Changelog: [GENERAL] [FIXED] JS Debugging: Fix inspector-proxy to allow for DevTools requests with query strings Pull Request resolved: https://github.com/facebook/react-native/pull/41005 Reviewed By: NickGerleman Differential Revision: D50342265 Pulled By: robhogan fbshipit-source-id: a65f2908f0bea9fc15e1e3e4e6d31a3b9598e81f --- .../dev-middleware/src/inspector-proxy/InspectorProxy.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js b/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js index be4fe3e13a..96d224a7cb 100644 --- a/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js +++ b/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js @@ -94,12 +94,13 @@ export default class InspectorProxy implements InspectorProxyQueries { response: ServerResponse, next: (?Error) => mixed, ) { + const pathname = url.parse(request.url).pathname; if ( - request.url === PAGES_LIST_JSON_URL || - request.url === PAGES_LIST_JSON_URL_2 + pathname === PAGES_LIST_JSON_URL || + pathname === PAGES_LIST_JSON_URL_2 ) { this._sendJsonResponse(response, this.getPageDescriptions()); - } else if (request.url === PAGES_LIST_JSON_VERSION_URL) { + } else if (pathname === PAGES_LIST_JSON_VERSION_URL) { this._sendJsonResponse(response, { Browser: 'Mobile JavaScript', 'Protocol-Version': '1.1',