fix: tired URL parsing bug (#70)

Closes https://github.com/microsoft/playwright-mcp/issues/67

When `req.headers.host` is defined, the URL parsing breaks because
there's no protocol.
This commit is contained in:
Simon Knott 2025-03-28 10:03:41 +01:00 committed by GitHub
parent 74a8f95ca3
commit edac6da891
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -54,9 +54,9 @@ program
if (options.port) {
const sessions = new Map<string, SSEServerTransport>();
const httpServer = http.createServer(async (req, res) => {
const url = new URL(req.url ?? '', `http://${req.headers.host}`);
if (req.method === 'POST') {
const host = req.headers.host ?? 'http://unknown';
const sessionId = new URL(host + req.url!).searchParams.get('sessionId');
const sessionId = url.searchParams.get('sessionId');
if (!sessionId) {
res.statusCode = 400;
res.end('Missing sessionId');