Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Twine2/Sugarcube2 - re-enable browser's back button?

I guess the title says it all. I made a very short and very simple game using Twine2/Sugarcube2. It would make more sense to me if users could just return to previous pages using the browser's back button. (There aren't any variables that I'm worried about getting messed up.)

Is this feasible? Maybe I'm crazy, but I think I had to alter the code to disable the back button in earlier versions prior to the current Sugarcube?



  • I'm pretty sure there's a back button on the sidebar for sugarcube 2. At least there's one in the latest version. And not just back, if you go back you can go forward too. It basically cycles through the history of viewed passages. Is that what you want?
  • @andrew9495 Correct. In SugarCube v2, the story history controls—Backward button, Jumpto dialog button, and Forward button—are at the top of the UI bar. The buttons are contextual and will not be shown if disabled.

    @Gridelin I'm afraid not. The ability to use the browser's backward and forward navigation buttons comes from the HTML5 history API. The API is not used at all within SugarCube v2 because the Chromium developers decided to completely break the HTML5 history API for locally opened files—see below for details.

    SugarCube v1 attempts to, poorly, work around the issue—"poorly" because there's no better way to do it.

    SugarCube v2 drops the HTML5 history API entirely to avoid the issue. Helpfully, as a side effect, this made the internal history API much simpler and easier to reason about—v1's history API is a labyrinthine mess—and enabled many new features, like the Jumpto dialog.

    The HTML5 history API breakage went live around September 2015 and generated quite a bit of buzz in many Twine circles at the time. A quote of mine from elsewhere about the issue:
    At the moment, I'm assuming this issue is related to the following change: Chrome 45 Beta: New ES2015 features, service worker improvements, and media controls
    Other updates in this release
    • To reduce the risk of certain types of attack, the 'self' source defined by Content Security Policy now excludes blob and filesystem URLs.
    Basically, locally opened files (the aforementioned filesystem URLs; i.e. those opened via file://) are no longer allowed to use the HTML5 history APIs (among, possibly, other things) in Chrome/Chromium (and quite possibly any Blink-based browser once they sync to v45).


    At the moment, I have no idea how I'm going to work around this insanity.
  • edited January 2017
    Ah, that clears it up. Thank you both. (And @andrew9495, I guess I forgot about those buttons, as my sidebar was completely disabled. Perhaps there's a way to keep them while removing the sidebar using Javascript...)

    It shouldn't impact me too much, but just thought I'd ask if enabling the browser back buttons was possible. Interesting about the HTML5 history API too... Thnx again.
  • The best way to remove the UI bar: (Twine 2: goes in Story JavaScript; Twine 1: goes in a script-tagged passage)

    The way to add your own buttons for the history controls:
    <<link "Backward">><<script>>Engine.backward()<</script>><</link>>
    <<link "Forward">><<script>>Engine.forward()<</script>><</link>>
    <<if Story.lookup('tags', 'bookmark').length gt 0>>
    \<<link "Jumpto">><<script>>UI.jumpto()<</script>><</link>>
Sign In or Register to comment.