---
title: "CefSwift"
description: "Build a Chromium browser, or embed Chromium, in a Mac app written in Swift and SwiftUI, on the official prebuilt CEF."
---

CefSwift embeds Chromium in macOS apps written in Swift, through the
official prebuilt [Chromium Embedded Framework](https://github.com/chromiumembedded/cef)
(CEF). You get Chromium's pages, tabs, profiles, extensions, bookmarks and
history as Swift types, without a Chromium checkout or a fork to rebase.

```swift
import CefSwiftUI
import SwiftUI

@main
struct MyApp: CefSwiftApp {
    var body: some Scene {
        WindowGroup {
            CefWebView(url: URL(string: "https://example.com")!)
        }
    }
}
```

Bundle it with `swift package cef bundle --product MyApp` and open
`dist/MyApp.app` ([Install](/start/install)). Gallery: [`ObservableStateDemo`](https://github.com/Rajaniraiyn/CefSwift/blob/main/Examples/Sources/Gallery/Demos/ObservableStateDemo.swift).

## Where to go next

- [Your first browser in 10 minutes](/start/first-browser): a tabbed browser
  with your own SwiftUI tab strip over Chromium's tabs.
- [Choosing a host](/start/choosing-a-host): `CefWebView`, `CefWindow` or
  `CefChromeWindow`.
- [Build with an agent](/start/agents): skills, `AGENTS.md` and `llms.txt`.
- [Known limits](/reference/known-limits) before you commit to it.

## Pre-1.0

CefSwift uses the official prebuilt CEF at the version `CEF_VERSION.json`
pins; custom CEF builds are not supported. Its API can change between
minor releases, so depend on one minor version
(`.upToNextMinor(from: "0.3.0")`).

Task-oriented reference for CefSwift, a library that embeds CEF in any
macOS app and exposes CEF's and Chromium's capabilities to Swift. The core,
`CefKit`, covers the runtime, pages, profiles, views and windows;
`CefSwiftUI` adds SwiftUI; `CefPasskeys` and `CefChromium` are optional
libraries. What a browser product decides (its UI, defaults, when to use a
capability) is the app's: the Browser example in `Examples/` shows one
built this way.

Snippets assume `import CefSwiftUI`, which re-exports `CefKit`; an AppKit
app imports `CefKit` alone (see [In AppKit](/embed/webview#in-appkit)), and passkey and
Chromium-store snippets also `import CefPasskeys` or `import CefChromium`.
The runtime, page, window and profile APIs are `@MainActor`.

- [Starting Chromium](/internals/flags-and-features#starting-chromium)
  - [Configuration](/internals/flags-and-features#configuration)
  - [Languages](/internals/flags-and-features#languages)
  - [Services and privacy](/internals/flags-and-features#services-and-privacy)
  - [System notifications](/ship/signing#system-notifications)
  - [Prompts macOS shows](/ship/signing#prompts-macos-shows)
  - [Keychain access](/ship/signing#keychain-access)
  - [Enterprise policies](/internals/flags-and-features#enterprise-policies)
  - [Signing and capabilities](/ship/signing#signing-and-capabilities)
  - [Preferences](/internals/flags-and-features#preferences)
  - [Relaunching](/internals/process-model#relaunching)
- [Pages](/embed/webview#pages)
  - [Waiting for a load](/embed/webview#waiting-for-a-load)
  - [PDF](/embed/webview#pdf)
  - [Attachments](/embed/webview#attachments)
- [Showing a page](/start/choosing-a-host)
  - [Background](/internals/layering#background)
  - [In AppKit](/embed/webview#in-appkit)
  - [Offscreen rendering](/embed/offscreen#offscreen-rendering)
  - [Animating a page](/embed/animation#animating-a-page)
  - [Title bars in web content](/internals/layering#title-bars-in-web-content)
  - [Tooltips](/embed/webview#tooltips)
  - [Swipe navigation](/embed/swipe-navigation#swipe-navigation)
  - [Offscreen accessibility](/embed/accessibility#offscreen-accessibility)
  - [Keyboard focus](/embed/webview#keyboard-focus)
- [Discarding pages](/browser/discarding-and-sessions#discarding-pages)
- [Lifecycle and energy](/browser/discarding-and-sessions#lifecycle-and-energy)
- [Processes](/internals/process-model#processes)
  - [Unresponsive pages](/internals/process-model#unresponsive-pages)
- [JavaScript](/embed/javascript#javascript)
  - [Frames](/embed/javascript#frames)
  - [User scripts and style sheets](/embed/javascript#user-scripts-and-style-sheets)
  - [Bridge](/embed/javascript#bridge)
- [Decisions](/browser/popups-and-permissions)
  - [Permissions](/browser/popups-and-permissions#permissions)
  - [Built-in sheets](/browser/popups-and-permissions#built-in-sheets)
  - [HTTP authentication](/browser/popups-and-permissions#http-authentication)
  - [Navigation and new windows](/browser/popups-and-permissions#navigation-and-new-windows)
  - [Back and forward](/embed/swipe-navigation#back-and-forward)
  - [Links to other apps](/browser/popups-and-permissions#links-to-other-apps)
  - [Downloads](/browser/downloads#downloads)
  - [File choosers](/browser/downloads#file-choosers)
  - [Passkeys](/browser/passkeys#passkeys)
- [Context menu](/embed/webview#context-menu)
- [Chrome-style windows](/start/choosing-a-host#chrome-style-windows)
  - [Connection security](/browser/address-bar#connection-security)
  - [Client certificates](/browser/popups-and-permissions#client-certificates)
  - [Toolbar and window](/start/choosing-a-host#toolbar-and-window)
  - [Tabs](/browser/tabs#tabs)
  - [Popups](/browser/popups-and-permissions#popups)
  - [Chrome commands](/browser/tabs#chrome-commands)
  - [Chromium's own interface](/browser/find-bar#chromiums-own-interface)
  - [Tabs Chromium opens itself](/browser/tabs#tabs-chromium-opens-itself)
- [Customizing Chromium's own pages](/browser/chrome-pages#customizing-chromiums-own-pages)
- [Profiles](/browser/profiles)
  - [What is configured where](/browser/profiles#what-is-configured-where)
  - [Request filter](/embed/request-filtering#request-filter)
  - [Profile settings](/browser/profiles#profile-settings)
  - [Loading a persistent profile](/browser/profiles#loading-a-persistent-profile)
  - [Network maintenance](/embed/request-filtering#network-maintenance)
  - [Requests through Chromium's network stack](/embed/request-filtering#requests-through-chromiums-network-stack)
  - [Site settings](/browser/popups-and-permissions#site-settings)
  - [Bookmarks, history and suggestions](/browser/bookmarks-history#bookmarks-history-and-suggestions)
  - [Zoom levels, search engines, browsing data and passwords](/browser/profiles#zoom-levels-search-engines-browsing-data-and-passwords)
  - [Chromium's tabs: windows, tabs and groups](/browser/tabs#chromiums-tabs-windows-tabs-and-groups)
  - [Restoring tabs and sessions](/browser/discarding-and-sessions#restoring-tabs-and-sessions)
- [Extensions](/browser/extensions#extensions)
  - [The profile's extensions](/browser/extensions#the-profiles-extensions)
  - [Installing extensions with the app](/browser/extensions#installing-extensions-with-the-app)
  - [Toolbars, popups and the Web Store](/browser/extensions#toolbars-popups-and-the-web-store)
  - [Native messaging hosts](/browser/extensions#native-messaging-hosts)
  - [Trust](/browser/extensions#trust)
- [DevTools](/embed/devtools-and-automation#devtools)
- [Compatibility with bot protection](/embed/devtools-and-automation#compatibility-with-bot-protection)
  - [What a page sees of CefSwift](/embed/devtools-and-automation#what-a-page-sees-of-cefswift)
  - [Features that use the DevTools Protocol](/embed/devtools-and-automation#features-that-use-the-devtools-protocol)
  - [How the app names itself](/embed/devtools-and-automation#how-the-app-names-itself)
  - [Offscreen pages](/embed/devtools-and-automation#offscreen-pages)
  - [Google sign-in](/embed/devtools-and-automation#google-sign-in)
  - [Differences that stay](/embed/devtools-and-automation#differences-that-stay)
- [Serving your own content](/embed/custom-schemes#serving-your-own-content)
  - [Where a handler runs](/embed/custom-schemes#where-a-handler-runs)
  - [Large and streamed bodies](/embed/custom-schemes#large-and-streamed-bodies)
- [Playing streaming services](/browser/streaming-and-drm#playing-streaming-services)
  - [Widevine in Chromium](/browser/streaming-and-drm#widevine-in-chromium)
  - [WebKit and FairPlay](/browser/streaming-and-drm#webkit-and-fairplay)
  - [Services](/browser/streaming-and-drm#services)
  - [System media decoders](/browser/streaming-and-drm#system-media-decoders)
  - [FairPlay in Chromium pages](/browser/streaming-and-drm#fairplay-in-chromium-pages)
- [Shipping updates with Sparkle](/ship/updates#shipping-updates-with-sparkle)
- [Footprint and launch time](/performance/memory#footprint-and-launch-time)
  - [What every bundle does](/performance/startup#what-every-bundle-does)
  - [What the presets turn off](/performance/memory#what-the-presets-turn-off)
  - [Process policy](/performance/memory#process-policy)
  - [Tuning a browser](/performance/memory#tuning-a-browser)
- [Known limits](/reference/known-limits#known-limits)

How CefSwift works inside, and why. For how to use it, see the
[guide](/).

CefSwift is a library for embedding CEF in a macOS app. The core, `CefKit`,
wraps CEF's C API and the Chromium behavior an embedder has to work with or
around; the other modules and the examples build on it:

| Where | What | Examples |
|---|---|---|
| `CefKit` (core) | What any app embedding CEF needs and could not write itself: the runtime, pages, profiles, the AppKit host views, CEF Views windows (`CefWindow`), handlers and delegates, offscreen rendering and its accessibility, discarding | `CefRuntime`, `CefPage`, `CefProfile`, `CefOffscreenPageView`, `CefWindow` |
| `CefSwiftUI` | SwiftUI on top of `CefKit`, nothing else | `CefSwiftApp`, `CefWebView`, `setToolbar`, `setPageOverlay` |
| `CefPasskeys`, `CefChromium` (optional) | Capabilities on Chromium internals some apps want: passkeys the app answers; Chromium's bookmark, history and suggestion stores, its extensions, its tabbed windows and tab strip, and its bubbles | `CefPasskeyController`, `CefBookmarks`, `CefExtensions`, `CefChromeWindow`, `CefTabs`, `CefChromiumSurface` |
| `CefBundling`, `cefswift`, `CefPlugin` | Build time: the app bundle, its helpers, signing and checks | `swift package cef bundle`, `Scripts/xcode-embed.sh` |
| `Examples` | Product decisions written against the public API: UI, defaults, heuristics for when to use a capability | the Browser's tab rail, toolbar, swipe indicator, Memory Saver, permission names |

The rule: the library holds what an app cannot write against its public
API, because it calls the CEF C API, hooks Chromium or works around a CEF
or Chromium limit, plus the defaults an embedder cannot ship without: the
built-in sheets and presenters that answer a delegate method nobody
implemented, each replaceable. Everything else belongs to the app.

## Modules

```
CefSwiftUI   CefSwiftApp, CefWebView (over CefKit's host views), SwiftUI modifiers,
    │        CefWindow.setToolbar, setTabAccessory and setPageOverlay
    │  CefPasskeys  optional: CefPasskeyController (a CefPageAttachment), passkey
    │     │         stores and the passkey sheet
    │     │  CefChromium  optional, bound to the pinned CEF: CefBookmarks, CefHistory,
    │     │     │         CefAutocomplete, CefExtensions, CefTabs, CefChromeWindow,
    │     │     │         CefTab and CefTabGroup (on CefKit's service hosts);
    │     │     │         CefChromiumSurface, chromiumSurfacePolicy and their SwiftUI
    │     │     │         glue (on Chromium's AppKit classes)
CefKit       CefRuntime, CefPage, CefWindow, CefPageDelegate, CefBridge,
    │        CefDevTools, CefProfile, CefPageAttachment, configuration and policy types; the AppKit
    │        host views CefWindowedPageView and CefOffscreenPageView
    │        (with its compositor and accessibility elements), the internal
    │        service hosts and tab discarding, no SwiftUI
CCef         vendored CEF C headers, the generated bridge, the runtime loader (C)

CefBase      reference counting, strings and process messages, shared by
             CefKit and the helper (no Foundation, no AppKit)
CefRenderer  renderer-side features (bridges, user scripts, evaluation) on
             the V8 API, run by the helper
CefHelper    the helper-process executable (product cefswift-helper)
CefHelperStartup  the helper's startup library (product cefswift_helper_startup),
             which seals the sandbox before the framework's code runs

CefBundling  the bundle: framework, helpers, Info.plists, entitlements,
             signing, cef doctor (Foundation only)
cefswift     the command-line tool over CefBundling (Sources/CefSwiftTool),
             run by the plugin and by the Xcode build phase
CefPlugin    swift package cef download | bundle | info | clean | doctor |
             package | notarize; builds the product, the helper and its
             startup library with SwiftPM and runs cefswift
```

### Extension points

CefKit names no optional feature. An optional module, such as
CefPasskeys or CefChromium, plugs into it at these points:

- `CefPageAttachment` (public), through `CefProfile.attachments` (every
  page of a profile, Chromium's own included) and
  `CefPage.Configuration.attachments`: told when Chromium has created a
  page (`pageDidCreate(_:)`), when a discarded one is created anew
  (`pageDidRestore(_:)`) and when it closes (`pageDidClose(_:)`). An
  attachment whose `preparesBeforeFirstDocument` is `true` holds the first
  page: the page starts on `about:blank`, `CefPage.bootstrap()`
  awaits every attachment with the task-local `settingUp` set (so their
  DevTools calls do not wait for `ready()`), and only then loads the page.
  Without such an attachment nothing is held: `adopt(_:)` completes
  `ready()` and then tells the attachments, in a task, so that one
  attachment cannot delay every page.
  Such a page's native popups are opened in a page CefKit creates
  (`openPopupInNewPage`), since Chromium runs a native popup's first
  document before anything can attach to it.
- `CefProfile.moduleState(_:make:)` (package): one object per type that a
  module keeps for a profile, made on first use.
- `CefWindow.moduleState(_:make:)` and `existingModuleState(_:)`
  (package): the same for a `CefWindow`. A state object that is a
  `CefWindowParticipant` is told when the window is destroyed
  (`windowDidClose(_:)`).
- `CefWindow.addChromeCommandInterceptor(_:)` (package): decides
  Chrome commands in every `CefWindow`, from Chrome's UI and from
  `CefPage.execute(_:disposition:)`, after the page's delegate and
  before Chromium runs them.
- `CefWindow.Configuration.moduleValues` (package): values a module
  keeps in a window configuration, by type, dropped for the window's
  popups; `showsChromiumStatusBubble` and `showsChromiumZoomBubble`
  (package) set the page's `chrome_status_bubble` and
  `chrome_zoom_bubble`. CefChromium's status bubble uses the public
  `pageOverlay`.
- The internal service hosts (package): `CefServiceHosts`
  (`CefProfile.serviceHosts`), `CefServiceHost` and `CefServiceHost.Module`. A module
  declares its own hosts and modules and calls them
  ([Internal-page services](/internals/mojo-services#internal-page-services)).

Inside CefKit, an object holding CEF references outside any page is a
`CefShutdownParticipant`: it adds itself with
`CefRuntime.addShutdownParticipant(_:)`, held weakly, and is told to
release them after the last page and window and before the profiles'
request contexts and `cef_shutdown()`. The service hosts (a module's
included) and the media router are participants.

A module also uses a few `package` members of CefKit that are not public
API: `CefDevTools.addListener(for:_:)`, `removeListener(_:for:)` and
`leaseCount(_:)` (synchronous, ordered event listeners and domain leases),
`CefPage.decision(_:_:)` with `CefPage.DecisionScope` (a question
cancelled when its page or document goes), `CefDialogPresenter.run(_:in:)`
(an alert that dismisses itself on cancellation), `CefLog`,
`CefWindow.owning(_:)`, `CefProfile.storageDirectory` (now public), and `CefObjCHook`
for overrides of Chromium's AppKit classes.

**CefChromium** wraps Chromium's own browser features, which are bound to
Chromium-private interfaces of the pinned CEF: its stores
(`profile.bookmarks`, `history` and `autocomplete`, kept weakly in the
profile's module state) and the surfaces of Chrome-style windows
(`window.chromiumSurfacePolicy`, kept in the window's module state). It depends on
CefKit and on CCef and CefBase for Chromium's command and string
identifiers. Its surface handling starts on the first use of its window
API: that installs the AppKit overrides and the command interceptor once,
for every window, and a window's state, made on first use or when
Chromium first attaches a child window to it, takes up the surfaces
already attached. Until then Chromium's interface shows natively, as
without the module.

**CefProtectedMedia** is FairPlay Streaming in Chromium pages
([guide](/browser/streaming-and-drm#fairplay-in-chromium-pages)), built only on CefKit's
public API: a `CefBridge` (`cefswiftFairPlay`, access limited to the listed
origins), a `CefUserScript` for those origins' top frames, and a
`CefPageAttachment` that ends a page's session when it closes.

```text
page (listed origin, main frame)  fairplay.js: EME for com.apple.fps, catches the playlist and certificate
  │  bridge: open / license / control / close        frame and origin established by the browser process
app (CefFairPlay)                 checks origin, frame, sizes; CefFairPlayPlaylist: https segments, skd/https keys
  │  NSXPCConnection, both ways
<App> FairPlay.xpc                AVPlayer + AVContentKeySession; playlist served by a resource loader
  │  keyRequest (SPC) ──▶ page's license server ──▶ license (CKC)      state ──▶ element mirrors it
```

The service is an XPC service of its own (`Sources/CefFairPlayService`,
product `cefswift-fairplay`) in the App Sandbox with outgoing connections
only, separate from the media decoders' service, which has no network.
One service process holds every page's session (at most eight); the app
names a session by the page and the page's own session name.
