From b8c4e198d15ddba142bc39cba3eb7598db12da08 Mon Sep 17 00:00:00 2001 From: Hercules Smith <30369360+ProfHercules@users.noreply.github.com> Date: Tue, 28 Jan 2025 09:40:30 +0200 Subject: [PATCH] Fix bad WebSocket URL in CrawlWatcher (#1053) * fix: bad websocket url in crawl watcher Fixed CrawlWatcher creating WebSocket using standard http url from base app. * Use regex to improve url replacement --- apps/js-sdk/firecrawl/src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/js-sdk/firecrawl/src/index.ts b/apps/js-sdk/firecrawl/src/index.ts index 3deeb909..58f77211 100644 --- a/apps/js-sdk/firecrawl/src/index.ts +++ b/apps/js-sdk/firecrawl/src/index.ts @@ -1298,7 +1298,9 @@ export class CrawlWatcher extends TypedEventTarget { constructor(id: string, app: FirecrawlApp) { super(); this.id = id; - this.ws = new WebSocket(`${app.apiUrl}/v1/crawl/${id}`, app.apiKey); + // replace `http` with `ws` (`http://` -> `ws://` and `https://` -> `wss://`) + const wsUrl = app.apiUrl.replace(/^http/, "ws"); + this.ws = new WebSocket(`${wsUrl}/v1/crawl/${id}`, app.apiKey); this.status = "scraping"; this.data = [];