project ·

WebGPT Lag Remedy

Sole developer

A JavaScript Tampermonkey userscript that windows long ChatGPT conversations using height-matched placeholders and observer-based restoration.

Skills & tools

  • JavaScript
  • DOM manipulation
  • MutationObserver
  • IntersectionObserver
  • WeakMap
  • Tampermonkey
WebGPT Lag Remedy JavaScript code calculates the active message window, replaces distant messages with placeholders, and restores them through IntersectionObserver.

Overview

WebGPT Lag Remedy is a Tampermonkey userscript designed to reduce rendering overhead in long ChatGPT conversations. It keeps messages near the viewport mounted while replacing distant messages with lightweight placeholders. Earlier messages are restored as the user scrolls back toward them.

My contribution

I built the implementation that connects message windowing, scroll-position preservation, media handling, and a diagnostic badge in one JavaScript userscript. Its settings control the target message count, surrounding buffer, update delay, and distance at which older messages begin returning to the page.

Technical work

The script identifies conversation messages through their data-message-id attributes and measures their positions using getBoundingClientRect(). Messages outside the active window are replaced with placeholders sized to their original height, preserving their space in the conversation.

Two WeakMap collections connect each placeholder to its original message element. An IntersectionObserver restores messages before they reach the viewport, while a MutationObserver schedules updates when the conversation changes. Scroll and resize events use the same delayed update function.

Detached messages also have image and video sources temporarily cleared. Their saved sources are restored when the messages return.

Challenges

Removing older messages without preserving their height would shift the conversation and disrupt navigation. Height-matched placeholders retain the page’s structure, while a surrounding message buffer and early restoration distance help keep content available during scrolling.

ChatGPT also updates its page dynamically. Observing DOM changes allows the script to revisit the active window as messages are added, while retaining the original message elements preserves their existing content.

Results and current state

The public repository contains the userscript and installation instructions for Tampermonkey. A diagnostic badge displays message, placeholder, and DOM-element counts so the windowing behavior can be inspected while navigating a conversation.

The project demonstrates browser-side DOM manipulation, observer-based event handling, and an approach to reducing the amount of conversation content mounted at once.

Links & resources

SiteNaviAI

Chat is currently unavailable. You can still explore the portfolio.