Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error trying to read local storage when browser has it turned off. #123

Open
PSCourtney opened this issue Feb 16, 2023 · 0 comments
Open

Comments

@PSCourtney
Copy link

PSCourtney commented Feb 16, 2023

When trying to read LocalStorage from Window. Access is denied.

Error:

Failed to read the 'localStorage' property from 'Window': Access is denied for this document. Error: Failed to read the 'localStorage' property from 'Window': Access is denied for this document. at /_framework/blazor.server.js:1:563 at Array.forEach () at i.findFunction (/_framework/blazor.server.js:1:465) at E (/_framework/blazor.server.js:1:2606) at /_framework/blazor.server.js:1:3494 at new Promise () at kt.beginInvokeJSFromDotNet (/_framework/blazor.server.js:1:3475) at /_framework/blazor.server.js:1:72001 at Array.forEach () at kt._invokeClientMethod (/_framework/blazor.server.js:1:71987) Microsoft.JSInterop.JSException Void Throw() at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
at Majorsoft.Blazor.Extensions.BrowserStorage.StorageServiceBase.GetItemAsync[T](String key)
at Majorsoft.Blazor.Components.GdprConsent.GdprConsentService.GetGdprConsentDataAsync()

Possible fix?:

var storageSupported = false;

try
{ 
    storageSupported = (window.localStorage && true);
}
catch (e) {}

if (storageSupported) 
{ 
    // your code
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant