MV Urgent problem in HTML5 with DreamX Options plugin

Hi all, finally finished my work to add an accessibility setting for photo-sensitive users to my game, but I've ran into a snag.

I'm using the DreamX options to add an Options Menu item, an ON/OFF flag, which controls a switch in the game that, in many places, is used as part of an IF conditional statement to enable/disable various effects to make the game more comfortable for photosensitive users.

It works fine for the Windows version of the game, but at the instant I try to change the option in the HTML5 version of the game, I get this:

1607981303471.png


I would ask in DreamX's thread, but they've been dormant for several years now, so I thought I'd ask here.

This is a really crushing disappointment because I've been working on this all week, and this was literally the final step of the process.

Does anyone know if there's an easy way to resolve this?
In Firefox I see a "SecurityError" in this situation. Not sure if it's the same problem, but for me, enabling local storage access for the site (via the purple shield to the left of the address bar) and refreshing the page seems to fix it.

Local storage and cookies are different but tend to be grouped under the same permissions bracket. Exactly how to adjust your browser's settings will vary depending on which browser you're using.
In Firefox I see a "SecurityError" in this situation. Not sure if it's the same problem, but for me, enabling local storage access for the site (via the purple shield to the left of the address bar) and refreshing the page seems to fix it.

Local storage and cookies are different but tend to be grouped under the same permissions bracket. Exactly how to adjust your browser's settings will vary depending on which browser you're using.

Hmmm; in that case I might just rework the game so that the web version is simpler, and maybe just the "screen flashes" option (which doesn't save to local storage) just controls ALL of the visual adjustments for photosensitivty.

EDIT: Oh, SERIOUSLY?!

It turns out that a similar error appears if you change ANY OPTION on the options screen, even default ones. This presumably is a core issue with how RPGMaker MV stores its options settings, meaning that it's impossible to have these sorts of switches in the HTML5 version while not having the user do some janky thing where they have to change browser options.

This is unacceptable. I just can't believe that sort of problem exists! I've already put up with how it's impossible for users to save, and as my Chapter 1 is only 30 minutes long, that just had to do - but this is terrible.

OK, that's it. I admit defeat. Unfortunately, the accessibility settings are going to have to be confined to the downloadable version of the game, and not available in the web-based version (and I appreciate the options screen "works" in a specific, limited fashion, but it doesn't work correctly the way Newgrounds, Itch and GameJolt are set up, they're the primary platforms, so that means it doesn't work from my perspective).
Note that local storage is the web version of files on disk. Avoiding local storage entirely means no [local] data will persist from one play session to the next, including saves and options. 😅

If you haven't already, I recommend testing to see if allowing cookies does fix the issue before you dive into such a radical rework of your project!

(There's a way to get the browser to ask for permission via scripting, but I haven't experimented with that, personally. 😴)
Note that local storage is the web version of files on disk. Avoiding local storage entirely means no [local] data will persist from one play session to the next, including saves and options. 😅

It seems it isn't even just that. I was always aware that information wasn't persistent; but it seems even if the user...

1) starts the game in the browser
2) opens "options" from the title screen
3) changes anything
4) hits <esc>

... they get the above error, because naturally the options can't write to disc. I had assumed the options wouldn't save but they would persist for the present session at least!

The cookies thing is a good point, but sadly, I'm not going to do that. Firstly, it's running on itchio, a site for which I have certainly enabled cookies in the past (I've used it for years) and secondly, even if there is a workaround, the whole point of the HTML5 version is so that the user can play, immediately, quickly and easily at a single click, without any hassle. Anything that gets in the way of that is something of a no-go; even if it works, it won't really do the job.
Yes, the error occurs when the browser attempts to access forbidden storage. Besides storing data server-side (cloud saves), online security doesn't really leave a lot of options open for storing persistent data.

If you're up to experiment, you could try saving this line of code as a .js file and importing as a plugin:
JavaScript:
if (document.requestStorageAccess) document.requestStorageAccess();
Yes, the error occurs when the browser attempts to access forbidden storage. Besides storing data server-side (cloud saves), online security doesn't really leave a lot of options open for storing persistent data.

If you're up to experiment, you could try saving this line of code as a .js file and importing as a plugin:
JavaScript:
if (document.requestStorageAccess) document.requestStorageAccess();
I'm about to head to bed, but before I try that - what is that snippet supposed to do?
I'm about to head to bed, but before I try that - what is that snippet supposed to do?
Me too~ 😴

I think it'll ask for the browser to allow local storage access. The if part is just to avoid an error if the browser doesn't support requestStorageAccess.

By the looks of the technical documentation I linked in an earlier post, that request might involve getting the user's input ("site wants access to local storage"), or it might happen automatically; depends how the browser handles it. It should be harmless but I totally understand if you'd rather wait for someone more knowledgable to chime in first. 👋
Yes, the error occurs when the browser attempts to access forbidden storage. Besides storing data server-side (cloud saves), online security doesn't really leave a lot of options open for storing persistent data.

If you're up to experiment, you could try saving this line of code as a .js file and importing as a plugin:
JavaScript:
if (document.requestStorageAccess) document.requestStorageAccess();

I see - will that get the thing to "fail silently" if it can't save?

So it would work for the session, just not save between sessions?
I see - will that get the thing to "fail silently" if it can't save?
It should ask the browser for access when the game boots up. If access is granted, I'd expect saving to work correctly with no errors; if access is not granted or the method is not supported, then the error will still occur, since nothing will have changed.
So it would work for the session, just not save between sessions?
Looks like it, yes, possibly with a limit on session duration (24 hours?).

If you wanted to avoid saving altogether when it's not supported, maybe try the attached plugin instead (still untested/experimental, full code below for reference).
Spoiler: Plugin code
JavaScript:
/*:
 * @plugindesc Experimental local storage etiquette.
 * @author Caethyril
 * @help Requests local storage access when appropriate.
 * Suppresses/paraphrases troublesome errors.
 */

(alias => {
'use strict';
    const deniedMsg = 'Your browser settings do not allow saving to local storage.';
    let doOnce = false;        // if true, error has been shown this play session

    const showDenied = function() {
        if (!doOnce) {          // max once per session
            doOnce = true;
            alert(deniedMsg);   // alert user
        }
    };

    // Adds error handling for saving config (game options).
    // By default in web mode, the game will crash here if local storage is forbidden.
    ConfigManager.save = function() {
        const a = alias.bind(this);                 // original method in this context
        if (StorageManager.isLocalMode()) a();      // original behaviour in local mode
        else {
            try {
                a();                                // try original behaviour
            } catch (e1) {
                try {                               // error, try asking for permission
                    document.requestStorageAccess()
                    .then(a())
                    .catch(() => showDenied());     // if denied, inform user
                } catch (e2) {                      // welp, that failed
                    console.error(e1);              // log errors to console ("silent")
                    console.error(e2);
                }
            }
        }
    };
})(ConfigManager.save);
If you (or anyone else reading this!) test this out in a web-hosted game, I'd be interested to hear whether or not it helps~ 🙏
Hey @caethyril, unfortunately your earlier snippet didn't help (the result was exactly the same).

I'm going to try this second one shortly.
Thanks so much @caethyril! That plugin has fixed it:


Everything seems to work now. The options are all reset to defaults when you refresh the page, and saving still doesn't work - but that's fine for my purposes; users who want a more flexible experience can play the downloaded version.

I'll keep testing just so I can be sure there are no not-immediately-obvious bugs.
Interesting. I'm guessing it's related to my browser settings, but it seems to save OK for me (options and save games) without having to explicitly enable access. Good to hear it removes the errors for you, though!

Also: that game looks amazing, imma download it and check it out~ 🙏
Interesting. I'm guessing it's related to my browser settings, but it seems to save OK for me (options and save games) without having to explicitly enable access. Good to hear it removes the errors for you, though!

Also: that game looks amazing, imma download it and check it out~ 🙏

Ah, the downloadable versions don't have these settings yet (I'm gonna fix that later), that being said, the only difference are these accessibility settings.

Original thread: https://forums.rpgmakerweb.com/threads/urgent-problem-in-html5-with-dreamx-options-plugin.130996/