MobileBlazorBindings icon indicating copy to clipboard operation
MobileBlazorBindings copied to clipboard

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

Open BenMakesGames opened this issue 4 years ago • 5 comments
trafficstars

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 avatar Sep 17 '21 17:09 BenMakesGames

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:

  • clicking any <a href...> fails to work (in my app's header, I have one with a URL in it, and another with javascript:history.go(-1), and both work before the print attempt, and both fail after)
  • I happen to be using Blazored.Modals, and clicking a button which should open one of these partially works: the page is updated so that scrolling is no longer possible (it adds styling rules to the <body> tag which I can see), but the modal never appears
  • there are no errors in the debugging console
  • when running with the debugger attached, it doesn't catch anything

BenMakesGames avatar Sep 24 '21 14:09 BenMakesGames

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...

BenMakesGames avatar Sep 24 '21 15:09 BenMakesGames

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

Eilon avatar Sep 24 '21 15:09 Eilon

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 avatar Sep 24 '21 18:09 BenMakesGames

@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 )

BenMakesGames avatar Oct 06 '21 13:10 BenMakesGames