46

Whenever I click on Stack-Snippets®'s Run code snippet in any post, a new entry is made in my tab's history (the one for the back and forward buttons, accessible through window.history in js).
I like to keep my tab's history clean, and I expect to see only new tab's history entries for when I really change from page A to page B. But here, I stay on the same page, only an ajax POST request* is made to load the content of an iframe, so I can't make a sense to this behavior.

// you can try it here, even if the color of the button is different

When writing answers from inside the Stack-Snippets® it can grow really big, to an extent that the back button of my browser becomes completely useless, and sometimes requiring me to go inside the whole history to come back to the page I was in before.

A lot of red circles

I didn't searched a lot, but I couldn't find a clear call to pushState, so I'll guess it's not made on purpose and tag this question as .


* Digging a little bit in snippet-javascript.en.js, I can now see that the request is actually not made through AJAX, but through an HTML <form>, which will explain the why it happens, remains the why it has been made like this, does SO really support IE<7?


| Browser + Version |     OS       | Repro | Notes  
| ----------------- | ------------ | ----- | -----      
| Firefox           |              |       |       
|          <50 ~ 57 | OsX Sierra   | true  |       
|                55 | Arch Linux   | true  |       
|                55 | Android 7    | true  |
|            55.0.3 | Debian       | true  |       
|            55.0.3 | Windows 10   | true  |
| Chrome            |              |       |       
|           60 ~ 63 | OsX Sierra   | true  |
|                60 | Windows 10   | both  |//Some can't repro, some can only on second and further clicks, some can directly
|                60 | Android 7    | true  |//Not recorded in app's "back" menu, but in device back button...
| Safari            |              |       |       
|            10.1.2 | OsX Sierra   | true  |//Records for long "back" button press (equivalent to right click in other browsers), but not for single 'back' button press
| Internet Explorer |              |       |
|           11.1715 | Windows 10   | true  |//Only on second and further clicks

Note: while writing this question, I noted that here on META, this history is eventually cleared after some time. This doesn't seem to happen on main, but would mean that the issue is at least known, so maybe I should reformulate as a so that this clearing is also implemented on main, and that the timeout is lowered (e.g to 0).

17
  • 56
    +14 for red free hand circles ...
    – rene
    Commented Sep 16, 2017 at 9:25
  • 38
    @rene +1 for counting these.
    – Kaiido
    Commented Sep 16, 2017 at 9:49
  • 5
    I don't get any history entries in my browser, except when clicking "full page". So be sure to document the browser you use. Commented Sep 16, 2017 at 10:16
  • 1
    @HansPassant ah interesting... Since I could repro in all my browsers, I thought it was general. Could also be interesting to know your specs then.
    – Kaiido
    Commented Sep 16, 2017 at 10:52
  • 6
    Interestingly, I'm not getting this behavior on the first click on "run snippet", but subsequent clicks add items to the history. BTW snippets aren't just AJAX calls, the snippet output is put in an iframe for isolation/security. So I guess the fist time an iframe loads it doesn't count as a navigation entry. Commented Sep 16, 2017 at 11:41
  • @LucasTrzesniewski as I said I didn't looked too much in what really happens, but I don't see why the iframe would make an other call, it could directly be populated by the ajax response, and I absolutely don't see why an iframe would change the history states anyway. (AFK so can't really dig into it, and there seems to be an automated mechanism here on meta, so I think devs know what happens)
    – Kaiido
    Commented Sep 16, 2017 at 12:00
  • 3
    @Kaiido It's been a long time since I last did web development, but I recall that navigating in an iframe would impact the history (the back button would go back to the previous page in the iframe). I've used this trick back when pushState didn't exist and IE didn't care about changing # hashes in the URL. Maybe snippets exhibit this behavior since they have to reset the iframe document in order to update the snippet - perhaps if they replaced the iframe with a fresh one this could solve the issue - but I don't know, I haven't read the SO JS code, so hopefully an SO dev will comment. Commented Sep 16, 2017 at 13:41
  • I am unable to reproduce on Windows 10 using Chrome 60.0.3112.113.
    – user4639281
    Commented Sep 16, 2017 at 16:21
  • Reproduced in Windows 10 Chrome 60.0.3112.113, does not happen on first snippet run but any future clicks cause new history entries.
    – SeinopSys
    Commented Sep 16, 2017 at 17:36
  • Me was able to reproduce it just now on (macOS 10.12.6, Firefox 55.0.3)
    – Michael
    Commented Sep 16, 2017 at 17:36
  • I can reproduce, nominally the same platform as TinyGiant: Windows 10, 60.0.3112.113 (Official Build) (64-bit) (cohort: Stable) both on my usual cocktail of extensions as well as with all extensions disabled
    – Jimmy
    Commented Sep 16, 2017 at 17:38
  • I see this too on FF 55.0.3 32-bit with extensions disabled. I noticed though that when you click out all the history, hiding the results will wipe it out. I guess it's because the iframe. Commented Sep 16, 2017 at 18:02
  • Repro on FF 55.0.3 64-bit on Arch Linux.
    – Majora320
    Commented Sep 16, 2017 at 18:03
  • I knew that time would come where more people voted for the red circles than people actually did vote...
    – Kaiido
    Commented Sep 17, 2017 at 15:40
  • bug : the red hand circles are not matching with each other
    – Sagar V
    Commented Sep 18, 2017 at 12:24

0

You must log in to answer this question.

Browse other questions tagged .