Skip to content

queryLocalFonts User activation is required #8299

@jonlepage

Description

@jonlepage

This security measure is not truly necessary in a local desktop application.
It appears that the user must interact with the application before gaining access to this API.
I resolved the issue by adding a Load System Fonts button, which slightly impairs the user experience (UX design).

This behavior remains inconsistent when interacting multiple times within the application.
It is essential that this functionality be triggered exclusively through a button to work !.
IDK if you can disable this rule in chromium or bypass, but i just want to warn.

// if you call this outside a button, it not work : will work in browser console
async function getSystemFonts(): Promise<string[]> {
	try {
		const availableFonts = await window.queryLocalFonts();
		for ( const fontData of availableFonts ) {
			console.log( fontData.postscriptName );
			console.log( fontData.fullName );
			console.log( fontData.family );
			console.log( fontData.style );
		}
	} catch( err ) {
		console.error( err );
	}

	return [ ];
}

https://developer.mozilla.org/en-US/docs/Web/Security/User_activation#transient_activation
https://developer.mozilla.org/en-US/docs/Web/API/Window/queryLocalFonts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions