Blazor JSExcpetion "Document is not focused"

When working with Blazor and clipboard, you might get following exception

DOMException: Document is not focused

or

JSException: Document is not focused

The exception is typically thrown when writeText or readText JS functions are invoked.

await _jsRuntime.InvokeVoidAsync("navigator.clipboard.writeText", text);

This exception happen if you have set some breakpoint in Blazor code or you have opened the debugging tools window.