Skip to content

Getting something went wrong error while calling cometd library in chrome  #1997

@itssonamsinha

Description

@itssonamsinha

CometD version(s) : 8

Java version & vendor (use: java -version) : openjdk 11.0.15

Description
"Getting something went wrong error" while hitting cometd library in chrome whereas on clearing the cookies it is working fine.
We are observing there are no issue with firefox.

How to reproduce?
We have created an apex component which configures , listens and suscribes to the event. We have written another visual force page to call this component and render the result on our page.

<apex:component>
    <script>
        $(document).ready(function(){
            $.cometd.configure({
                url: window.location.protocol + '//' + window.location.hostname + '/cometd/49.0',
                requestHeaders: { Authorization: 'OAuth {!$Api.Session_ID}' },
                appendMessageTypeToURL: false
            });

            // Define a variable to track handshake state
            var isHandshaken = false;

            // Add a handshake listener
            // $.cometd.on('handshake', function(message) {
            //     isHandshaken = true;
            // });

            // to avoid illegal state, handshake done only once on page load
            if (!isHandshaken) {
                console.log('before handshake');
            
                // disable websockets
                $.cometd.websocketEnabled = false; 
                    
                $.cometd.handshake();
                
                console.log('before addListener');  
                
                $.cometd.addListener('/meta/handshake', function(message) {
                    if (message.successful) {
                        console.log('Handshake Successful: ' + JSON.stringify(message));                 
                        subscription = $.cometd.subscribe('/event/xxx', 
                                            function(response) {
                                               
                                                if (subscriptionResponse.Status === "Success" ) {
                                                    $.cometd.unsubscribe(subscription);
                                                } else if (subscriptionResponse.Status === "Failure") {
                                                    $.cometd.unsubscribe(subscription);
                                                }
                                            },
                                            function(subscribeResponse) {
                                                console.log('Response on subscribing to event->xxx : ' + JSON.stringify(subscribeResponse));
                                                eventSubscriptionSuccessful = subscribeResponse?.successful;
                                            }
                            );
                    } 
                });
            }
        })
    </script>
</apex:component>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions