Application is the root of every WebviewJS program. It owns the native event loop, all BrowserWindow instances, tray icons, web contexts, and menus you create during the session. You must construct exactly one Application before calling any other WebviewJS API, and keep it alive for the duration of your program.
Constructor
ApplicationOptions is accepted by the constructor but is currently unused. You can safely pass null or omit the argument entirely.
Lifecycle Methods
run(options?)
Starts the event pump by calling pumpEvents() on a setInterval and returns immediately, leaving the Node.js event loop free for async work such as file I/O and timers. This is the recommended way to drive the event loop in most Node.js applications.
number
default:"16"
How often to pump OS events, in milliseconds. The default of 16 ms targets ~60 FPS.
boolean
default:"true"
When
false, the underlying timer is unref’d and will not prevent the Node.js process from exiting on its own.runSync()
Runs the native Tao event loop on the current thread and blocks JavaScript until the application exits. The Node.js event loop is unavailable while this call is in progress.
Use
run() in most Node.js applications. Reserve runSync() for cases where you explicitly want the GUI loop to own the thread.stop()
Clears the pump interval started by run(). The Application object and all windows remain valid — you can restart the pump by calling run() again.
exit()
Stops the pump, hides all tracked windows, and marks the application as exited. Subsequent pumpEvents() calls return false. All resources owned by the application (windows, webviews, tray icons, web contexts) are disposed.
pumpEvents()
Processes one batch of OS events without blocking. Returns true while the application is alive, false when the application should stop. You normally do not call this directly — run() drives it automatically.
whenReady(options?)
Returns a Promise that resolves after the native event loop fires its first resumed lifecycle callback, indicating that the platform is ready to display windows. By default, calling whenReady() also starts the event pump automatically.
boolean
default:"true"
When
true (default), whenReady() calls run() internally. Set to false when you plan to drive the loop manually with run() or pumpEvents().number
Forwarded to
run(). Only valid when autoRun is true.boolean
Forwarded to
run(). Only valid when autoRun is true.If the application is already ready when you call
whenReady(), the promise still resolves asynchronously on the next microtask tick.isReady()
Returns true if the native event loop has already emitted its resumed event.
Factory Methods
Use these methods to create WebviewJS resources. Resources created through the application are automatically tracked and disposed whenapp.exit() is called.
createBrowserWindow(options?)
Creates and returns a new BrowserWindow wrapping an OS-level window.
createChildBrowserWindow(options?)
Creates a child/popup window. The webview inside a child window occupies a precise region you specify rather than filling the whole window. Useful for panels, overlays, and embedded views.
createWebContext(options?)
Creates an isolated browser-data context that can be shared across multiple webviews, giving them a common cookie jar, cache, and local storage.
Always create contexts through
app.createWebContext(). Calling new WebContext() directly is not supported.createTrayIcon(options)
Creates a system tray icon with an optional menu and tooltip.
setMenu(options?)
Sets the global application menu. Pass null or omit the argument to remove it.
MenuOptions shape.
Application Events
Application extends the standard Node.js EventEmitter. Subscribe to application-level events with .on(), .once(), or any other EventEmitter method.
Event reference
The
ApplicationEvent payload shape:
Usage example
Available EventEmitter methods
All registration and removal methods return
this and are chainable.
Legacy onEvent() / bind()
These methods are provided for backwards compatibility. Prefer the EventEmitter API (
.on(), .once(), etc.) for new code.event field against the exported WebviewApplicationEvent enum:
Resource Management
Symbol.dispose
Application implements the TC39 Explicit Resource Management protocol. You can use a using declaration to guarantee cleanup even if an exception is thrown:
Root-owned disposal
Every resource you create through anApplication instance — windows, webviews, tray icons, web contexts, and menus — is owned by that application. Calling app.exit() (or triggering [Symbol.dispose]) disposes all of them in one shot.
Disposal is idempotent: calling exit() more than once is safe. After disposal, retained resource wrapper objects (e.g. BrowserWindow, Webview) report isDisposed() === true and throw if you call further methods on them. Attempting to create new resources after exit() also throws.
Complete Example
The following example shows the recommended pattern for a WebviewJS application usingwhenReady():