Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0314· OpenAIAi2 WildChat-4.8M (AI2)

I am making a request to a SSE stream, using a website. In the response, it starts with…

  1. User

    I am making a request to a SSE stream, using a website. In the response, it starts with : joining queue

    data: {"id":"chatcmpl-7Fa82BsbBoDIy6DfrZWy4sOxJU1ZG","object":"chat.completion.chunk - the : joining queue messes up the pre-existing request interpreter in my browser. Is it possible to create an userscript to automatically hide the ": joining queue" before chrome processes it?

  2. Assistant

    Yes, you can create a userscript to modify the server-sent events (SSE) stream and filter out the "joining queue" message. Here's an example of how to create a userscript to do this using JavaScript:

    1. Install a userscript manager extension for your browser like Tampermonkey.
    2. Open the Tampermonkey dashboard and create a new script.
    3. Paste the following code into the editor and modify the @match value to match the website you are using:
    // ==UserScript==
    // @name         Filter SSE Stream
    // @namespace    http://tampermonkey.net/
    // @version      1.0
    // @description  Filters out the 'joining queue' message from a SSE stream
    // @author       You
    // @match        https://your-website.com/*
    // @grant        none
    // ==/UserScript==
    
    (function() {
        'use strict';
    
        // Replace the EventSource with a custom version that filters events
        window.EventSource = class CustomEventSource extends EventSource {
            constructor(url, options) {
                super(url, options);
                this.addFilteredEventListener();
            }
    
            addFilteredEventListener() {
                const originalAddEventListener = this.addEventListener;
    
                this.addEventListener = (type, callback, ...args) => {
                    const filteredCallback = (event) => {
                        const message = event.data ? event.data.trim() : '';
                        if (message.includes(': joining queue')) {
                            console.log('Filtered message:', message);
                        } else {
                            callback(event);
                        }
                    };
                    originalAddEventListener.call(this, type, filteredCallback, ...args);
                };
            }
        };
    
    })();
    
    1. Save the script and reload the website in your browser. The userscript should automatically run and hide the ": joining queue" messages in the SSE stream.

    Please note that this solution assumes the website uses the native EventSource API for SSE. If the website uses a different library or method, you will need to adapt the script accordingly.