Last active
September 6, 2022 12:09
-
-
Save moekhalil/c3e334fc92d2931bcb0e84134b2e60d0 to your computer and use it in GitHub Desktop.
Get list of all browser permissions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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