Use the forwarded address for integrated browser previews - #861
Use the forwarded address for integrated browser previews#861Yuyang Li (5o1) wants to merge 1 commit into
Conversation
When Live Preview runs in a Dev Container, its server can listen on remote port 3000 while VS Code forwards it to a different local port because local port 3000 is unavailable. The issue is reproduced by opening the integrated preview after that mapping is created: the preview still navigates to 127.0.0.1:3000 instead of the Forwarded Address. Resolve the HTTP URI through vscode.env.asExternalUri before opening the integrated browser, preserve any path and query parameters from the forwarded URI, and add regression coverage for the resolved address. The integrated preview now follows VS Code’s current port mapping, so remote port 3000 opens through local port 3001 or any other Forwarded Address while retaining the Live Preview browser reuse marker. Co-authored-by: Codex <codex@openai.com>
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Pull request overview
This PR fixes Dev Container / port-forwarding scenarios where the integrated (workbench) browser preview previously opened the non-forwarded http://{connection.host}:{connection.httpPort} address, causing failures when VS Code forwards the remote port to a different local port.
Changes:
- Resolve the preview base URI via
connection.resolveExternalHTTPUri()(backed byvscode.env.asExternalUri) before opening the integrated browser. - Rebuild the integrated-browser URL by joining the forwarded base URI with the requested path and ensuring the Live Preview reuse marker is present in the query string.
- Add a regression test asserting the integrated browser receives the forwarded address (including preserved base path/query).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/editorPreview/previewManager.ts | Uses resolveExternalHTTPUri() and vscode.Uri.joinPath to open the integrated browser with the forwarded address while retaining/augmenting query params. |
| src/test/suite/preview.test.ts | Adds a regression test verifying the integrated browser command is invoked with the resolved forwarded URL. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Fixes #817
Problem
When Live Preview runs in a Dev Container, the server may listen on remote port 3000 while VS Code forwards it to a different local port. If local port 3000 is unavailable, VS Code may forward the server to localhost:3001, but the integrated preview previously continued to open localhost:3000 and failed to connect.
Changes
Expected behavior
The integrated browser now follows the Forwarded Address selected by VS Code. For example, when remote port 3000 is forwarded to local port 3001, the preview opens through localhost:3001 while retaining the Live Preview browser reuse marker.
Validation