Web Permission API

JadeView 2.4 provides a unified web permission interception system. When a page requests camera, microphone, display capture, file access, clipboard read, geolocation, notifications, and other permissions, the main process can centrally decide whether to allow or deny them through a unified handler.

Register Handler

C
set_webview_permission_handler(permission_callback);

Clear the handler:

C
clear_webview_permission_handler();

Callback Signature

C
int32_t JADEVIEW_CALL permission_callback(
    uint32_t window_id,
    const char* event_data
);
  • window_id: id of the window that initiated the permission request.
  • event_data: UTF-8 JSON, for example:
JSON
{
  "window_id": 1,
  "kind": "camera",
  "requestingUrl": "https://example.com/",
  "origin": "https://example.com",
  "isUserInitiated": true,
  "mediaTypes": ["video"]
}

Permission Types

kindMeaning
cameraCamera
microphoneMicrophone
display-captureScreen / window / tab capture
file-system-accessFile system access, such as showOpenFilePicker, showDirectoryPicker
clipboard-readRead the clipboard
geolocationGeolocation
notificationsWeb notifications
midiMIDI devices
sensorsSensors
local-fontsLocal font access
window-managementMulti-window management
pointer-lockPointer lock
automatic-downloadsAutomatic downloads
autoplayMedia autoplay
otherOther or unrecognized permissions

Callback Return Value

The integer returned by the callback determines the permission result:

Return valueResult
0Use the browser default behavior
1Allow the permission
-1Deny the permission
Any other valueDeny the permission

The browser default behavior is used when no handler is set.

Example

C
int32_t JADEVIEW_CALL on_permission(uint32_t window_id, const char* data) {
    /*
     * Parse the JSON according to your business logic before deciding.
     * This example allows only camera and denies all other permissions.
     */
    if (strstr(data, "\"kind\":\"camera\"") != NULL) {
        return 1;
    }
    return -1;
}

set_webview_permission_handler(on_permission);

Platform Support

  • Windows: fully supports WebView2 permission types; requestingUrl and origin in event data are available.
  • Linux: due to WebKitGTK limitations, requestingUrl and origin may be empty; Windows-specific types such as file-system-access may be reported as other.

Error Handling Recommendations

  • The permission callback is synchronous; do not block for a long time or perform time-consuming work inside it.
  • When no handler is set, the browser default behavior is used; if you need strict unified allow/deny, call set_webview_permission_handler first.
  • The permission handler is called inline synchronously on the GUI thread; see Event Types.