Skip to content
CefSwift
Esc
↑↓navigate↵open⌘Jpreview
On this page

The C bridge

How CefKit calls CEF's C API: the generated bridge, the runtime loader, and where Swift meets C++.

Scripts/generate-bindings.py           # regenerate the C bridge
Scripts/generate-bindings.py --check   # fail if it is out of date, as CI does

The C bridge

CefSwift calls CEF through its C API and resolves every function at run time, so the Swift modules build without the framework.

  • Scripts/generate-bindings.py runs the C preprocessor over the vendored headers at the CEF_API_VERSION pinned in ccef_config.h and writes two files: ccef_capi.h, which includes the whole C API, and ccef_symbols.h, which lists every exported cef_* function the pinned version declares.
  • ccef_loader.c expands that list into trampolines with CEF’s own function names. Each one looks itself up with dlsym on its first call, so Swift calls cef_initialize(...) directly and unused functions cost nothing.
  • At start-up CefRuntime dlopens the framework from the app bundle and compares cef_api_hash with the hash the headers define for the pinned version. A framework that does not match fails with CefError.apiHashMismatch instead of misbehaving.
  • In a bundle from cef bundle, the app executable also links the framework, weakly, so dyld loads it at launch and dlopen returns the library already loaded. See Loading the framework at launch.
  • ccef_net_error.c names Chromium’s network errors from the vendored cef_net_error_list.h (ccef_net_error_name(-105) is "NAME_NOT_RESOLVED"), without the framework.

Because the API version is pinned, CEF binaries update without changes to the Swift code. Adopting newer C APIs is a separate step that moves the pin (automation).

Swift and C++

CEF’s binary distribution exports its C API from the framework: about 240 cef_* functions, which return the structs of function pointers the rest of the API is made of (nm -gU on the framework lists 2,548 symbols; the others are V8’s debugger helpers (_As_*), Chrome’s app-mode entry points and allocator shims). CEF’s C++ API (CefRefPtr, CefV8Value and the rest) is a set of headers and the libcef_dll_wrapper static library, which wraps that same C API. Chromium’s own C++ (content/, chrome/, Blink, V8’s API) is neither exported nor shipped as headers. So Swift’s C++ interoperability would reach nothing that importing the C API does not, and would add the wrapper’s build; CefSwift imports the C API directly.

What reaches further into Chromium is, in the renderer, the V8 and DOM APIs (cef_v8*, cef_domdocument_t, cef_frame_t) through the helper’s render process handler; in the browser process, Chromium’s Objective-C classes (Chromium’s AppKit classes), the Mojo interfaces of its WebUI pages (Internal-page services), the DevTools Protocol, and preferences and command-line switches.

The renderer side makes these possible without the DevTools Protocol, each as a CefRendererExtension: native bridges in every frame, cross-site ones included; JavaScript functions that call Swift synchronously; reading a document through cef_domdocument_t visitors without running script; a context’s V8 heap statistics; and per-frame features that start before a document’s first script.

Strings, scheme bodies and DevTools events

Measured the same way, 2026-11-13, before and after builds back to back (-benchmark requests, devtools; nine and two runs):

  • A string going into CEF was copied into an Array of UTF-16 units and then into a heap buffer; it is transcoded once into a stack buffer. The request filter’s own work around the filter (three strings out, two URLs parsed, headers in) took 3.1–4.9 µs a request before and 2.9–3.4 µs after: parsing the URL dominates; the referrer is parsed only when a filter reads it.
  • A 200 MB .file body was read in 256 KB Data chunks on CefFileActor and copied from them into Chromium’s buffer; it is read with pread(2) straight into Chromium’s buffer. Total time (242–339 ms before, 280–284 ms after), peak footprint (+13–15 MB, +12–15 MB) and app CPU (220–328 ms, 222–234 ms) did not change measurably: Chromium’s own work on the body sets them. What changed is one copy and one allocation per 256 KB fewer, and no actor hop per chunk.
  • 20 000 DevTools events nobody listens to: CefKit copied each event’s parameters before looking for a listener; it looks first. 8.0–8.2 allocations an event on the main thread before, 6.0–6.3 after; CefKit’s own time stayed at 0.9–1.0 µs an event.

The Minimal example’s footprint (measure-footprint.py, median of five relaunches) is 88.5 MiB after these changes, as before (88 MiB). The web-compatibility probe (compat-matrix.py probe, rows nothing, bridge and evaluateJavaScript in the windowed, offscreen and window hosts) reads the same with the wire transport as without a feature, except for the bridge’s own global.

Was this page helpful?