Search code examples
javascriptevalmicrosoft-edge

EDGE: eval('window.localStorage')


eval('window.localStorage') is throwing the SCRIPT16389: Unspecified error. In Chrome works as expected - the same result as console.log(window.localStorage). Is there any reason why Microsoft EDGE browser is suppressing this?

EDIT:

Why eval?

It's used in the application as an "export" feature. Current state among with source code is zipped and base64 encoded. This zip is attached to HTML, this HTML file includes all resources so the app can be "reconstructed" offline. During the reconstruction process I'm calling the eval on unzipped, base64 decoded sources.

Same behavior occurred in Safari, here is a screenshot from IE Edge https://i.sstatic.net/jrnAx.png

noticed on Microsoft Edge 41.16299.248.0


Solution

  • window.localStorage combined with file:// protocol is the problem, not the eval itself

    workaround:

    if (typeof window.localStorage !== 'undefined')` {
        // ...
    }
    

    more info: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8816771/