I have the following MudBlazor button that copies text from a row inside a table:
<MudIconButton OnClick="@(() => WriteTextAsync(@context.TokenName))"></MudIconButton>
@code {
public ValueTask WriteTextAsync(string text) {
return JsRuntime.InvokeVoidAsync("copyToClipboard", text);
}
}
This is the JavaScript function inside _Host.cshtml that the button invokes:
<script>
function copyToClipboard(text) {
navigator.clipboard.writeText(text).catch((err) => {
alert(err.message);
});
}
</script>
This code does work as expected on PC and Android but on iOS the following exception is thrown:
The request is not allowed by the user agent or the platform in the current context possibly because the user denied permission.
In this thread it was stated that the reason for the exception is that navigator.clipboard
must be called by user interactions and not by API calls. So it seems that the interaction with the button in Blazor does not count as a user interaction.
At the moment, unfortunately, I have no approach to be able to solve this problem and I am grateful for any help.
EDIT:
I have created a temporary fix by replacing the MudBlazor-button with the following HTML-button:
<button onclick="copyToClipboard(this.id)" id="@context.TokenName">
<svg> /*contains the graphics of the mudblazor button*/ </svg>
</button>