TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/webviewjs/webview/llms.txt
Use this file to discover all available pages before exploring further.
Application class is the root of every WebviewJS program. It owns the native OS event loop (powered by Tao), drives the pump that feeds events to all windows, and acts as the single factory for BrowserWindow, WebContext, and TrayIcon instances. You must create exactly one Application per process, then call whenReady() (or run()) before interacting with any window or webview.
Constructor
Reserved for future use. Pass
null or omit entirely.Methods
whenReady(options?)
Returns a Promise that resolves the first time the native event loop emits its resumed() lifecycle callback, indicating the OS is ready to display windows. By default this also starts the event pump via run() so your .then() callback fires as soon as hardware is ready.
Resolves once the native event loop is ready. Subsequent calls after readiness also resolve asynchronously.
isReady()
Returns true after the native event loop has fired its first resumed() event.
true if the app is ready, false otherwise.run(options?)
Start the event pump. Calls pumpEvents() on a setInterval and returns immediately, leaving the Node.js event loop free to handle I/O, timers, and promises in parallel.
exit()
Stop the pump, hide all tracked windows, and mark the application as exited. Subsequent pumpEvents() calls return false. All owned resources (windows, webviews, web contexts, tray icons) are disposed automatically.
pumpEvents()
Process one batch of OS events without blocking. Returns true while the app is alive, false when the app should stop. Normally called automatically by run(), but you can drive it manually for precise control (e.g., a custom game loop).
true while alive, false when exit() has been called.runSync()
Run the native event loop on the current thread, blocking JavaScript until the application exits. Use run() when the Node.js event loop must remain available for I/O, timers, and promises.
createBrowserWindow(options?)
Create and return a new top-level BrowserWindow.
See BrowserWindow options for the full options reference.
A new
BrowserWindow instance.createChildBrowserWindow(options?)
Create a child/popup window. The webview inside fills a precise sub-region of the parent rather than the whole window, useful for overlay UIs or panels.
Same shape as
createBrowserWindow. The resulting window reports isChild === true.A new child
BrowserWindow instance.createWebContext(options?)
Create an isolated browser-data context that can be shared across multiple webviews for cookie, cache, and storage sharing — or used in isolation for profile separation.
A new
WebContext instance. See WebContext reference.Always create contexts through
app.createWebContext() — calling new WebContext() is not supported.createTrayIcon(options)
Create a system tray icon.
A new
TrayIcon instance.setMenu(options?)
Set the global application menu. Pass null or omit to remove the current menu.
{ items: MenuItemOptions[] } — see the Menus guide for the full shape.Symbol.dispose
Application implements the TC39 Explicit Resource Management protocol. Use the using declaration to guarantee exit() is called even if an exception is thrown.
Events
Application extends the standard Node.js EventEmitter. All on, once, off, addListener, removeListener, removeAllListeners, listenerCount, listeners, rawListeners, emit, and eventNames methods are available. Listener-registration and removal methods are chainable.
| Event | Payload | Fired when |
|---|---|---|
window-close-requested | ApplicationEvent | User clicks the OS close button on a window |
application-close-requested | ApplicationEvent | The last window is closed |
custom-menu-click | ApplicationEvent (with customMenuEvent) | A custom menu item is selected |
ready | ApplicationEvent | The native event loop is ready |
WebviewApplicationEvent enum values: WindowCloseRequested (0), ApplicationCloseRequested (1), CustomMenuClick (2), Ready (3).
Legacy event API
Prefer the EventEmitter
on()/once() interface above for new code. The onEvent/bind API is kept for backward compatibility.onEvent(handler) / bind(handler)
Register a callback for all application-level events. Both names are equivalent aliases for the same underlying registration.
Root-owned disposal
All resources created through anApplication are owned by that application. Calling app.exit(), using Symbol.dispose, or letting the application be finalized will dispose every tray icon, webview, window, web context, menu, and callback registered under it. Cleanup is idempotent — calling exit() twice is safe. Retained wrapper objects report isDisposed() === true and reject further method calls after disposal.