Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

fix for the DOMException SecurityError on Twine 2 games using the Harlowe (1/2) syntax format

A topic by Efi created Jul 07, 2020 Views: 625
Viewing posts 1 to 1
(+1)

​Recently I noticed the iframes for some Twine 2 games like the ones I have were not loading unless the iframe was removed by loading only the contents.

This is caused by a security exception on the iframe. The code inside doesn’t respect the Same Domain Policy. So I investigated…

First I noticed the obvious console error stating a SecurityError, then tried to track it down to the source. Took a while, but turns out there’s a call to localStorage on the Harlowe syntax in versions 1 and 2, but it was fixed for version 3, which made it harder to track.

Ultimately, in your Twine projects, you will have a minified version of the Harlowe syntax (or whichever you use) which means it doesn’t map exactly to the source symbols, but thankfully the localStorage is a window property that has a fixed name wherever it exists.

To fix this error, you can either edit your minified format.js file, then rebuild/export your twine game (I use Twee2, if you’re wondering), or you can directly edit your index.html if that’s what contains your game. That’s how I upload it to Itch, since it will just show the twine on the game page. You probably did the same if you have this issue.

What you have to change is very simple. You search for localStorage and you will find something like

y=!!localStorage&&function()...

That’s the right place, though the letter on the left may vary. just cut the !!localStorage&& part and paste it after the next return on its right so it looks something like

try {return !!localStorage&&localStorage.

Make sure that space is after the return. That’s all! Now you can recompile if you edited the format.js or just reupload the modified index.html (after re-zipping it) and you’re good!!

It’s a small oversight with an easy fix, but it seems it went unnoticed for long, or at least I couldn’t find anything on it during my search.

I hope this small guide is simple enough that everyone can follow it without breaking anything else and that I am right that this is the only issue with that syntax. Let me know if you try this! <3