Skip to content

Instantly share code, notes, and snippets.

@moekhalil
Last active September 6, 2022 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moekhalil/c3e334fc92d2931bcb0e84134b2e60d0 to your computer and use it in GitHub Desktop.
Save moekhalil/c3e334fc92d2931bcb0e84134b2e60d0 to your computer and use it in GitHub Desktop.
Get list of all browser permissions.
const getAvailablePermissions = async () => {
const allFeatures = document.featurePolicy
.features()
.sort()
.map((i) => ({ name: i }));
const availablePermissions = [];
const nonPermissionFeatures = [];
for (let index = 0; index < allFeatures.length; index++) {
const feature = allFeatures[index];
try {
const permissionStatus = await navigator.permissions.query(feature);
availablePermissions.push({
feature: feature.name,
permission: permissionStatus.name,
state: permissionStatus.state,
});
} catch (error) {
nonPermissionFeatures.push({
feature: feature.name,
error: error.message.split(':')[2].trim(),
});
}
}
return { availablePermissions, nonPermissionFeatures };
};
await getAvailablePermissions();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment