7

In a lightning community with LockerService enabled, I am trying to instantiate a websocket using new WebSocker('wss://xyz.com'), but I am unable to because of the way WebSocket is implemented in SecureWindowHelper. It uses the SecureObject.$createFilteredMethod$ which returns a function instead of an "newable" object.

Here's the error:

Uncaught TypeError: Failed to construct 'WebSocket': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
at WrappedWebSocket (:30:55)
at new value (https://livepreview.na40.force.com/clean/s/sfsites/auraFW/javascript/yFpIOtval-qIdUy0rMdm1A/aura_proddebug.js:17508:45)
at eval (eval at evaluate (:85:21), :1:12)
at WrappedWebSocket (:30:55)
at new value (https://livepreview.na40.force.com/clean/s/sfsites/auraFW/javascript/yFpIOtval-qIdUy0rMdm1A/aura_proddebug.js:17508:45)

Also, on the Locker Service API explorer, web sockets are supported.

Any workaround?

  • Hi MAV, welcome to SFSE! No need to add thanks or your name in your posts. They just add noise and will be removed. – Adrian Larson Mar 1 '17 at 22:52
  • 1
    I've mentioned you on a post in the Partner Community regarding a conversation about this. – Fabien Taillon Mar 1 '17 at 22:58
8

WebSocket will be exposed in Summer '17 and you can instantiate a WebSocket instance like in your example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.