Here's a way to fix the problem you're having when returning to the non-temporary chat:
You currently have:
window.location.href = 'https://chatgpt.com';
You can replace it with:
const root = new URL('/', url.origin);
history.replaceState(null, '', root.toString());
This will stop the full page reload and go to the root on the same origin to avoid any cross-origin navigation.
Also, a small bug in your code, although it shouldn't affect things too much with your current code:
if (e.key !== 'Shift'&& e.location===KeyboardEvent.DOM_KEY_LOCATION_LEFT) return;
...this line allows almost any keystroke to get past it. The only ones it will stop are Left Alt, Left Ctrl and Left Meta/Windows. But your isShiftHeld flag does block all those other keystrokes, so the bug doesn't really harm anything.
To write that line properly, change it to:
if (e.key !== 'Shift' || e.location !== KeyboardEvent.DOM_KEY_LOCATION_LEFT) return;
Here's a way to fix the problem you're having when returning to the non-temporary chat:
You currently have:
You can replace it with:
This will stop the full page reload and go to the root on the same origin to avoid any cross-origin navigation.
Also, a small bug in your code, although it shouldn't affect things too much with your current code:
...this line allows almost any keystroke to get past it. The only ones it will stop are
Left Alt
,Left Ctrl
andLeft Meta/Windows
. But yourisShiftHeld
flag does block all those other keystrokes, so the bug doesn't really harm anything.To write that line properly, change it to:
or if you want it even simpler, write: