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?