Skip to content

feat(mac/v2): expose mediaTypesRequiringUserActionForPlayback on WKWebView#5512

Open
Eyalm321 wants to merge 1 commit into
wailsapp:masterfrom
Eyalm321:fix/macos-media-playback-options-v2
Open

feat(mac/v2): expose mediaTypesRequiringUserActionForPlayback on WKWebView#5512
Eyalm321 wants to merge 1 commit into
wailsapp:masterfrom
Eyalm321:fix/macos-media-playback-options-v2

Conversation

@Eyalm321
Copy link
Copy Markdown

@Eyalm321 Eyalm321 commented May 27, 2026

Summary

Adds EnableAutoplayWithoutUserAction to mac.Preferences, mapping to WKWebViewConfiguration.mediaTypesRequiringUserActionForPlayback. Without it, there is no way to autoplay HTML5 video/audio in a Wails v2 macOS app — every <video autoplay> is blocked.

Closes #5511.

Implementation

Mirrors the existing preference-passing pattern (compare TabFocusesLinks, FullscreenEnabled):

  1. Add EnableAutoplayWithoutUserAction u.Bool to mac.Preferences (v2/pkg/options/mac/preferences.go)
  2. Add bool *enableAutoplayWithoutUserAction to the C struct Preferences (WailsContext.h)
  3. Wire through the Go side via IsSet() + bool2CboolPtr(...) (window.go)
  4. Apply on WKWebViewConfiguration when set:
    if (preferences.enableAutoplayWithoutUserAction != NULL && *preferences.enableAutoplayWithoutUserAction) {
        config.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
    }

Defaults preserve WebKit's current behaviour (user gesture required) — opt-in only.

iOS in v3 already exposes the equivalent option (EnableAutoplayWithoutUserAction in application_options.go), and the same gap is being filled for v3 macOS in a parallel PR.

Note: allowsInlineMediaPlayback is iOS-only on WKWebViewConfiguration (verified by macos-latest compile failure with Xcode 16.4 SDK), so it is intentionally not exposed on macOS.

Test plan

  • Build on macOS (validated via fork CI on macos-latest / Xcode 16.4)
  • Manual: a v2 app with <video autoplay src="..."> and Mac.Preferences.EnableAutoplayWithoutUserAction: mac.Enabled autoplays without a click
  • Regression: unset/false preserves prior behaviour (gesture required)

Summary by CodeRabbit

New Features

  • Introduced macOS preference for automatic media playback without user interaction. Developers can now configure whether media playback requires explicit user gestures, enabling more flexible playback control in desktop applications while respecting default behavior when disabled.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 30ce49c7-07bf-42a7-9a32-13d8d7947377

📥 Commits

Reviewing files that changed from the base of the PR and between bf58079 and f39b362.

📒 Files selected for processing (4)
  • v2/internal/frontend/desktop/darwin/WailsContext.h
  • v2/internal/frontend/desktop/darwin/WailsContext.m
  • v2/internal/frontend/desktop/darwin/window.go
  • v2/pkg/options/mac/preferences.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • v2/pkg/options/mac/preferences.go
  • v2/internal/frontend/desktop/darwin/WailsContext.m
  • v2/internal/frontend/desktop/darwin/window.go

Walkthrough

This PR adds macOS media autoplay support to Wails v2 by introducing a new user-facing preference, bridging it through C to Objective-C, and applying it directly to WebKit's audio/visual media configuration during window creation.

Changes

macOS Media Autoplay Feature

Layer / File(s) Summary
Public macOS autoplay option
v2/pkg/options/mac/preferences.go
Preferences adds EnableAutoplayWithoutUserAction field documented to permit WebKit autoplay without user gesture; when unset or false preserves WebKit's default gesture-required behavior.
Go-to-C bridge for autoplay
v2/internal/frontend/desktop/darwin/WailsContext.h, v2/internal/frontend/desktop/darwin/window.go
C struct Preferences gains enableAutoplayWithoutUserAction pointer field; Go NewWindow conditionally reads the option and forwards its value to the C struct before window creation.
WebKit autoplay configuration
v2/internal/frontend/desktop/darwin/WailsContext.m
CreateWindow method conditionally sets config.mediaTypesRequiringUserActionForPlayback to WKAudiovisualMediaTypeNone when the bridged preference is present and enabled.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

reviewed ✅

Suggested reviewers

  • leaanthony

Poem

🐰 With a bound and a hop through macOS so grand,
Media now plays at a developer's command.
No gesture required—autoplay's the way!
WebKit's magic flows, no delays, hip hooray! 🎬

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: exposing mediaTypesRequiringUserActionForPlayback on WKWebView for macOS v2.
Description check ✅ Passed The PR description is comprehensive, covering summary, implementation details, test plan, and linking to issue #5511. However, some template sections like 'How Has This Been Tested?' and checklist items are incomplete.
Linked Issues check ✅ Passed The PR directly addresses issue #5511 by implementing EnableAutoplayWithoutUserAction for macOS v2, mapping to mediaTypesRequiringUserActionForPlayback, which was the primary coding requirement.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing EnableAutoplayWithoutUserAction across four files (preferences.go, WailsContext.h, WailsContext.m, window.go) as specified in issue #5511, with intentional exclusion of allowsInlineMediaPlayback.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
.github/workflows/build-macos-media-playback.yml (1)

18-23: ⚖️ Poor tradeoff

Consider pinning actions to commit SHAs.

Pinning to commit hashes prevents supply-chain attacks via tag/version manipulation.

Example with SHA pinning
-      - uses: actions/checkout@v4
+      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
         with:
           persist-credentials: false
 
-      - uses: actions/setup-go@v5
+      - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0

You can find the commit SHAs for specific versions in each action's repository release page.

Also applies to: 43-48

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/build-macos-media-playback.yml around lines 18 - 23,
Replace floating action tags with immutable commit SHAs: locate the occurrences
of "uses: actions/checkout@v4" and "uses: actions/setup-go@v4" (and the other
occurrences flagged around lines 43-48) and change them to the corresponding
commit SHA references from each action's GitHub repo (e.g.,
actions/checkout@<commit-sha> and actions/setup-go@<commit-sha>); update the
workflow comments to note the chosen SHAs and, if desired, add a short note or
workflow-level variable that documents the original tag version for future
updates.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/build-macos-media-playback.yml:
- Line 20: Replace the outdated runner reference "uses: actions/setup-go@v4"
with "uses: actions/setup-go@v5" wherever it appears in the workflow (there are
two occurrences of the literal "uses: actions/setup-go@v4"); update both
instances so the workflow uses actions/setup-go@v5.
- Line 18: Update the checkout steps that use the action identifier "uses:
actions/checkout@v4" to include the option persist-credentials: false so
credentials are not persisted in the workspace; apply this change to each
checkout step occurrence (including the second occurrence referenced in the
review) by adding the persist-credentials: false key under the same job/step
that calls actions/checkout@v4.
- Around line 1-9: Add an explicit top-level GitHub Actions permissions block
for the "Build darwin (media-playback options)" workflow (the YAML with the
name: Build darwin (media-playback options) and the on: section) to restrict the
OIDC token scope; include only the minimal required permissions such as
contents: read and packages: read (and add id-token: write only if the workflow
needs OIDC), placing the permissions stanza at the top-level of the workflow
file.

---

Nitpick comments:
In @.github/workflows/build-macos-media-playback.yml:
- Around line 18-23: Replace floating action tags with immutable commit SHAs:
locate the occurrences of "uses: actions/checkout@v4" and "uses:
actions/setup-go@v4" (and the other occurrences flagged around lines 43-48) and
change them to the corresponding commit SHA references from each action's GitHub
repo (e.g., actions/checkout@<commit-sha> and actions/setup-go@<commit-sha>);
update the workflow comments to note the chosen SHAs and, if desired, add a
short note or workflow-level variable that documents the original tag version
for future updates.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 85a2b43e-54c3-4dce-a8e9-db080071f2e3

📥 Commits

Reviewing files that changed from the base of the PR and between 6329e9d and 20bd946.

📒 Files selected for processing (5)
  • .github/workflows/build-macos-media-playback.yml
  • v2/internal/frontend/desktop/darwin/WailsContext.h
  • v2/internal/frontend/desktop/darwin/WailsContext.m
  • v2/internal/frontend/desktop/darwin/window.go
  • v2/pkg/options/mac/preferences.go

Comment thread .github/workflows/build-macos-media-playback.yml Outdated
Comment thread .github/workflows/build-macos-media-playback.yml Outdated
Comment thread .github/workflows/build-macos-media-playback.yml Outdated
@Eyalm321 Eyalm321 force-pushed the fix/macos-media-playback-options-v2 branch from 20bd946 to bf58079 Compare May 27, 2026 21:34
Add EnableAutoplayWithoutUserAction to mac.Preferences, mapping to
WKWebViewConfiguration.mediaTypesRequiringUserActionForPlayback.

Without this option, there is no way to autoplay HTML5 video/audio in
a Wails v2 macOS app — every <video autoplay> is blocked by WebKit's
user-gesture requirement.

Follows the existing pattern used for TabFocusesLinks, FullscreenEnabled
etc.: u.Bool option, bool* in the C struct, applied on WKWebViewConfiguration
when set. Defaults preserve current WebKit behaviour (gesture required) —
opt-in only.

iOS already exposes the equivalent (EnableAutoplayWithoutUserAction in
v3 application_options.go); this brings v2 macOS to parity.

Closes wailsapp#5511
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (3)
.github/workflows/build-macos-media-playback.yml (3)

20-20: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

actions/setup-go@v4 is outdated and can fail the workflow.

At Line 20 and Line 45, bump to actions/setup-go@v5.

Suggested patch
-      - uses: actions/setup-go@v4
+      - uses: actions/setup-go@v5
...
-      - uses: actions/setup-go@v4
+      - uses: actions/setup-go@v5

Also applies to: 45-45

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/build-macos-media-playback.yml at line 20, Replace the
outdated GitHub Actions step using actions/setup-go@v4 with actions/setup-go@v5
in the workflow file: locate the occurrences of the runner step that reads
"uses: actions/setup-go@v4" (found at the instances around the top-level steps,
including the lines referenced) and update the version tag to
"actions/setup-go@v5" for both occurrences so the workflow uses the current
setup-go action.

18-18: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Disable credential persistence on checkout.

At Line 18 and Line 43, set persist-credentials: false to reduce token exposure across later steps/artifacts.

Suggested patch
       - uses: actions/checkout@v4
+        with:
+          persist-credentials: false
...
       - uses: actions/checkout@v4
+        with:
+          persist-credentials: false

Also applies to: 43-43

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/build-macos-media-playback.yml at line 18, Update the
GitHub Actions checkout steps to disable credential persistence by adding
persist-credentials: false to each actions/checkout@v4 invocation; specifically
modify the checkout step(s) referenced (the steps that call actions/checkout@v4
at both occurrences) to include the persist-credentials: false key so tokens are
not automatically persisted to later steps or artifacts.

1-9: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add least-privilege workflow permissions.

There is no top-level permissions block, so the workflow inherits broader defaults. Add minimal read-only scope unless a job explicitly needs more.

Suggested patch
 name: Build darwin (media-playback options)
 
+permissions:
+  contents: read
+
 on:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/build-macos-media-playback.yml around lines 1 - 9, Add a
top-level GitHub Actions permissions block to this workflow (name "Build darwin
(media-playback options)") to enforce least-privilege access by setting minimal
read-only scopes (e.g., set contents: read) at the root of the YAML; if any job
or step (refer to job names in this workflow) requires broader rights, grant
only the specific additional permissions on that job via its own permissions
map.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In @.github/workflows/build-macos-media-playback.yml:
- Line 20: Replace the outdated GitHub Actions step using actions/setup-go@v4
with actions/setup-go@v5 in the workflow file: locate the occurrences of the
runner step that reads "uses: actions/setup-go@v4" (found at the instances
around the top-level steps, including the lines referenced) and update the
version tag to "actions/setup-go@v5" for both occurrences so the workflow uses
the current setup-go action.
- Line 18: Update the GitHub Actions checkout steps to disable credential
persistence by adding persist-credentials: false to each actions/checkout@v4
invocation; specifically modify the checkout step(s) referenced (the steps that
call actions/checkout@v4 at both occurrences) to include the
persist-credentials: false key so tokens are not automatically persisted to
later steps or artifacts.
- Around line 1-9: Add a top-level GitHub Actions permissions block to this
workflow (name "Build darwin (media-playback options)") to enforce
least-privilege access by setting minimal read-only scopes (e.g., set contents:
read) at the root of the YAML; if any job or step (refer to job names in this
workflow) requires broader rights, grant only the specific additional
permissions on that job via its own permissions map.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 01eaee00-77e6-49e6-bf80-f93f014163cc

📥 Commits

Reviewing files that changed from the base of the PR and between 20bd946 and bf58079.

📒 Files selected for processing (5)
  • .github/workflows/build-macos-media-playback.yml
  • v2/internal/frontend/desktop/darwin/WailsContext.h
  • v2/internal/frontend/desktop/darwin/WailsContext.m
  • v2/internal/frontend/desktop/darwin/window.go
  • v2/pkg/options/mac/preferences.go
✅ Files skipped from review due to trivial changes (1)
  • v2/internal/frontend/desktop/darwin/WailsContext.h
🚧 Files skipped from review as they are similar to previous changes (3)
  • v2/internal/frontend/desktop/darwin/window.go
  • v2/pkg/options/mac/preferences.go
  • v2/internal/frontend/desktop/darwin/WailsContext.m

@Eyalm321 Eyalm321 force-pushed the fix/macos-media-playback-options-v2 branch from bf58079 to f39b362 Compare May 27, 2026 21:37
Eyalm321 pushed a commit to Eyalm321/claudepanel that referenced this pull request May 27, 2026
Pin to a Wails v2 fork that exposes WKWebViewConfiguration.mediaTypesRequiringUserActionForPlayback,
then opt in via Mac.Preferences.EnableAutoplayWithoutUserAction.

Without this, every <video>/<audio> tag in the embedded webview required
a click before playback — making things like ambient bar audio unusable.

Fork: github.com/Eyalm321/wails/v2 v2.12.0-mediaplayback.1
Upstream PR: wailsapp/wails#5512

Bumps CI Go to 1.25 to match the fork's go.mod requirement.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Eyalm321 added a commit to Eyalm321/claudepanel that referenced this pull request May 28, 2026
Pin to a Wails v2 fork that exposes WKWebViewConfiguration.mediaTypesRequiringUserActionForPlayback,
then opt in via Mac.Preferences.EnableAutoplayWithoutUserAction.

Without this, every <video>/<audio> tag in the embedded webview required
a click before playback — making things like ambient bar audio unusable.

Fork: github.com/Eyalm321/wails/v2 v2.12.0-mediaplayback.1
Upstream PR: wailsapp/wails#5512

Bumps CI Go to 1.25 to match the fork's go.mod requirement.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS: expose WKWebViewConfiguration.mediaTypesRequiringUserActionForPlayback and allowsInlineMediaPlayback

1 participant