WebView: release-build inspector + cross-platform background-colour Options API#24
Merged
jakepenn merged 3 commits intoMay 21, 2026
Merged
Conversation
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>
cd7e303 to
c93b913
Compare
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>
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>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Inspector access in release builds (
c93b9139ed)JUCE_DEBUGguard arounddeveloperExtrasEnabled, addsetInspectable: YESfor macOS 13.3+ / iOS 16.4+.#if !JUCE_DEBUG put_AreDevToolsEnabled(false)block.Cross-platform pre-paint background-colour control (
bdddb1619c)WebBrowserComponent::Options::AppleWkWebView::withBackgroundColour(Colour)mirroring the existingWinWebView2::withBackgroundColour. When set, macOS usesdrawsBackground = NOvia KVC (same private-but-stable trick Tauri/wry uses) and, on macOS 12+, the publicsetUnderPageBackgroundColor. Opt-in — default behaviour unchanged.WinWebView2::withBackgroundColour. No code change needed there.webkit_web_view_set_background_colorthrough 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
drawsBackgroundKVC trick lets the host paint its own background through the transparent surface — the same approach Tauri/wry takes across all three platforms.Test plan
juce::WebBrowserComponent. Attach Safari → Develop → [Mac] → [WebView entry]; inspector connects.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.withBackgroundColour: confirm behaviour is unchanged from upstream.withBackgroundColourdoesn't break a release build.WinWebView2::withBackgroundColourcontinues to work; Release inspector still right-click → Inspect.