BytexDigital / BytexDigital.Blazor.Components.CookieConsent

Components for handling GDPR cookie consent
https://www.nuget.org/packages/BytexDigital.Blazor.Components.CookieConsent/
Apache License 2.0
38 stars 14 forks source link

Unhandled exception when using uBlock cookie filters #32

Open danielchalmers opened 1 week ago

danielchalmers commented 1 week ago

Loading mudblazor.com in incognito with uBlock cookie filters enabled on the latest version results in the site getting stuck on the loading screen with these errors:

Failed to load resource: net::ERR_BLOCKED_BY_CLIENT
dotnet.js:3 

        Uncaught (in promise) TypeError: Failed to fetch
    at Object.A [as fetch_like] (dotnet.js:3:4508)
    at dotnet.js:3:11593
    at dotnet.js:3:11609
blazor.webassembly.js:1  Error in mono_download_assets: Error: download 'https://mudblazor.com/_framework/BytexDigital.Blazor.Components.CookieConsent.wasm' for BytexDigital.Blazor.Components.CookieConsent.wasm failed 0 TypeError: Failed to fetch
Dt @ blazor.webassembly.js:1
3dotnet.js:3  Uncaught (in promise) Error: download 'https://mudblazor.com/_framework/BytexDigital.Blazor.Components.CookieConsent.wasm' for BytexDigital.Blazor.Components.CookieConsent.wasm failed 0 TypeError: Failed to fetch
    at dotnet.js:3:9983
    at async K (dotnet.js:3:8871)
    at async Y (dotnet.js:3:8196)
2mudblazor.com/:1  Uncaught (in promise) Error: download 'https://mudblazor.com/_framework/BytexDigital.Blazor.Components.CookieConsent.wasm' for BytexDigital.Blazor.Components.CookieConsent.wasm failed 0 TypeError: Failed to fetch
    at dotnet.js:3:9983
    at async K (dotnet.js:3:8871)
    at async Y (dotnet.js:3:8196)
blazor.webassembly.js:1  Uncaught (in promise) Error: Failed to start platform. Reason: Error: download 'https://mudblazor.com/_framework/BytexDigital.Blazor.Components.CookieConsent.wasm' for BytexDigital.Blazor.Components.CookieConsent.wasm failed 0 TypeError: Failed to fetch
    at mn (blazor.webassembly.js:1:57654)
dotnet.runtime.8.0.6.scyrrn9hx4.js:3  Uncaught (in promise) Error: download 'https://mudblazor.com/_framework/BytexDigital.Blazor.Components.CookieConsent.wasm' for BytexDigital.Blazor.Components.CookieConsent.wasm failed 0 TypeError: Failed to fetch
    at dotnet.js:3:9983
    at async K (dotnet.js:3:8871)
    at async Y (dotnet.js:3:8196)

If I disable the adblock, load the site successfully, then turn it back on, I get this error:

blazor.webassembly.js:1 

 GET https://mudblazor.com/_content/BytexDigital.Blazor.Components.CookieConsent/cookieconsent.js net::ERR_BLOCKED_BY_CLIENT
dotnet.runtime.8.0.6.scyrrn9hx4.js:3 
 fail: BytexDigital.Blazor.Components.CookieConsent.CookieConsentService[0]
      Exception raised trying to run CookiePreferencesChanged event handler
Microsoft.JSInterop.JSException: Failed to fetch dynamically imported module: https://mudblazor.com/_content/BytexDigital.Blazor.Components.CookieConsent/cookieconsent.js
TypeError: Failed to fetch dynamically imported module: https://mudblazor.com/_content/BytexDigital.Blazor.Components.CookieConsent/cookieconsent.js
   at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__16`1[[Microsoft.JSInterop.IJSObjectReference, Microsoft.JSInterop, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
   at BytexDigital.Blazor.Components.CookieConsent.Broadcasting.CookieConsentEventHandler.PublishToJsAsync(String name, String data)
   at BytexDigital.Blazor.Components.CookieConsent.Broadcasting.CookieConsentEventHandler.BroadcastCookiePreferencesChangedAsync(CookiePreferences cookiePreferences)
   at BytexDigital.Blazor.Components.CookieConsent.CookieConsentService.PublishCookiePreferencesChanged(CookiePreferences preferences)
   at BytexDigital.Blazor.Components.CookieConsent.CookieConsentServiceAuthority.NotifyApplicationLoadedAsync()

but the site still loads ok.

I'm looking to be able to take them blocking the cookies as a denial and continue loading the site smoothly.

danielchalmers commented 1 week ago

I don't think we're using the code wrong but we might have missed something https://github.com/search?q=repo%3AMudBlazor%2FMudBlazor%20cookie&type=code

ScarletKuro commented 1 week ago

I don't think we're using the code wrong but we might have missed something https://github.com/search?q=repo%3AMudBlazor%2FMudBlazor%20cookie&type=code

Better to redirect to PR that introduced it: https://github.com/MudBlazor/MudBlazor/pull/8602

RyanTT commented 1 week ago

https://github.com/BytexDigital/BytexDigital.Blazor.Components.CookieConsent/pull/31 would atleast fix the .js file from not being loaded, but the .wasm file is a bit tricky to me at the moment, as it gets baked into the bootup process of the WASM environment and I'm not sure yet how to best combat the blocking of this file crashing the entire bootup. I'll look around a little

ScarletKuro commented 1 week ago

31 would atleast fix the .js file from not being loaded, but the .wasm file is a bit tricky to me at the moment, as it gets baked into the bootup process of the WASM environment and I'm not sure yet how to best combat the blocking of this file crashing the entire bootup. I'll look around a little

As far as I read about the Failed to load resource: net::ERR_BLOCKED_BY_CLIENT error on StackOverflow, it seems like the adblocker is blocking URLs that contain "cookieconsent" or similar terms. While issue #31 can deal with the JS block since you can customize that part, there is nothing you can do about the assembly name.

It's not really impossible to dynamically load an assembly in WASM, but it is not trivial, especially if you need to rename the original assembly. Furthermore, it is impossible to dynamically load it if you are using WasmEnableWebcil since, as far as I know, the AssemblyLoadContext doesn't support it (though I am uncertain about this, as I recall some complaints about it in the runtime repository). At this point, it would be easier to fork the library and apply the AssemblyName tag change in the csproj.

The assembly load problem is the nastiest one because it will cause your website to crash, while a failed JS load won't, and the website will continue functioning.