konami-command icon indicating copy to clipboard operation
konami-command copied to clipboard

Find a way to force referrer (-1) page on back instead of -2

Open jesus2099 opened this issue 3 years ago • 8 comments

After a quick redirect without user interaction on referrer page, the back function goes -2 instead of -1. Find a way to force go back on -1.

Maybe test on popstate event that no click on any links was done within the last second? And then how to know if it's a back or a forward action that triggered popstate? And then if back, force navigation to referrer (-1) instead of -2.


Related to:

  • #711

I reproduced History Skip problem is reproduced in both Vivaldi 5.5.2805.42 (Stable channel) (64-bit) and Edge 107.0.1418.35 (Version officielle) (64 bits) but not in Debian 10 Firefox.

Quick redirect without human interaction skips one page in history and then Back goes -2 instead of -1.

Browser History skip problem
Debian 10 Firefox No
Windows 10 Chrome 107 Yes
Windows 10 Edge 107 Yes
Windows 10 Firefox 78 No
Windows 10 Vivaldi 5 Yes

So it seems to be a Chromium specific History Skip problem. Doubled by Vivaldi specific Rewind instead of Back problem.

I really don't like it, but it seems I will have to do some browser sniffing.

jesus2099 avatar Nov 08 '22 09:11 jesus2099

Already a case.

When on entity page, you detect a quick redirect (sessionStorage == referrer) and show the MB_banner, and if history.length == 2, so it means you had a quick redirect where the intermediate search result page was not stored in history.

But in fact my problem was not to detect quick redirects. I already do it when calling my MB_banner

jesus2099 avatar Nov 08 '22 09:11 jesus2099

Maybe I should send a pushState before redirect?

jesus2099 avatar Nov 08 '22 09:11 jesus2099

OK I found the problem!! Adding a pushState fixes the issue for regular Back feature (browser button, Alt+Left, Backspace).

But in Vivaldi, the Mouse and Keyboard Browser Back buttons are triggering Rewind instead of Back!!

I think I should file a Vivaldi bug. Maybe in the meantime, there is a way to force Back when event.button == 3 (3: back, 4: forward) on mousedown? I could not cancel the Rewind action yet, despite detecting button 3 pressed, indeed.

jesus2099 avatar Nov 08 '22 10:11 jesus2099

history.pushState({}, "", location); worked well in Vivaldi but in fact nothing is needed in Debian 10 Firefox. I must check also other browsers…

jesus2099 avatar Nov 09 '22 00:11 jesus2099

I reproduced History Skip problem is reproduced in both Vivaldi 5.5.2805.42 (Stable channel) (64-bit) and Edge 107.0.1418.35 (Version officielle) (64 bits) but not in Debian 10 Firefox.

Quick redirect without human interaction skips one page in history and then Back goes -2 instead of -1.

Browser History skip problem
Debian 10 Firefox No
Windows 10 Chrome 107 Yes
Windows 10 Edge 107 Yes
Windows 10 Firefox 78 No
Windows 10 Vivaldi 5 Yes

So it seems to be a Chromium specific History Skip problem. Doubled by Vivaldi specific Rewind instead of Back problem.

I really don't like it, but it seems I will have to do some browser sniffing.

jesus2099 avatar Nov 09 '22 10:11 jesus2099

First draft:

if (navigator.userAgent.match(/\bChrome\b/)) {
	// “History Skip” problem: https://bugs.chromium.org/p/chromium/issues/detail?id=907167
	history.pushState({}, "", location);
	if (navigator.userAgent.match(/\bVivaldi\b/)) {
		// “Rewind instead of Back” problem: https://forum.vivaldi.net/topic/80807/keyboard-and-mouse-back-button-are-triggering-rewind-instead-of-back
	}
}

jesus2099 avatar Nov 09 '22 10:11 jesus2099

Ach, Vivaldi detection will be tough: Ah no, Vivaldi is no longer part of the navigator.userAgent. Trying to AJAX load vivaldi://about doesn't work either, always error 0.

And I guess there is no way to detect Rewind.

jesus2099 avatar Nov 09 '22 11:11 jesus2099

I found a secret (in Vivaldi, at least): open() breaks the Rewind (and Back) actions, unload is prevented!

I didn't find a way to sniff/detect Vivaldi, yet, maybe I will ask the user on first run.

jesus2099 avatar Nov 10 '22 00:11 jesus2099