-
Notifications
You must be signed in to change notification settings - Fork 29.9k
[devtools] Ensure Chrome DevTools workspace can connect with proxy rewrites #86289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[devtools] Ensure Chrome DevTools workspace can connect with proxy rewrites #86289
Conversation
|
|
||
| if (opts.dev && isChromeDevtoolsWorkspaceUrl(parsedUrl)) { | ||
| // We want the original pathname without any basePath or proxy rewrites. | ||
| if (opts.dev && isChromeDevtoolsWorkspaceUrl(req.url)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (opts.dev && isChromeDevtoolsWorkspaceUrl(req.url)) { | |
| if (opts.dev && isChromeDevtoolsWorkspaceUrl((req.url || '').split('?')[0])) { |
The req.url parameter can include query strings (e.g., ?.foo=bar), but the isChromeDevtoolsWorkspaceUrl function performs a strict equality check that will fail if query parameters are present.
View Details
Analysis
Chrome DevTools URL detection fails with query parameters
What fails: isChromeDevtoolsWorkspaceUrl() function in packages/next/src/server/lib/router-server.ts line 579 performs a strict equality check, but receives the full req.url which includes query parameters. Requests to /.well-known/appspecific/com.chrome.devtools.json?foo=bar fail to match and Chrome DevTools workspace is not recognized.
How to reproduce:
// Current behavior at line 579:
if (opts.dev && isChromeDevtoolsWorkspaceUrl(req.url)) { // req.url may include query stringSend HTTP request: GET /.well-known/appspecific/com.chrome.devtools.json?foo=bar
Result: Request is not recognized as Chrome DevTools workspace endpoint. Handler returns 404 instead of Chrome DevTools JSON response.
Expected: Should recognize the endpoint and return Chrome DevTools workspace configuration, matching requests with or without query parameters (same behavior as line 193 of the same file which explicitly splits req.url on ?).
Reference: The same file at line 193 explicitly handles this case: const urlParts = (req.url || '').split('?', 1) because Node.js req.url includes query strings. The Node.js HTTP documentation confirms req.url includes the query string.
Fix applied: Extract pathname before passing to function at line 579: isChromeDevtoolsWorkspaceUrl((req.url || '').split('?')[0])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chrome doesn't include query params in its requests
Failing test suitesCommit: 15e692f | About building and testing Next.js
Expand output● chrome-devtools-workspace proxy › should be able to connect to Chrome DevTools in dev |
15e692f to
ccefd9e
Compare
Follow-up to #80260
We used to match against the
parsedUrlwhich is the URL after proxy applied. For our default implementation, rewrites won't matter so we use the original request URL instead. Otherwise we'd serve 404s.This doesn't affect custom implementations of the
/.well-known/appspecific/com.chrome.devtools.jsonroute. Only Next.js' default implementation.