Skip to content

Use the forwarded address for integrated browser previews - #861

Open
Yuyang Li (5o1) wants to merge 1 commit into
microsoft:mainfrom
5o1:fix/817-forwarded-address
Open

Use the forwarded address for integrated browser previews#861
Yuyang Li (5o1) wants to merge 1 commit into
microsoft:mainfrom
5o1:fix/817-forwarded-address

Conversation

@5o1

Copy link
Copy Markdown

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

  • Resolve the HTTP URI through vscode.env.asExternalUri before opening the integrated browser.
  • Preserve paths and query parameters from the forwarded URI.
  • Add regression coverage to verify that the integrated browser receives the resolved address.

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

  • npm run compile
  • npm run lint
  • Full extension test suite: 53 passing
  • Fork GitHub Actions: Compile and Test passed

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>
Copilot AI lite review requested due to automatic review settings August 29, 2026 08:23
@5o1

Copy link
Copy Markdown
Author

Yuyang Li (Yuyang Li (@5o1)) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 by vscode.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When used with DevContainers the Forwarded Address should be used

2 participants