Skip to content

macOS: expose WKWebViewConfiguration.mediaTypesRequiringUserActionForPlayback and allowsInlineMediaPlayback #5511

@Eyalm321

Description

@Eyalm321

Summary

Wails currently constructs WKWebViewConfiguration on macOS but never exposes two important media-playback properties. This makes it impossible to let media autoplay without a user gesture in a Wails macOS application.

Affected properties

Property What it controls
WKWebViewConfiguration.mediaTypesRequiringUserActionForPlayback Whether audio/video requires a user gesture before playback. Set to WKAudiovisualMediaTypeNone (0) to allow autoplay.
WKWebViewConfiguration.allowsInlineMediaPlayback Whether video plays inline (inside the page) rather than full-screen.

Use cases blocked today

  • Kiosk / digital-signage apps with ambient background video
  • Media players that should start playing on load
  • WebRTC self-preview (camera stream) that starts without a click
  • Any page that uses <video autoplay> or the Web Audio API

Current state

v2 (stable): WailsContext.m allocates WKWebViewConfiguration and applies suppressesIncrementalRendering, user-agent, scheme handlers, and a small set of WKPreferences flags — but not the two media properties.

v3 (alpha): webview_window_darwin.go passes a struct WebviewPreferences through to windowNew() in Objective-C and applies TabFocusesLinks, TextInteractionEnabled, FullscreenEnabled, and AllowsBackForwardNavigationGestures — but again, not the media properties.

Precedent: iOS already does this

v3/pkg/application/webview_window_ios.m (lines inside viewDidLoad) already sets both properties based on options passed from Go:

config.allowsInlineMediaPlayback = ios_is_inline_media_playback_enabled();
if (ios_is_autoplay_without_user_action_enabled()) {
    config.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
} else {
    config.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAll;
}

These are exposed in application_options.go as:

EnableInlineMediaPlayback       bool
EnableAutoplayWithoutUserAction bool

macOS should have the equivalent options.

Related

Proposed fix

Add two new u.Bool fields to MacWebviewPreferences (v3) and mac.Preferences (v2), extend the C struct Preferences / struct WebviewPreferences conduit, and apply the properties in the Objective-C WKWebViewConfiguration setup block — mirroring exactly what iOS already does.

Defaults preserve current behaviour (WebKit requires a user gesture unless the app explicitly opts in).

I have a fork with both v2 and v3 branches ready. Happy to open PRs once this issue is acknowledged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions