Return from Invoke-UDJavascript

Product: PowerShell Universal
Version: 5.0.15

I checked out post #5321 to try and find out a solution here, but basically I’m trying to pull the current theme variant (dark || light). The only place I can find this stored is localstorage, so logically my next step is to do this:

$CurrentMode = Invoke-UDJavascript -Javascript "window.localStorage.theme"

However, $CurrentMode evaluates to "" by the time it gets back to me. Testing in the browser console shows that running eval("window.localStorage.theme") (pulled from the documentation here) does return 'dark' or 'light' accordingly; is there a way I can access this?

The exact use case is when defining custom components at a function level, I’m trying to vary the colors based on the theme/mode/variant/whatever determines dark or light. Basically.

This seems like a variable we should just have defined automatically. Feel free to open an issue for that.

I’m not at the computer right now, but I wonder if the JavaScript isn’t running quite at the right time or something. If you run the same code in something like a button press does it work?

Sorry for the delay - yes, it does return when using a button! For some reason I didn’t test that; it’s been quite a month. I’ll mark this as resolved and open an issue!