Skip to content

WebView: release-build inspector + cross-platform background-colour Options API#24

Merged
jakepenn merged 3 commits into
minimal_masterfrom
jake/re-enable-webview-inspector-release
May 21, 2026
Merged

WebView: release-build inspector + cross-platform background-colour Options API#24
jakepenn merged 3 commits into
minimal_masterfrom
jake/re-enable-webview-inspector-release

Conversation

@jakepenn

@jakepenn jakepenn commented May 21, 2026

Copy link
Copy Markdown
Member

Summary

  1. Inspector access in release builds (c93b9139ed)

    • macOS: drop JUCE_DEBUG guard around developerExtrasEnabled, add setInspectable: YES for macOS 13.3+ / iOS 16.4+.
    • Windows: drop the #if !JUCE_DEBUG put_AreDevToolsEnabled(false) block.
    • Re-applies 7330a68, which was dropped by the 58c87ee develop merge.
  2. Cross-platform pre-paint background-colour control (bdddb1619c)

    • Adds WebBrowserComponent::Options::AppleWkWebView::withBackgroundColour(Colour) mirroring the existing WinWebView2::withBackgroundColour. When set, macOS uses drawsBackground = NO via KVC (same private-but-stable trick Tauri/wry uses) and, on macOS 12+, the public setUnderPageBackgroundColor. Opt-in — default behaviour unchanged.
    • Windows already supports this via WinWebView2::withBackgroundColour. No code change needed there.
    • Linux (webkit2gtk) does not yet expose webkit_web_view_set_background_color through JUCE's symbol resolver — flagged as a follow-up in the commit message.

Why

Plugins ship as release builds and run inside a DAW host — JUCE_DEBUG-only gating made the inspector unreachable in the only environment plugin UIs actually run in.

WKWebView paints an opaque default background (white in light mode, a system grey in dark mode) until the first content frame renders. Plugins that gate webview visibility on a first-paint handshake (1×1 during boot, hidden-then-shown, etc.) see this flash every launch. The drawsBackground KVC trick lets the host paint its own background through the transparent surface — the same approach Tauri/wry takes across all three platforms.

Test plan

  • macOS: build a Release plugin with juce::WebBrowserComponent. Attach Safari → Develop → [Mac] → [WebView entry]; inspector connects.
  • macOS: with Options::AppleWkWebView{}.withBackgroundColour(Colour(0,0,0,0)) set on a webview that gates visibility on a first-paint handshake, confirm no flash on first reveal.
  • macOS without withBackgroundColour: confirm behaviour is unchanged from upstream.
  • iOS: smoke-test that withBackgroundColour doesn't break a release build.
  • Windows: existing WinWebView2::withBackgroundColour continues to work; Release inspector still right-click → Inspect.

Re-applies 7330a68, which was lost in the 58c87ee develop merge.

macOS:
- Drop the JUCE_DEBUG guard around `developerExtrasEnabled` so the
  Safari Web Inspector is reachable from release builds.
- Set `inspectable: YES` on the WKWebView for macOS 13.3+ / iOS 16.4+,
  where Apple made it a required public-API opt-in alongside the
  legacy preference key.

Windows:
- Drop the `#if !JUCE_DEBUG put_AreDevToolsEnabled(false)` block so
  WebView2's DevTools stay enabled by default in release.

Plugins ship as release builds by definition — the developer-only
gating made the inspector unreachable in the one environment where
plugin UIs actually run, which made webview-based UI work painful to
debug.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jakepenn jakepenn changed the title WebView: enable Web Inspector / DevTools in release builds WebView: release-build inspector + kill the WKWebView startup white flash May 21, 2026
@jakepenn jakepenn force-pushed the jake/re-enable-webview-inspector-release branch from cd7e303 to c93b913 Compare May 21, 2026 15:55
Mirrors the existing WinWebView2::withBackgroundColour API surface so a
cross-platform host can configure both backends from one place.

When set, the WKWebView's NSView gets `drawsBackground = NO` via KVC —
the same private-but-stable trick Tauri/wry uses (`wry/src/wkwebview/
mod.rs`, stable since macOS 10.14, the path Safari and Xcode follow).
On macOS 12+ / iOS 15+ the public `setUnderPageBackgroundColor` is
also set so the overscroll bounce area picks up the chosen colour.

Opt-in: only takes effect when withBackgroundColour() is called on the
AppleWkWebView options. Default behaviour is unchanged.

Why: WKWebView paints an opaque default background (white in light
mode, a system grey in dark mode) until the page renders, which
produces a one-frame flash whenever the OS surface is shown or resized
into real bounds. Plugins doing any form of webview-host visibility
gating (hidden-on-load, 1×1 during boot, etc.) hit this every launch.

Linux backend (juce_WebBrowserComponent_linux.cpp) does not yet expose
an equivalent — webkit_web_view_set_background_color isn't bound
through the JUCE symbol resolver. Adding that is a follow-up.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jakepenn jakepenn changed the title WebView: release-build inspector + kill the WKWebView startup white flash WebView: release-build inspector + cross-platform background-colour Options API May 21, 2026
WKWebView copies WKWebViewConfiguration values at init, so KVC-setting
`drawsBackground` on the config after webview creation was a no-op —
the surface kept its opaque default and the very first frame still
flashed white/system-grey on reveal. Move the call to the WebView
itself, where it actually takes effect.

Also belt-and-braces the underlying NSView's CALayer on macOS: some
recent WebKit builds composite the host NSView independently of the
WKWebView's drawsBackground state, so a transparent layer background
catches the remaining frame.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jakepenn jakepenn merged commit a2d1826 into minimal_master May 21, 2026
1 check failed
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.

1 participant