Skip to content

Latest commit

 

History

History
128 lines (82 loc) · 3.49 KB

permissions.md

File metadata and controls

128 lines (82 loc) · 3.49 KB

permissions

Documentation: Chrome Permissions API

A promise-based wrapper for the Chrome permissions API to request and manage extension permissions.

Methods

Events


isAvailablePermissions

isAvailablePermissions(method?: ApiMethodName<typeof chrome.permissions>): boolean

The optional method is a native function name, for example isAvailablePermissions("contains"). Import the public ApiMethodName type from @addon-core/browser for your own typed helpers. This checks callable presence without invoking the method; permissions and argument support still require handling.

Returns true when the permissions namespace is present on the API selected by browser() in the current context. Returns false if the namespace or WebExtension environment is absent, or if accessing it throws. The check is synchronous, does not log, and reads the current API on every call without caching. Without an argument, it checks namespace presence only. Pass a native method name to also check that it is callable. Neither form verifies permissions, argument support, or a successful operation. See method availability.

import {isAvailablePermissions} from "@addon-core/browser";

if (isAvailablePermissions()) {
    // The namespace is present; handle operation-specific failures when using it.
}

containsPermissions

containsPermissions(permissions: chrome.permissions.Permissions): Promise<boolean>

Checks whether the extension has the specified permissions.

getAllPermissions

getAllPermissions(): Promise<chrome.permissions.Permissions>

Retrieves all granted permissions.

requestPermissions

requestPermissions(permissions: chrome.permissions.Permissions): Promise<boolean>

Prompts the user to grant additional permissions.

removePermissions

removePermissions(permissions: chrome.permissions.Permissions): Promise<boolean>

Removes the specified permissions if granted.

addHostAccessRequest

addHostAccessRequest(request?: chrome.permissions.AddHostAccessRequest): Promise<void>

Requests additional host access at runtime.

removeHostAccessRequest

removeHostAccessRequest(request?: chrome.permissions.RemoveHostAccessRequest): Promise<void>

Clears a previously requested host access.

onPermissionsAdded

onPermissionsAdded(callback: (permissions: chrome.permissions.Permissions) => void): () => void

Fires when new permissions are granted.

onPermissionsRemoved

onPermissionsRemoved(callback: (permissions: chrome.permissions.Permissions) => void): () => void

Fires when permissions are removed.