DevTools and automation
Input events for any page, the DevTools window, the DevTools Protocol in-process, and what a page can tell about CefSwift.
try await page.devTools.send("Emulation.setDeviceMetricsOverride",
["width": 390, "height": 844, "deviceScaleFactor": 3, "mobile": true])
page.showDevTools()
Gallery: DevToolsDemo, InputEventsDemo.
Input events
CefPage sends clicks, keys, scrolls and gestures straight to a page’s
web content, with CEF’s portable input events. The same calls drive a
windowed page, a Chrome-style one and an offscreen one, with no AppKit
events, no DevTools session, and events the page sees as trusted
(isTrusted), so automation and agents can drive any page:
page.hostViewDidBecomeKey() // keys go to the focused page
page.click(at: CGPoint(x: 120, y: 105)) // points from the view's top-left
page.typeText("Ada Lovelace")
page.press(.enter)
page.press(CefKeyboardInputEvent.Key("a"), modifiers: [.command])
page.scroll(at: CGPoint(x: 200, y: 200), by: CGVector(dx: 0, dy: -300)) // down
// One event at a time, with every field:
page.send(CefMouseInputEvent(.down, at: CGPoint(x: 10, y: 10), button: .right, clickCount: 1))
page.send(CefGestureInputEvent(.pinchUpdate, at: CGPoint(x: 200, y: 200), scale: 1.1))
- Positions are points from the top-left of the page’s view. The screen position each event also carries is worked out from the view’s window.
- Keys carry their identity and text as they are (Chromium’s DOM code and
DOM key), so the result does not depend on the Mac’s keyboard layout.
typeText(_:)sends a key down, a character and a key up per character; a US keyboard’s key for it givesKeyboardEvent.code.CefKeyboardInputEvent(_:)converts anNSEventwith Chromium’s own mapping and the current layout. - Events go to web content only: no AppKit control, menu or input method
sees them. Command-A reaches the page’s key listeners, and does not
select all, which on the Mac is the Edit menu’s work; use
selectAll(). - Chromium routes input by hit-testing what the page has drawn, and drops events sent before the page’s first frames.
How long events take to reach a page is in Portable input events, measured.
The offscreen methods (sendMouseMove(to:modifiers:) and the rest, see
Offscreen rendering) remain for hosts that
forward AppKit events to an offscreen page.
Portable input events, measured
CEF’s API version 15800 sends input to web content directly
(send_mouse_event, send_keyboard_event, send_wheel_event,
send_gesture_event). Measured on 2026-11-29 (CEF 158.0.6, M2, macOS
27.2.1, three runs of SELFTEST_TIMINGS=1 SELFTEST_ONLY=input), from
sending the first event in Swift to the page’s event, on the wall clock
both processes share:
| Page | 6 key presses (17 events) → last input event |
A wheel event → first scroll event |
|---|---|---|
| Windowed | 1.0–1.7 ms | 2.1–22.8 ms |
| Chrome style | 1.0–1.3 ms | 9.9–23.7 ms |
| Offscreen | 1.0–1.3 ms | 7.4–18.2 ms |
Key events are delivered without waiting for a frame; a scroll waits for
the compositor’s next frame, which is most of the spread. Events sent
before a page has drawn its first frames are dropped: the first SelfTest
run, which clicked right after the load finished, saw the click lost in
windowed and offscreen pages and kept in a Chrome-style one, so the
checks wait for two animation frames first. A wheel’s scroll animates on
the compositor and can outlive a page’s own scrollTo: on CI’s virtual
Mac it moved the page down again after scrollY read 0, and a tap sent
then landed beside its target, so the tap check waits for scrollend and
ten frames at the top.
DevTools
page.devTools speaks the
Chrome DevTools Protocol
in-process, without a debugging port:
try await page.devTools.send("Emulation.setDeviceMetricsOverride",
["width": 390, "height": 844, "deviceScaleFactor": 3, "mobile": true])
try await page.devTools.send("Network.enable")
for await event in page.devTools.events("Network.responseReceived") {
print(event["response"]["url"].stringValue ?? "")
}
send(_:_:) waits for the page to be created and returns the result as
CefJSON; send(_:_:as:) decodes it. A protocol error throws
CefDevToolsError. events(_:bufferingPolicy:) streams one event’s
parameters until the page closes or the consuming task is cancelled;
enable the event’s domain first. A consumer that falls behind keeps the
newest 1,000 events (CefDevTools.defaultEventBuffering); pass
.unbounded to keep every one.
Typed commands
A CefDevToolsCommand is a command with typed parameters and a typed
result, and a CefDevToolsEvent an event with typed parameters. CefKit
declares the commands an agent or an automated browser needs to see and
drive a page, under CefDevTools: Page.CaptureScreenshot,
Accessibility.GetFullAXTree, DOMSnapshot.CaptureSnapshot and
Input.DispatchMouseEvent, DispatchKeyEvent and InsertText. Input
reaches windowed and offscreen pages alike, in CSS pixels from the
viewport’s top left.
let devTools = page.devTools
// What the page shows, as assistive apps see it.
let tree = try await devTools.send(CefDevTools.Accessibility.GetFullAXTree())
let buttons = tree.nodes.filter { $0.role == "button" }
// Where things are, with every frame's nodes and their bounds.
let snapshot = try await devTools.send(CefDevTools.DOMSnapshot.CaptureSnapshot())
// Click, then type.
for kind in [CefDevTools.Input.DispatchMouseEvent.Kind.pressed, .released] {
try await devTools.send(CefDevTools.Input.DispatchMouseEvent(
kind, at: CGPoint(x: 160, y: 100), button: .left, clickCount: 1))
}
try await devTools.send(CefDevTools.Input.InsertText("hello"))
let screenshot = try await devTools.send(CefDevTools.Page.CaptureScreenshot(format: .jpeg, quality: 70))
Declare any other command or event the same way:
struct RequestWillBeSent: CefDevToolsEvent {
static let method = "Network.requestWillBeSent"
struct Request: Decodable, Sendable { var url: String }
var request: Request
}
try await page.devTools.send("Network.enable")
for await event in page.devTools.events(RequestWillBeSent.self) {
print(event.request.url)
}
A typed command’s parameters are encoded once into the message, and its
result is decoded straight from the reply’s bytes, as with
send(_:_:as:), with no CefJSON tree in between. A typed event stream
decodes each event from Chromium’s buffer the same way, and an event
that does not decode is dropped and logged. The saving is small next to
what Chromium does: decoding a reply holding a 4 MB image took 14.8 ms
typed against 15.9 ms through CefJSON and Data(base64Encoded:), and a
whole-page PNG of a 1600 × 1000 window at 2× took about 210 ms either way,
nearly all of it Chromium’s (median of 12 and 15 runs, release build, M2,
macOS 27.2.1 on AC power with other builds running, CEF 158.0.6, 2026-11-28).
DOMSnapshot bounds are in device pixels, CSS pixels times
window.devicePixelRatio (2 on a Retina display, and more when the page
is zoomed); divide by it for the coordinates Input takes.
page.showDevTools() opens the DevTools window, and
showDevTools(inspecting:) inspects the element at a point in view
coordinates.
Compatibility with bot protection
Sites behind bot protection read what a page can observe about the browser
and compare it with what stock browsers show. A CefSwift browser is the
browser a person is using; this section lists what CefSwift itself adds
that a page can observe, the settings that decide how the app names itself,
and the differences from Google Chrome that come with CEF.
Scripts/compat-matrix.py measures all of it against local and public
test pages, in each kind of host, with each feature on by itself, and in
Chrome for comparison.
What a page sees of CefSwift
Nothing, for a page that uses no bridge, user script or DevTools
feature: no global, no injected script, no DevTools session, and
navigator.webdriver is false. No preset passes a switch that sets it
(--enable-automation, --headless, --remote-debugging-pipe,
--remote-debugging-port=0); remoteDebuggingPort does not either, but
it opens a debugging port to anything on the machine, so leave it nil in
shipping apps.
Bridges, user scripts and evaluateJavaScript(_:) run in the helper’s
renderer code with the V8 API, without the DevTools Protocol. A page sees
a bridge’s global, where access allows it, and what a user script or an
evaluated script does, and nothing else: the bridge’s functions are native
functions, and scripts leave no sourceURL. A script that returns a
promise is awaited through the promise’s then, which the page could
replace.
Features that use the DevTools Protocol
These attach devTools to the page. CEF keeps the session attached
until the page closes. An enabled domain can be seen. A session with no
domain enabled showed no difference in what Scripts/compat-matrix.py’s
probe page reads (Scripts/compat/probe.html: whether console calls
read an Error’s properties, the time to log a large object, the time a
debugger statement takes, automation globals, navigator.webdriver,
window geometry, focus and visibility, animation frame rate, plugins,
client-hint brands, codecs, WebGL, permissions, voices, media devices),
measured with CEF 156.0.28 on 2026-11-13 in a windowed and an offscreen
page. That is what those probes found, not a guarantee about every
measurement a page can make.
| Feature | What attaches | What a page can observe |
|---|---|---|
page.devTools |
Whatever you send; CefKit’s features share the session, and a domain stays enabled until every X.enable sent through it has had its X.disable |
Runtime.enable makes every console call serialize its arguments: logging a large object takes 2–3 times as long. Debugger.enable stops the page at debugger statements. Page.enable, Network.enable and the like: nothing measured. |
services.systemMediaDecoders = .audio |
The media shim, in every document’s main world, before its scripts | In Scripts/compat-matrix.py (windowed and offscreen, CEF 158.0.6), only the AAC answer differs: canPlayType says probably for AAC where the other cells say "". The replaced functions print as native code but are constructible and have a prototype (System media decoders). |
CefPasskeys’ CefPasskeyController |
WebAuthn, Debugger, Page and Runtime, for the page’s lifetime |
Each debugger statement takes about 10 ms (the controller resumes at once), and console calls serialize their arguments as above. Leave passkeys to Chromium (no controller) for pages that show sites you do not control. |
evaluateJavaScript(_:userGesture: true) |
Runtime.evaluate, no domain |
The gesture itself. |
snapshot() of a windowed page |
Page.captureScreenshot, no domain |
Nothing measured. An offscreen page’s snapshot is the frame its view shows, with an open <select> list or date picker drawn in, and uses no protocol. |
discard(), discardBlockers() |
DOMDebugger.getEventListeners on every frame’s window, reached with Runtime.evaluate, Page.getFrameTree and DOM look-ups, and for a cross-site frame a session attached with Target.attachToTarget and detached again; no domain |
Nothing measured; the page is about to be unloaded. |
profile.clearSiteData(for:types:) |
Storage.clearDataForOrigin in one of the profile’s live pages, no domain |
Not measured; the page it runs in may be on another site. |
| Offscreen accessibility actions | Accessibility for the length of one lookup; DOM.focus, DOM.scrollIntoViewIfNeeded; Input.insertText only for a field that takes no input-method text |
Nothing measured. Only an assistive app’s actions use it. |
CefKit’s internal services (tab discarding, and CefChromium’s bookmarks, history and suggestions) run in hidden pages that show Chromium’s own pages, and attach no DevTools session.
How the app names itself
CefRuntime.Configuration.userAgent sets the User-Agent header and
navigator.userAgent:
| Choice | User-Agent |
Client hints |
|---|---|---|
.chromium (default) |
… AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36 |
All |
.appendingProduct("MyApp/1.0") |
… Chrome/158.0.0.0 MyApp/1.0 Safari/537.36 |
All |
.replacingProduct("MyApp/1.0") |
… (KHTML, like Gecko) MyApp/1.0 Safari/537.36 |
All |
.custom("…") |
That string | Low-entropy ones only: getHighEntropyValues() returns no versions or architecture |
The client hints (Sec-CH-UA and navigator.userAgentData) name the
brands Chromium and a GREASE brand, as every Chromium build does; Chrome
adds Google Chrome. CEF has no setting for them. The DevTools Protocol’s
Emulation.setUserAgentOverride changes them per page, at the cost of
an attached session. Sites look for an engine they know in the
User-Agent, compare it with the client hints, and compare both with what
the page can measure; a User-Agent that names another browser than the
one running fails those comparisons.
Offscreen pages
An offscreen page reports the window it is shown in: screenX,
screenY, outerWidth and outerHeight are the window’s,
screen.availWidth and the like leave out the menu bar and the Dock,
screen.colorDepth and devicePixelRatio are the display’s, and
document.visibilityState follows whether the view can be seen. Pages lose
focus when the view stops being first responder in the key window, as in a
browser window. CefOffscreenViewInfo carries these values; a custom
CefOffscreenHost should fill in all of them. Chromium times the frames
itself at the page’s frame rate (.offscreen(frameRate:), 60 by
default), so requestAnimationFrame runs as often as in a window.
Google sign-in
Google refuses sign-in from browsers it takes for embedded ones, with
“Couldn’t sign you in: This browser or app may not be secure”. CefSwift
adds nothing to a Chrome-style page that a page can observe (above), and
no preset passes a switch Google’s check looks for: no
--enable-automation, no debugging port, and navigator.webdriver is
false.
Measured with CEF 158.0.6 on 2026-11-28, without credentials, with the
Compat example (-url https://accounts.google.com/ -script Scripts/compat/google-signin.js), which types an address into the
identifier step and presses Next.
| Host, preset | Identifier step |
|---|---|
CefWindow, .chrome |
Account lookup (“Couldn’t find this account” for an address that has none) |
CefWindow, Configuration() |
Same |
CefWebView windowed, .embedded |
Same |
CefWebView offscreen, .embedded |
Same |
No host got the “may not be secure” page at the identifier step. After six tries in ten minutes from one address, Google asked every host for a CAPTCHA (“Type the text you hear or see”), as it does for any browser that signs in repeatedly. Without an account the measurement stops before the password step, where Google can still refuse a browser. Not measured, but each changes what the sign-in page sees and so could change Google’s answer:
- A
.customuser agent, which drops the client hints’ versions, or one that names another browser than the one running. - DevTools Protocol features attached to the page, such as
CefPasskeyController(Debugger,Runtime), andremoteDebuggingPort. - Bridges or user scripts that change what the sign-in page reads.
Sign in to Google in a Chrome-style page with none of them, on the
.chrome preset.
Differences that stay
These come with CEF and Chromium as CefSwift uses them; no setting of CefSwift’s changes them, and some need a different Chromium build:
- Client hint brands:
Chromiumand noGoogle Chrome, as above. - Codecs: CEF’s standard builds have no H.264, AAC or HEVC, so
canPlayType('video/mp4; codecs="avc1.42E01E"')returns""where Chrome returns"probably". Adding them takes a CEF build withproprietary_codecsand the licenses that come with them. The experimentalservices.systemMediaDecodersanswers"probably"for AAC and the other system audio codecs with.audio, and for H.264 and HEVC with.video; System media decoders lists what else a page can tell from it. - Google services: no Google network voices for speech synthesis (Chrome lists about 20 more), no Safe Browsing, sync or Chrome’s own browser sign-in. Signing in to Google’s sites is another matter; see Google sign-in.
- Alloy style (
CefWebView): CEF answers Chromium’s media permission check with “allowed”, sonavigator.mediaDevices.enumerateDevices()lists every camera, microphone and speaker before the user grants anything, where Chrome lists one of each kind. Chrome-style pages (CefWindow) list what Chrome lists. Browse the web inCefWindow. - The window:
outerHeight - innerHeightis your window’s title bar and toolbar, not Chrome’s; it is what the window is.