Fix ChatGPT not loading in multiple tabs (due to Performance.measure Error)

Fixes ChatGPT failing to load when you open several tabs. Some sessions crash because of bad `Performance.measure` calls used for analytics. This script safely overrides `Performance.measure`, skipping invalid calls so the site loads normally while leaving your experience unchanged. Fully commented; questions and feedback welcome.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

You will need to install an extension such as Tampermonkey to install this script.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Fix ChatGPT not loading in multiple tabs (due to Performance.measure Error)
// @namespace    12centuries
// @version      0.1
// @description  Fixes ChatGPT failing to load when you open several tabs. Some sessions crash because of bad `Performance.measure` calls used for analytics. This script safely overrides `Performance.measure`, skipping invalid calls so the site loads normally while leaving your experience unchanged. Fully commented; questions and feedback welcome.
// @author       12centuries
// @license      MIT
// @match        *://chatgpt.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Override the Performance.measure function
    if (window.performance && typeof window.performance.measure === 'function') {
        const originalMeasure = window.performance.measure;
        window.performance.measure = function(measureName, startMark, endMark) {
            try {
                // Check if the 'end' attribute (endMark) is negative
                // or any other condition that causes the specific TypeError
                if (typeof endMark === 'number' && endMark < 0) {
                    console.warn(`Userscript intercepted problematic Performance.measure call for: ${measureName}. End mark was negative.`);
                    return; // Skip the problematic call
                }
                // Call the original function if the values are valid
                originalMeasure.call(this, measureName, startMark, endMark);
            } catch (e) {
                if (e instanceof TypeError && e.message.includes('Given attribute end cannot be negative')) {
                    console.warn(`Userscript caught and suppressed TypeError in Performance.measure for: ${measureName}`);
                    // Suppress the error and continue
                } else {
                    throw e; // Re-throw other errors
                }
            }
        };
    }
})();