| 294 | } |
| 295 | |
| 296 | function handleMessage(event: MessageEvent) { |
| 297 | let data; |
| 298 | try { |
| 299 | if (typeof event.data === 'string') { |
| 300 | data = JSON.parse(event.data); |
| 301 | if (__DEBUG__) { |
| 302 | debug('WebSocket.onmessage', data); |
| 303 | } |
| 304 | } else { |
| 305 | throw Error(); |
| 306 | } |
| 307 | } catch (e) { |
| 308 | console.error( |
| 309 | '[React DevTools] Failed to parse JSON: ' + (event.data: any), |
| 310 | ); |
| 311 | return; |
| 312 | } |
| 313 | messageListeners.forEach(fn => { |
| 314 | try { |
| 315 | fn(data); |
| 316 | } catch (error) { |
| 317 | // jsc doesn't play so well with tracebacks that go into eval'd code, |
| 318 | // so the stack trace here will stop at the `eval()` call. Getting the |
| 319 | // message that caused the error is the best we can do for now. |
| 320 | console.log('[React DevTools] Error calling listener', data); |
| 321 | console.log('error:', error); |
| 322 | throw error; |
| 323 | } |
| 324 | }); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | type ConnectWithCustomMessagingOptions = { |