Skip to content

Commit

Permalink
Update getPermission() to handle "top-level-storage-access" correctly (
Browse files Browse the repository at this point in the history
…mdn#37831)

Querying for `top-level-storage-access` [requires](https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccessFor) the caller to pass a `requestedOrigin` value in addition to a `name`. This updates the implementation of the `getPermission()` to pass the `origin` of the window to the `query` call so that the required parameters are passed to the `permissions.query` call.
  • Loading branch information
aselya authored Jan 28, 2025
1 parent 8f10db5 commit d74e45a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion files/en-us/web/api/permissions/query/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,15 @@ async function processPermissions() {
// Query a single permission in a try...catch block and return result
async function getPermission(permission) {
try {
const result = await navigator.permissions.query({ name: permission });
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)`;
Expand Down

0 comments on commit d74e45a

Please sign in to comment.