Namespace: SpawnDev.SpawnJS.JSObjects
Source: JSObjects/PermissionDescriptor.cs
MDN Reference: PermissionDescriptor on MDN
An object that sets options for the Permissions.query operation consisting of a comma-separated list of name-value pairs. https://developer.mozilla.org/en-US/docs/Web/API/Permissions/query
| Property | Type | Access | Description |
|---|---|---|---|
PermissionDescriptor |
class |
get | An object that sets options for the Permissions.query operation consisting of a comma-separated list of name-value pairs. https://developer.mozilla.org/en-US/docs/Web/API/Permissions/query |
UserVisibleOnly |
bool? |
get | |
Sysex |
bool? |
get |
SpawnDev.SpawnJS Mapping Note: The JavaScript examples below show the standard Web API usage. In SpawnDev.SpawnJS, the same API is available with C# conventions:
- Properties and methods use PascalCase (e.g.,
readyStatebecomesReadyState)- Events use ActionEvent with
+=/-=(e.g.,addEventListener("click", fn)becomesOnClick += handler)- Async methods return
Task<T>instead ofPromise<T>- Objects should be disposed with
usingstatements- Access via
JS.Get<PermissionDescriptor>(...)or constructornew PermissionDescriptor(...)
navigator.permissions.query({ name: "geolocation" }).then((result) => {
if (result.state === "granted") {
showLocalNewsWithGeolocation();
} else if (result.state === "prompt") {
showButtonToEnableLocalNews();
}
// Don't do anything if the permission was denied.
});// Array of permissions
const permissions = [
"accelerometer",
"accessibility-events",
"ambient-light-sensor",
"background-sync",
"camera",
"clipboard-read",
"clipboard-write",
"geolocation",
"gyroscope",
"local-fonts",
"magnetometer",
"microphone",
"midi",
"notifications",
"payment-handler",
"persistent-storage",
"push",
"screen-wake-lock",
"storage-access",
"top-level-storage-access",
"window-management",
];
processPermissions();
// Iterate through the permissions and log the result
async function processPermissions() {
for (const permission of permissions) {
const result = await getPermission(permission);
log(result);
}
}
// Query a single permission in a try...catch block and return result
async function getPermission(permission) {
try {
let result;
if (permission === "top-level-storage-access") {
result = await navigator.permissions.query({
name: permission,
requestedOrigin: window.location.origin,
});
} else {
result = await navigator.permissions.query({ name: permission });
}
return `${permission}: ${result.state}`;
} catch (error) {
return `${permission} (not supported)`;
}
}