From 7f7f625cbe9513c87804b3cbcfcf0521c7bffeb7 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Fri, 22 May 2026 11:11:09 -0700 Subject: [PATCH 1/2] fix: websocket check to prevent runtime conflict on network framework --- packages/nativescript-inspector/src/index.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/nativescript-inspector/src/index.ts b/packages/nativescript-inspector/src/index.ts index 637fc487..6fce5845 100644 --- a/packages/nativescript-inspector/src/index.ts +++ b/packages/nativescript-inspector/src/index.ts @@ -891,7 +891,7 @@ function createInspectorSocket( url: string, handlers: InspectorSocketHandlers, ): InspectorSocket { - if (typeof WebSocket === "function") { + if (isBrowserWebSocket(WebSocket)) { const socket = new WebSocket(url) as any; socket.onmessage = (event: { data: string }) => { handlers.onMessage(String(event.data)); @@ -912,6 +912,23 @@ function createInspectorSocket( ); } +// NativeScript exposes Objective-C class as a global "function", and +// recent iOS SDKs ship a top-level `WebSocket` class in Network.framework. +// `typeof WebSocket === "function"` therefore matches that native class and +// `new WebSocket(url)` fails with "No initializer found that matches +// constructor invocation." Require browser-style readyState constants and a +// `send`/`close` prototype to confirm the global is a real WebSocket polyfill +// (e.g. @valor/nativescript-websockets) before using it. +function isBrowserWebSocket(ctor: any): boolean { + return ( + typeof ctor === "function" && + ctor.CONNECTING === 0 && + ctor.OPEN === 1 && + typeof ctor.prototype?.send === "function" && + typeof ctor.prototype?.close === "function" + ); +} + function createNSURLSessionWebSocket( url: string, handlers: InspectorSocketHandlers, From a6969beb87255d2830e3644557970ceda0c71387 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Fri, 22 May 2026 15:12:07 -0400 Subject: [PATCH 2/2] fix: preserve websocket fallback when global is missing --- packages/nativescript-inspector/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nativescript-inspector/src/index.ts b/packages/nativescript-inspector/src/index.ts index 6fce5845..8b8f4a45 100644 --- a/packages/nativescript-inspector/src/index.ts +++ b/packages/nativescript-inspector/src/index.ts @@ -891,7 +891,7 @@ function createInspectorSocket( url: string, handlers: InspectorSocketHandlers, ): InspectorSocket { - if (isBrowserWebSocket(WebSocket)) { + if (typeof WebSocket !== "undefined" && isBrowserWebSocket(WebSocket)) { const socket = new WebSocket(url) as any; socket.onmessage = (event: { data: string }) => { handlers.onMessage(String(event.data));