e. * @param {string=} options.userContext * The id of the user context which should be used as a target * for permission update. * * @throws {InvalidArgumentError} * Raised if an argument is of an invalid type or value. * @throws {UnsupportedOperationError} * Raised when unsupported permissions are set. */ async setPermission(options = {}) { const { descriptor, state, origin, userContext: userContextId = null, } = options; lazy.permissions.validateDescriptor(descriptor); const permissionName = descriptor.name; if (permissionName === "storage-access") { // TODO: Bug 1895457. Add support for "storage-access" permission. throw new lazy.error.UnsupportedOperationError( `"descriptor.name" "${permissionName}" is currently unsupported` ); } lazy.permissions.validateState(state); lazy.assert.string( origin, lazy.pprint`Expected "origin" to be a string, got ${origin}` ); lazy.assert.that( origin => URL.canParse(origin), lazy.pprint`Expected "origin" to be a valid URL, got ${origin}` )(origin); let userContext; if (userContextId !== null) { lazy.assert.string( userContextId, lazy.pprint`Expected "userContext" to be a string, got ${userContextId}` ); if (!lazy.UserContextManager.hasUserContextId(userContextId)) { throw new lazy.error.NoSuchUserContextError( `User Context with id ${userContextId} was not found` ); } userContext = lazy.UserContextManager.getInternalIdById(userContextId); } const activeWindow = Services.wm.getMostRecentBrowserWindow(); let typedDescriptor; try { typedDescriptor = activeWindow.navigator.permissions.parseSetParameters({ descriptor, state, }); } catch (err) { throw new lazy.error.InvalidArgumentError( `The conversion of "descriptor" was not successful: ${err.message}` ); } lazy.permissions.set(typedDescriptor, state, origin, userContext); } } export const permissions = PermissionsModule; PK