Webview ui

From Generous-Corp/pulp · View interactive version

Webview ui is an AI agent skill from the GitHub repository Generous-Corp/pulp. Build or iterate on a Pulp WebView UI using the native WebView bridge, embedded assets, directory-backed dev resources, and focused WebView validation.

How to use this skill

Skill file

WebView UI

Use this skill when working on Pulp's optional WebView layer: HTML/JS panels,

Monaco-style tools, documentation views, or mixed native/WebView windows.

Core Positioning

Pulp WebView is an opt-in compatibility layer, not the primary UI path.

Default to native Pulp UI unless the task truly benefits from existing web

content.

Core Runtime Pieces

Main APIs:

Bridge contract:

Platform Truth

PULP_BUILD_WEBVIEW=ON is now the honest opt-in switch for the common Pulp

WebView layer on:

Required platform notes:

Keep claims narrow:

pulp-webview-palette build proof

actually there

File drag-and-drop (from `choc::ui::WebView`)

CHOC's WebView layer carries file drag-and-drop, exposed to page JS — no Pulp

C++ wiring needed, it rides the choc/gui/choc_WebView.h we already wrap in

core/view/src/web_view.cpp:

from a pointerdown/mousedown handler.

e.detail.paths is the array of absolute paths.

Platform reality: macOS (WKWebView) + Linux (WebKitGTK) — both directions.

Windows (WebView2) — inbound only (outbound is a documented no-op: windowed

WebView2 can't start a drag from web content without moving to composition

hosting). The JS call exists on all platforms for parity.

⚠ Interim source: this lands via an interim fork pin of CHOC

(danielraffel/choc tag pulp-webview-dnd-poc2, carrying WebView drag-and-drop

support; Tracktion/choc pull request 64 is the upstream tracker).

When that support is available upstream, the pin reverts to

Tracktion/choc with no API change. The runnable reference lives in the choc repo

(examples/webview_drag_and_drop.cpp), not in Pulp.

Choose A Loading Mode

  1. Simple inline proof

1.5. Placeholder first paint

platform WebView would otherwise flash white before the real content loads

transparent/native host background

  1. Embedded bundled assets
  1. Directory-backed dev assets

Monaco Guidance

Do not chase Monaco's deprecated AMD path.

Use a prebundled ESM workflow:

Treat raw Monaco source or raw ESM output as build inputs, not as the final

browser payload. Worker and CSS handling belongs to the bundler.

Current proven local recipe:

cd /Users/danielraffel/Code/monaco-editor
npm install
npm run build-monaco-editor

cd /path/to/pulp
node examples/webview-monaco/build_monaco_bundle.mjs \
  --monaco-root /Users/danielraffel/Code/monaco-editor \
  --out-dir /path/to/pulp/build/examples/webview-monaco/dist

cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DPULP_BUILD_WEBVIEW=ON \
  -DPULP_MONACO_BUNDLE_DIR=/path/to/pulp/build/examples/webview-monaco/dist
cmake --build build --target pulp-webview-monaco -j8
./build/examples/webview-monaco/pulp-webview-monaco

Important notes from the working proof:

Window Embedding

WebView backend availability and host embedding availability are separate. A

WebViewPanel can exist even when the surrounding WindowHost or

PluginViewHost cannot accept a native child surface. Always check:

Current host truth:

handles yet

WindowHost::Factory or PluginViewHost::Factory

For palette / inspector style UI:

For standalone native-child embeds, do not size from startup constants once

the host is live. Read WindowHost::get_content_size() for the current

content bounds, attach the child with that size, and keep it in sync via

WindowHost::set_resize_callback(...). examples/webview-monaco/main.cpp

is the current reference pattern.

For plugin-editor embedding, use the view::NativeViewHost widget — do NOT

hand-roll plugin_view_host()->attach_native_child_view(...):

(host->flex().flex_grow = 1.0f to fill), and call

set_native_child(panel->native_handle(), snapshot_fn)

back-reference + Yoga layout, so it works under BOTH a PluginViewHost

(editor) and a WindowHost (standalone). It falls back from

plugin_view_host() to window_host()

(core/view/src/native_view_host.cpp try_attach() / active_viewport_transform())

snapshot capture for free — no on_view_opened/resized/closed plumbing

Native-editor gotchas (G2, learned building `examples/webview-plugin`)

tree.** ViewBridge::close() destroys the whole view tree on editor close

(core/format/src/view_bridge.cpp). A view-owned WebViewPanel is recreated

every close/reopen, discarding the WKWebView's JS heap + page/scroll state. Put

the panel on the Processor (create once, lazily in create_view()); the

NativeViewHost only BORROWS native_handle(). Rule of thumb: *anything that

must survive editor close lives on the Processor.* Pinned by a pointer-identity

test across two open/close cycles in test/test_webview_plugin_example.cpp.

standalone the root is hosted by a WindowHost, not a PluginViewHost

(core/format/src/standalone.cpp), so plugin_view_host() is null and a

hand-rolled attach returns without attaching — the WebView never appears and

nothing errors. NativeViewHost's window_host() fallback is the fix.

so a letterbox-scaled native child does not visually match a scaled Pulp

sibling. WKWebView.pageZoom = scale parity is deliberately DEFERRED (not a

native-editor blocker).

WKWebView's takeSnapshot needs an on-screen window with painted content.

Example/headless tests therefore assert the snapshot ROUTE by equality

(NativeViewHost::capture_native_overlay_png == panel->snapshot_png()), not a

literal non-empty size; the non-empty forwarding guarantee is pinned at the

widget level in test/test_native_view_host.cpp.

For a standalone app that should behave like a single-pane WebView shell:

standalone Editor/Settings chrome entirely

with a dark placeholder so the host opens into the final visual family

the example CMakeLists.txt via pulp_app_icon(...); it stays optional and

should not be wired through the runtime WebView code itself

Validation Loop

For focused local proof:

cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DPULP_BUILD_WEBVIEW=ON
cmake --build build --target pulp-test-webview -j8
./build/test/pulp-test-webview --reporter compact

If example code changed, also build the relevant example target:

cmake --build build --target pulp-webview-palette -j8

Current proof expectations:

Screenshot / Preview Workflow

For quick visual inspection, keep a static browser preview page beside the

runtime assets when useful. That gives you a cheap screenshot path without

pretending the browser preview replaces native validation.

For Monaco specifically:

Headless capture of a native WebView overlay

A WebView is an OS-composited native child view (attach_native_child_view); it

is NOT painted into the Pulp Skia canvas, so a plain headless capture

(render_to_png / a host back-buffer read) of an editor that hosts one sees a

blank where the WebView is. To make a WebView editor self-verifiable headlessly,

the owning Pulp View wrapper must opt in:

  1. call set_contains_native_overlay(true) when it attaches the WebView, and
  2. override capture_native_overlay_png() to forward WebViewPanel::snapshot_png()

(macOS: WKWebView takeSnapshot, no screen-recording permission needed).

The smart capture path (pulp::view::capture_view / `pulp-screenshot --backend

auto / standalone --screenshot`) then returns the in-process WebView snapshot

instead of silently rastering a blank, and refuses with a reason only when no

snapshot is available. Without the flag+override, auto captures a blank overlay

area silently. See examples/webview-plugin WebViewEditorPane for the pattern

and the screenshot skill for the dispatch contract.

Canvas2D bridge gotchas (when the editor is on the @pulp/react native path, NOT WebView)

When porting a WebView editor to the native bridge (translating browser <canvas> + Canvas2D code to pulp's canvas* bridge globals via a JS shim like Spectr's canvas2d-shim.ts), several browser idioms silently break. Authoritative reference is the import-design skill's "Canvas2D Bridge Gotchas" section — see that for the full rule set with example code. Top-of-mind summary:

  1. ctx.arc() does not add to a path — bridge canvasArc strokes immediately. Synthesize as ~32 canvasLineTo segments so ctx.fill() honors the active gradient. Same applies to arcTo, ellipse, roundRect.
  2. Gradient stops must be spread as variadic (color, pos) pairs — passing JSON makes the bridge parse zero stops → silent fall-through to default white fill. canvasSetLinearGradient(id, x0, y0, x1, y1, c1, p1, c2, p2, ...).
  3. Radial gradient bridge takes single outer circle (cx, cy, R), not the spec's two-circle form. Map (x0,y0,r0,x1,y1,r1) → (x1, y1, r1) (visually identical when r0=0, same center).
  4. Per-canvas save_layer isolation — since pulp v0.74.1, ctx.clearRect() on one canvas no longer erases pixels another sibling just painted. Pin SDK >= 0.74.1 for any multi-canvas editor.
  5. SDK version floor for canvas2d parity is v0.74.1 (sibling isolation) on top of v0.72.4 (gradient bridge) + v0.72.5 (gradient fills). Anything older has visible gaps.
  6. Always pixel-sample after rendering — uniform-fallback bugs (every gradient stop resolved to default white) look superficially "filled" at thumbnail scale but are structurally broken.
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.