0

I'm trying to set up a Lightning component to listen for Platform Events and the above error occurs while CometD is handshaking.

What's interesting is I've tried the code in a Dev org and did not run into this issue (the error occurs in a sandbox).

This issue was mentioned in a comment here, but no solution was given.

The setup looks like this and is called after the CometD static resource has loaded (adapted from here)

doInit: function(component, event, helper) {
    var action = component.get("c.getSessionId");
    action.setCallback(this, function(response) {

        var sessionId = response.getReturnValue();
        var cometd = new window.org.cometd.CometD();
        cometd.configure({
            url: window.location.protocol + '//' + window.location.hostname + '/cometd/41.0/',
            requestHeaders: { Authorization: 'OAuth ' + sessionId},
            appendMessageTypeToURL : false
        });
        cometd.websocketEnabled = false;

        cometd.handshake($A.getCallback(function(status) {
            if (status.successful) {
                var eventName = component.get("v.channel");
                cometd.subscribe(eventName, $A.getCallback(function(message) {
                        var messageEvent = component.getEvent("onMessage");
                        messageEvent.setParam("payload", message.data.payload);
                        messageEvent.fire();
                    }
                ));
            } else {
                console.log(status.failure);
            }
        }));

    });
    $A.enqueueAction(action);
}

And here is the error stack trace (redacted)

TypeError: Cannot add property context, object is not extensible
    at F.LongPollingTransport._self.xhrSend (https://xxx/cometd/cometd.js:564:25)
    at F.LongPollingTransport._self.transportSend (https://xxx/cometd/cometd.js:596:36)
    at F._transportSend (https://xxx/cometd/cometd.js:336:18)
    at F._queueSend (https://xxx/cometd/cometd.js:376:32)
    at F.RequestTransport._self.send (https://xxx/cometd/cometd.js:487:28)
    at _send (https://xxx/cometd/cometd.js:1657:24)
    at _handshake (https://xxx/cometd/cometd.js:1875:13)
    at CometD.handshake (https://xxx/cometd/cometd.js:2553:13)
    at Object.<anonymous> (https://xxx/apex/components/c/streaming.js:24:20)
    at n (https://xxx/auraFW/javascript/xxx/aura_prod.js:824:138)

Has anyone else run into this issue and found a solution?

  • 1
    This comment explains the error and possible workarounds. – sbordet Nov 3 '17 at 9:10
  • How did I miss that? That fixed it, thanks! – kacrouse Nov 3 '17 at 16:18
1

As sbordet said in the comment above, there was a solution (or at least workaround) given in the question I linked to, that I somehow missed.

Here is the workaround provided by Grekker in that thread:

The cometd library on GitHub since version 3.1.2 added a line of code that Salesforce doesn't like, my guess is because it changes XHR and LockerService is forcing XHR to not change. Here's the offending commit: github.com/cometd/cometd/commit/… To get around this use version 3.1.1, or reverse/comment out the additions in this commit.

Switching my CometD version to 3.1.1 fixed the issue.

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.