dotnet / MobileBlazorBindings

Experimental Mobile Blazor Bindings - Build native and hybrid mobile apps with Blazor
MIT License
1.21k stars 172 forks source link

JSRuntime issue: after JS-invoking `print`, the application becomes very broken #408

Open BenMakesGames opened 3 years ago

BenMakesGames commented 3 years ago

after calling JSRuntime.InvokeVoidAsync("print"), <a href>s stopped working (clicking them had no effect).

rolling back to 0.5.50 resolved the issue.

BenMakesGames commented 3 years ago

actually, I think I confused myself: this bug exists in 0.5.50 as well, however if you use Ctrl+P to print page, there are no ill side effects.

view:

<button @onclick="DoPrint">Print</button>

code-behind:

        private async Task DoPrint()
        {
            await JS.InvokeVoidAsync("print");
        }

I also tried the suggestion here: https://stackoverflow.com/questions/67206330/window-print-in-blazor-wasm where the print method is moved into a custom JS function (not sure why that would matter, but I tried it, anyway), and the problem persisted.

I also-also tried making DoPrint not be async or await, but that didn't change anything, either.

I am able to JS.InvokeVoidAsync other JS methods with no ill effect (I made a ScrollToBottom method to scroll a div after content is added, and that doesn't cause any problems).

again, using Ctrl+P to print works fine; using JS.InvokeVoidAsync to do it, however, breaks the app in the following ways:

BenMakesGames commented 3 years ago

I just tried changing the button to instead be:

<a class="button" href="javascript:print();">Print</a>

and that works, without any ill side-effects!

so weird...

Eilon commented 3 years ago

Hmm yes weird indeed! I'm surprised that one works and not the other!

BenMakesGames commented 3 years ago

I've attempted to create a minimum project which will show the issue, however I'm unable to test it because I'm getting that "can't reach this page" issue I mentioned in the other issue (https://github.com/dotnet/MobileBlazorBindings/issues/416)

maybe there's some environment difference, though, and it'll work for you?? I've posted it here: https://github.com/BenMakesGames/MBBPrintBug

BenMakesGames commented 3 years ago

@Eilon I have a minimum project demonstrating the issue (now working, thanks to your hint about explicitly including WebView2), here: https://github.com/BenMakesGames/MBBPrintBug

I've added some notes on the print page about how to reproduce and see the issue. (seen here: https://github.com/BenMakesGames/MBBPrintBug/blob/main/PrintBug/Pages/Print.razor )