Skip to content

CefSwift 0.2.0

Choose a tag to compare

@github-actions github-actions released this 15 Nov 17:39
· 53 commits to main since this release

CefSwift 0.2.0 is a rewrite. It is now a general library for embedding Chromium in macOS apps: an app shell whose sections are web pages, a web browser, or any app that shows web content. It uses the official prebuilt CEF 156.0.28 (Chromium 156.0.8078.88).

The Browser example

Requirements

  • macOS 14 or later. Swift 6.1 or later (CI builds with 6.1).
  • Add it with .package(url: "https://github.com/Rajaniraiyn/CefSwift", .upToNextMinor(from: "0.2.0")). Before 1.0 the API can change between minor versions.

Breaking changes

Every public name changed; there is no compatibility layer. Apps on 0.1.0 need porting:

  • The three view types of 0.1.0 are replaced by one observable CefPage, shown by CefWebView in SwiftUI, by CefWindowedPageView or CefOffscreenPageView in AppKit, or by a Chrome-style CefWindow.
  • CCefAppKit and cef-helper are gone. The helper is built and bundled for you.
  • Apps are bundled with swift package cef bundle or the Xcode Run Script phase, which both run the cefswift tool.

The guide and the examples show the new API.

Modules

Module What it is
CefKit The core: runtime, pages, profiles, delegates, AppKit page views, CefWindow, offscreen rendering, discarding
CefSwiftUI SwiftUI on top of CefKit: CefSwiftApp, CefWebView, toolbar and overlay modifiers
CefChromium (optional) Chromium's own features: bookmarks, history, autocomplete, extensions, Chromium's tabbed windows (CefChromeWindow, CefTabs), and its bubbles and dialogs
CefPasskeys (optional) WebAuthn requests answered by the app from its own store
cefswift, swift package cef … Download CEF, then assemble, sign, check, package and notarize the app

What's new

  • Hosting: windowed and offscreen page views in AppKit and SwiftUI, and Chrome-style windows. Pages keep drawing under SwiftUI animations and layer transforms. The page canvas is white by default, with transparency opt-in.
  • Pages: a typed JavaScript-to-Swift bridge and user scripts run as native V8 functions, with no DevTools session. Also: navigation decisions that know the frame, JavaScript per frame, the frame tree, awaitable loads, PDF, find, and the DevTools protocol.
  • Profiles: persistent profiles are real Chromium profiles on disk, and incognito profiles are available. A profile owns the request filter, scheme handlers, user scripts, bridges, permissions and download destination, and a page can override each. Profiles also carry cookies, typed preferences and site settings. URLRequests go through Chromium's network stack.
  • Decisions: permissions, sign-in, client certificates, JavaScript dialogs, file choosers and unresponsive pages are async delegate methods, each with a localized built-in sheet you can replace.
  • Downloads and context menus: a download policy, a replaceable save panel and observable downloads. Context menus are values you edit, with typed commands, shown as an NSMenu in every hosting mode.
  • Resources: discard() and restore(), blocked by audio, form input or beforeunload, as read from Chromium's page graph. Lifecycle state and a task manager.
  • Tabs (CefChromium): CefTabs mirrors and drives Chromium's own tab model, so the app can draw its own tab UI. It opens, closes, moves, pins and groups tabs, and moves them between windows. ⌘⇧T reopens closed tabs and windows, and a previous session can be restored after relaunch.
  • Extensions (CefChromium): a store per profile, with Chrome Web Store installs, install by ID (also on first run), bundled and unpacked installs, toolbar actions with popups, new-tab overrides and extension menu items. CefSwift ships no extension of its own.
  • Offscreen: the macOS accessibility tree, IME, drag and drop, native tooltips, and copies of only the changed part of each frame.
  • Bundling: SwiftPM and Xcode share one tool. It includes cef doctor, locale trimming and notarization, and reports App Sandbox as an error.

Examples

Examples/ has a Gallery of 30 single-file demos, a Browser built from removable feature folders with a SwiftUI tab rail over Chromium's tabs, and the Minimal, Compat, SystemEngine, SelfTest and Xcode samples.

Known limits (CEF 156)

  • A window holds one Chrome-style view, so CefWindow has one tab. Only CefChromeWindow has real tabs and tab groups.
  • CEF restores nothing at startup; CefSwift restores sessions itself.
  • Chromium's RemoteCoreAnimationAPI feature is off by default. On macOS 27.2 it leaves pages Chromium draws invisible.
  • No proprietary codecs; Widevine L3 only.

Testing

542 unit tests, also under Thread and Address Sanitizer, and 37 example tests. 108 documentation samples compile. SelfTest runs 1356 checks against real Chromium, and 1350 pass. The remaining 6 check documented limits. CI runs all of it on every change.

Full changes: #25 · v0.1.0...v0.2.0