In this application I try to access the local fonts of a browser using the following API: https://wicg.github.io/local-font-access
The app should ask the user for permission to access the fonts, however my problem is that because of security reasons the prompt for asking permission is not shown unless the user has some displayed some activity (e.g. user clicked before 5s passed). That rule is defined here.
I need to request font access at when the application starts and when user hasn't conducted any activity yet. Adding a button like Load fonts
will fix the problem but I am trying to avoid this.
Is it possible to overcome this restriction and prompt the user or permission at startup without initial user interaction?
<!DOCTYPE html>
<html>
<body onload="loadFonts()">
<script>
async function loadFonts() {
setTimeout(async () => {
try {
const array = await self.queryLocalFonts();
array.forEach(font => {
console.log(font.postscriptName);
});
} catch(e) {
// Handle error, e.g. user cancelled the operation.
console.warn(`Local font access not available: ${e.message}`);
}
}, 5000);
}
</script>
</body>
</html>