ReadonlycanWhether the web view can navigate back in history
ReadonlycanWhether the web view can navigate forward in history
ReadonlyestimatedThe estimated loading progress from 0.0 to 1.0
ReadonlyisWhether the web view is currently loading a page
ReadonlytitleThe title of the current page
ReadonlyurlThe URL of the current page, or null if no page is loaded
Enable or disable the macOS back/forward trackpad swipe gestures
Gestures are enabled by default. Pass false to disable them.
Pass false to disable back/forward swipe gestures
Self for chaining
Control whether the web page background is visible
Pass false to make the web view background transparent. Enabled (visible) by default.
Pass false to hide the web content background
Self for chaining
Execute JavaScript in the web page and deliver the result to a callback
The script is not evaluated as an expression: it runs as the body of an async
function, and the result is the value it returns. Use return to send a value
back — a script without one, such as "document.title", gives a result of null.
Because the function is async, the script can use await, and if it returns a
Promise the callback gets the value the Promise resolves to.
The result is copied out of the page, so it must be a number, string, boolean,
array, plain object, null or undefined (which arrives as null). Anything else,
such as a DOM element or a function, is delivered as an error.
If the script throws, or returns a Promise that rejects, the error is the page's own
message for it, such as "Error: boom" or "SyntaxError: Unexpected token '}'".
The JavaScript function body to run, which should return the result
Called with the result or an error message
Self for chaining
Execute JavaScript in the web page without capturing the result
The script runs as the body of an async function, so it can use await.
The JavaScript function body to execute
Self for chaining
Enable or disable the Safari Web Inspector for this web view When enabled, the web view appears in Safari → Develop menu.
Pass true to enable the Web Inspector
Self for chaining
Enable or disable link preview popovers shown on force-click
Link previews are enabled by default. Pass false to disable them.
Pass false to disable link previews
Self for chaining
Load an HTML string directly into the web view
The HTML content to display
Self for chaining
Load a URL in the web view
The URL to load (e.g. "https://apple.com")
Self for chaining
Enable or disable the trackpad pinch-to-zoom magnification gesture
The gesture is enabled by default. Pass false to disable it.
Pass false to disable pinch-to-zoom
Self for chaining
Register a callback that fires when loading state or progress changes
Called whenever isLoading, url, title, or estimatedProgress changes.
Called with current loading state
Self for chaining
Let the page send messages to a callback
Adds webkit.messageHandlers.<name> to the page, for this and every later page the web
view loads. When the page calls webkit.messageHandlers.<name>.postMessage(body), the
callback is called with body, and the Promise postMessage() returns settles with the
The body and the result can be strings, numbers, booleans, null, dates, and arrays and
plain objects of those. Calling this again with the same name replaces the callback.
The handler name the page uses, as in webkit.messageHandlers.<name>
Called with each message the page sends. Its result is the reply
Self for chaining
Register a callback that fires when navigation to a new page completes
Called with the final URL
Self for chaining
Register a callback that controls whether navigation is allowed
Called before each navigation. Return true to allow or false to block.
Return true to allow, false to block
Self for chaining
Register a callback that fires when the page title changes
Called with the new title
Self for chaining
Stop the page from sending messages with a name registered by onMessage()
Removes webkit.messageHandlers.<name> from the page.
The handler name passed to onMessage()
Self for chaining
Configure the toolbar with a list of standard and custom items
The toolbar renders above the web view. Each element of the array is either a string
naming a standard control or a dictionary describing a custom button.
An empty array (or omitting this call) hides the toolbar.
Standard string items: "back", "forward", "reload", "url", "spacer".
Toolbar items in display order
Self for chaining
Set a custom User-Agent string for HTTP requests
The User-Agent string
Self for chaining
hs.ui.webview
A web browser element for embedding in
hs.ui.windowlayouts* Available on macOS 26.0 or later,hs.ui.webview()creates a web browser element backed by a SwiftUIWebViewandWebPage. Embed it in anyhs.ui.windowusing.webview(element)— it fills the available space and can sit alongside other elements in stacks.Because
wvis a regular JavaScript object you can keep a reference and call navigationCustom Toolbar Example
Full Example with Callbacks
Navigation Policy Example
Page Messages Example
The page can call back into your config with
webkit.messageHandlers.<name>.postMessage(body), which returns a Promise that settlesJavaScript Evaluation Example