From edac6da891f84461fae1a95be114a5e4eaa87df3 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Fri, 28 Mar 2025 10:03:41 +0100 Subject: [PATCH] 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. --- src/program.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/program.ts b/src/program.ts index ed9cf50..f3fe23d 100644 --- a/src/program.ts +++ b/src/program.ts @@ -54,9 +54,9 @@ program if (options.port) { const sessions = new Map(); 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');