Office.DevicePermissionType enum

Specifies the device capability to which an add-in is requesting access.

Remarks

Applications: This API is supported by the following Office applications when running in Chromium-based browsers, such as Microsoft Edge and Google Chrome.

  • Excel on the web

  • Outlook on the web

  • PowerPoint on the web

  • Word on the web

It's also supported in new Outlook on Windows.

Requirement set: DevicePermission 1.1

Examples

// Request permission from a user to access their device capabilities.
const host = Office.context.host;
if (host === Office.HostType.Excel || host === Office.HostType.PowerPoint || host === Office.HostType.Word) {
    if (Office.context.platform === Office.PlatformType.OfficeOnline) {
        const deviceCapabilities = [
            Office.DevicePermissionType.camera,
            Office.DevicePermissionType.microphone
        ];
        Office.devicePermission
            .requestPermissions(deviceCapabilities)
            .then((isGranted) => {
                if (isGranted) {
                    console.log("Permission granted.");
                    // Reload your add-in before you run code that uses the device capabilities.
                    location.reload();
                } else {
                    console.log("Permission has been previously granted and is already set in the iframe.");

                    // Since permission has been previously granted, you don't need to reload your add-in.

                    // Do something with the device capabilities.
                }
            })
            .catch((error) => {
                console.log("Permission denied.");
                console.error(error);

                // Do something when permission is denied.
            });
    }
} else if (host === Office.HostType.Outlook) {
    if (Office.context.mailbox.diagnostics.hostName === "OutlookWebApp") {
        const deviceCapabilities = [
            Office.DevicePermissionType.camera,
            Office.DevicePermissionType.geolocation,
            Office.DevicePermissionType.microphone
        ];

        Office.devicePermission.requestPermissionsAsync(deviceCapabilities, (asyncResult) => {
            if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                console.log("Permission denied.");

                // Do something when permission is denied.
            } else {
                if (asyncResult.value) {
                    console.log("Permission granted.");
                    // Reload your add-in before you run code that uses the device capabilities.
                    location.reload();
                } else {
                    console.log("Permission has been previously granted and is already set in the iframe.");
                    
                    // Since permission has been previously granted, you don't need to reload your add-in.

                    // Do something with the device capabilities.
                }
            }
        });
    }
} else {
    console.log("The add-in isn't running in Excel, Outlook, PowerPoint, or Word.");
}

Fields

camera

The add-in is requesting access to the user's camera.

geolocation

The add-in is requesting access to the user's geolocation.

Important: Access to a user's geolocation is only supported in Outlook on the web and new Outlook on Windows.

microphone

The add-in is requesting access to the user's microphone.