Skip to content

extension api: port mapping for websockets not working #74085

@SimonSiefke

Description

@SimonSiefke

The new port mapping API doesn't work for websockets, e.g.
http://localhost:3000 is mapped to http://localhost:4000
ws://localhost:3000 is not mapped to ws://localhost:4000

Steps to Reproduce:

// extension.js
const vscode = require('vscode')
const { createServer } = require('http')

createServer((req, res) => {
  res.end('ok')
}).listen(4000)

const html = `<!doctype html>
	<html>
    <h1>hello world</h1>
		<script>
			fetch('http://localhost:3000')
			new WebSocket('ws://localhost:3000')
		</script>
	</html>
	`

exports.activate = () => {
  const webViewPanel = vscode.window.createWebviewPanel(
    'my-extension',
    'my-extension',
    {
      viewColumn: 1,
    },
    {
      enableScripts: true,
      portMapping: [
        {
          extensionHostPort: 4000,
          webviewPort: 3000,
        },
      ],
    }
  )
  webViewPanel.webview.html = html
}

screenshot

Metadata

Metadata

Assignees

Labels

feature-requestRequest for new features or functionalityhtmlHTML support issueswebviewWebview issues

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions