I'm trying to copy the results of a game to the clipboard upon completion of the game, but I'm receiving the following error when running in Safari: "Unhandled Promise Rejection: NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission."
The following function is called when the game is finished, and the clipboard api is called towards the bottom. Every related question I've been able to find has had to do with playing audio, but I'm not sure what applies here. Thanks for any help!
function generateScoreCard () {
let result = ``;
result = result + "Circuit " + GetFormattedDate() + "\n\n";
for( var i=0; i< pastGuesses.length; i++ )
{
console.log(pastGuesses[i].color)
switch (pastGuesses[i].color) {
case '#51ff45':
result = result + '✅';
break;
case '#c1ff4d':
result = result + '🟢';
break;
case '#fceb4c':
result = result + '🟡';
break;
case '#ffa647':
result = result + '🟠';
break;
case '#ff774a':
result = result + '🟠';
break;
default:
result = result + '🔴';
break;
}
}
var clip_result = result + " = " + numGuesses;
//await navigator.permissions.query({ name: 'clipboard-read' });
await navigator.clipboard.writeText(clip_result);
}