Skip to content

FF desktop readiness: document-start scripts, host groups, Windows authored origin, fail-closed prebuilt - #36

Merged
wenkaifan0720 merged 2 commits into
mainfrom
feat/ff-desktop-readiness
Sep 22, 2026
Merged

wenkaifan0720 merged 2 commits into
mainfrom
feat/ff-desktop-readiness

Conversation

@wenkaifan0720

@wenkaifan0720 wenkaifan0720 commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Everything the FlutterFlow desktop Test Mode preview and code editors need from flutter_cef on macOS and Windows. It follows the #35 audit.

What changes

  • Document-start scripts: CefWebController(documentStartScripts: [...]) runs each script in every main-frame document before the page's own scripts. Each script runs again after a cross-site navigation. If one throws, the error is reported to the console and the next script still runs.
  • Create-time JS channels: channels registered before create reach the renderer the same way, so the page's first <head> script can post. This removes the OnLoadStart race.
    • Both of these ride in CreateBrowser's extra_info and are installed in OnContextCreated.
  • hostGroup: ephemeral sessions in a group share one cef_host, which exits with the last of them. A profile dir is created only when a host actually spawns.
  • onCreateFailed:
    • CefWebView stops retrying a failed create.
    • The failure reaches onCreateFailed, and so do createFailed and protocolMismatch processGone events. The consumer can then fall back to another web view.
  • Windows parity:
    • Authored documents are served at their real origin (kOpSetAuthoredHtml 0x3f, loadAuthored), so the 2 MB data: cap no longer applies.
    • Document-start (0x41) and host groups work on Windows too.
    • Fix: a dispose racing its own create leaked the browser; it no longer does.
    • Ctrl+C/X/V/A/Z/Shift+Z/Y reach the page first, as on macOS. CefWebView no longer turns them into edit commands; cef_host's OnKeyEvent runs the edit command only when the page leaves the key unhandled. Before this, Monaco's own undo stack and selection handling were bypassed.
    • fetch_cef.ps1 verifies the CEF download against a SHA-1 pinned in the script (fail closed), not one fetched from the same host as the tarball.
    • Protocol is now v4.
  • macOS prebuilt:
    • FLUTTER_CEF_REQUIRE_PREBUILT=1 makes fetch and embed fail closed.
    • A prebuilt whose hash doesn't match the sources is now removed instead of embedded. Before this, it would speak an old protocol.
    • The host keeps only the en locale paks, since CEF runs en-US anyway. That takes it from 311 MB to 262 MB installed, about 12 MB less compressed. The list is configurable via CEF_HOST_LOCALES.
    • Protocol is now v8.

Verification

  • macOS, Flutter 3.47.1, ad-hoc host built from this branch:
    • New example/lib/document_start_probe.dart: 13/13 pass. It covers first document, cross-site document, channel-ready-before-first-script, throw isolation, host group sharing and lifetime, and a 3 MB authored document at a synthetic origin.
    • Regression probes pass: authored_origin_probe, keyboard_shortcut_probe, samesite_probe and multiview_probe.
    • profile_probe's restart-persistence check fails the same way on origin/main with an ad-hoc host, so it is not caused by this PR.
  • Dart tests: 190 pass, including new tests for the create args, onCreateFailed, the no-retry behaviour, and a check that the two copies of document_start.h stay identical.
  • Windows: the host and plugin are compiled by this PR's CI (windows-build), and a Dart test checks that each editing chord reaches the host as a raw key rather than an edit command. Runtime testing on Windows is pending.

After merge

Publish the new host (make publish-cef-host; the source hash changed). Then repin FlutterFlow to the merge SHA.

🤖 Generated with Claude Code

https://claude.ai/code/session_018RfksfS1ncw7gNNtrtNJVa

wenkaifan0720 and others added 2 commits September 22, 2026 11:44
…thored origin, fail-closed prebuilt

What FlutterFlow's desktop Test Mode and code editors need from flutter_cef,
on macOS and Windows.

- documentStartScripts + create-time JS channels. Both are carried to the
  renderer in the browser's CreateBrowser extra_info and installed in
  OnContextCreated, before the page's first script. They are installed again
  after a cross-site navigation. A throwing script is reported to the console
  and the next script still runs. macOS protocol v8, Windows v4 (op 0x41).
- hostGroup: ephemeral sessions in one group share a single cef_host. A
  profile dir is minted only when a host is actually spawned.
- onCreateFailed: CefWebView no longer retries a failed create. The failure is
  also reported for a createFailed or protocolMismatch processGone, so a
  consumer can fall back to another web view.
- Windows serves authored documents at their real origin (op 0x3f,
  loadAuthored), as macOS does, so there is no 2 MB data: cap. The dispose
  op no longer requires the slot, which leaked a browser when a dispose
  raced its create.
- macOS prebuilt: FLUTTER_CEF_REQUIRE_PREBUILT=1 makes fetch and embed fail
  closed. A prebuilt whose hash doesn't match the sources is removed instead
  of embedded. The host bundle keeps only the en locale paks, since CEF runs
  en-US anyway (311 MB -> 262 MB installed, about 12 MB less compressed).

Verified on macOS with Flutter 3.47.1: new document_start_probe 13/13, plus the
authored_origin, keyboard_shortcut, samesite and multiview probes, and 190 Dart
tests. The Windows host and plugin are compiled by CI.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018RfksfS1ncw7gNNtrtNJVa
… digest

CefWebView ran frame Undo/Redo/SelectAll/Copy/Cut/Paste in place of
Ctrl+Z/Y/Shift+Z/A/C/X/V on Windows, so an editor that owns its undo
stack and selection never saw them: in Monaco, undo did nothing and
select-all selected only the hidden textarea. The chords now reach the
page as raw keys, as the macOS ⌘ chords already do. Blink's key bindings
run the edit command when the page leaves the key unhandled, and
cef_host_win gains the macOS host's OnKeyEvent fallback for a key both
left unhandled. A Ctrl chord (not Ctrl+Alt, which is AltGr) is never
treated as text.

fetch_cef.ps1 verified the tarball against a .sha1 fetched from the
same CDN and only warned when it was missing. The digest is now pinned
in the script, and a mismatch fails the build.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018RfksfS1ncw7gNNtrtNJVa
@wenkaifan0720
wenkaifan0720 merged commit f79e163 into main Sep 22, 2026
2 checks passed
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