Skip to content

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

@PSCourtney

Description

@PSCourtney

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions