- Qt 6.8
- Qt WebEngine
- C++ Classes
- QtWebEngineCore
- QWebEnginePermission
- Qt 6.8.1 Reference Documentation

# QWebEnginePermission Class

A QWebEnginePermission is an object used to access and modify the state of a single permission that's been granted or denied to a specific origin URL. More...

Header: | `#include <QWebEnginePermission>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS WebEngineCore)` `target_link_libraries(mytarget PRIVATE Qt6::WebEngineCore)`
qmake: | `QT += webenginecore`
Since: | Qt 6.8
In QML: | webEnginePermission

## Detailed Description

The typical usage pattern is as follows:

1. A website requests a specific permission, triggering the QWebEnginePage::permissionRequested() signal;
2. The signal handler triggers a prompt asking the user whether they want to grant the permission;
3. When the user has made their decision, the application calls grant() or deny();

Alternatively, an application interested in modifying already granted permissions may use QWebEngineProfile::listAllPermissions() to get a list of existing permissions associated with a profile, or QWebEngineProfile::queryPermission() to get a QWebEnginePermission object for a specific permission.

The origin() property can be used to query which origin the QWebEnginePermission is associated with, while the permissionType() property describes the type of the requested permission. A website origin is the combination of its scheme, hostname, and port. Permissions are granted on a per-origin basis; thus, if the web page `https://www.example.com:12345/some/page.html` requests a permission, it will be granted to the origin `https://www.example.com:12345/`.

QWebEnginePermission::PermissionType describes all the permission types Qt WebEngine supports. Only some permission types are remembered between browsing sessions; they are persistent. Non-persistent permissions query the user every time a website requests them. You can check whether a permission type is persistent at runtime using the static method QWebEnginePermission::isPersistent().

Persistent permissions are stored inside the active QWebEngineProfile, and their lifetime depends on the value of QWebEngineProfile::persistentPermissionsPolicy(). By default, named profiles store their permissions on disk, whereas off-the-record ones store them in memory (and destroy them when the profile is destroyed). A stored permission will not query the user the next time a website requests it; instead it will be automatically granted or denied, depending on the resolution the user picked initially. To erase a stored permission, call reset() on it.

A non-persistent permission, on the other hand, is only usable until the related QWebEnginePage performs a navigation to a different URL, or is destroyed.

You can check whether a QWebEnginePermission is in a valid state using its isValid() property. For invalid objects, calls to grant(), deny(), or reset() will do nothing, while calls to state() will always return QWebEnginePermission::Invalid.

See also QWebEnginePage::permissionRequested(), QWebEngineProfile::queryPermission(), and QWebEngineProfile::listAllPermissions().