MōBrowser 2.5.0
We’re happy to announce the release of MōBrowser 2.5.0! This release adds support for third-party Node packages that use native add-ons, introduces app launch-at-login APIs, adds window close handling, and expands window customization options such as shadow, transparency, opacity, and resizability.
What’s new
Third-party Node packages with native add-ons
You can now use third-party Node packages that rely on Node.js native add-ons.
For example, you can use the sharp package to process images in your application. It loads platform-specific native libraries at runtime to perform image processing tasks.
To make this work, externalize packages that use native add-ons in your project’s vite.config.ts file so Vite does not bundle the require() calls that load the .node binaries. For example:
function defineMainConfig(): UserConfig {
return {
root: path.resolve(__dirname, "./src/main"),
build: {
target: "esnext",
outDir: path.resolve(__dirname, "./out/main"),
emptyOutDir: true,
sourcemap: true,
lib: {
entry: path.resolve(__dirname, "./src/main/index.ts"),
formats: ["es"],
fileName: () => "index.js",
},
rollupOptions: {
external: [
"mobrowser",
/^node:.*/,
// Externalize packages that use native add-ons; bundling them breaks
// the require() calls used to load the .node files in ESM output.
"sharp",
],
},
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src/main"),
},
},
server: {
forwardConsole: {
unhandledErrors: true,
logLevels: ['warn', 'error'],
},
},
}
}
When you externalize the package, MōBrowser will bundle the package together with the native files it needs at runtime.
Launching the app at login
You can now configure the app to automatically launch at login on macOS and Windows. The following example demonstrates how to configure the app to launch when the user logs in to their system:
import { app } from '@mobrowser/api';
app.setLoginItemSettings({
openAtLogin: true,
args: ['--hidden'], // Windows only.
});
if (app.loginItemSettings.openAtLogin) {
console.log('Launch at login is enabled');
}
Handling window close
You can now intercept attempts to close an application window and decide whether to close it, hide it, or keep it open. This is useful when you want to minimize the app to the tray, keep a background agent running, or block closing until the user confirms the action.
You can also detect if the window is being closed as part of the application quitting.
The following example demonstrates how to handle window close:
import { BrowserWindow, CloseBrowserWindowParams } from '@mobrowser/api';
const win = new BrowserWindow()
win.handle('close', async (params: CloseBrowserWindowParams) => {
if (params.isQuitting) {
// Close the window and let the application quit.
return 'close'
}
// Hide the window instead of closing it.
return 'hide'
})
Note: If you suppress window closing, the application will not quit. Use params.isQuitting to return 'close' when the close request is part of application shutdown.
Learn more about the browser window close handler.
Features
Window customization support has been expanded with new BrowserWindow options and methods:
- Added
BrowserWindowOptions.hasShadowandBrowserWindow.setHasShadow(boolean)to control the visibility of the window shadow on macOS. - Added
BrowserWindowOptions.transparentBackgroundandBrowserWindow.setTransparentBackground(boolean)to control transparent window backgrounds on macOS. - Added
BrowserWindowOptions.opacityandBrowserWindow.setOpacity(number)to control window opacity on macOS and Windows. - Added
BrowserWindowOptions.resizableandBrowserWindow.setResizable(boolean)to control whether windows can be resized on macOS, Windows, and Linux. - You can now register a single key modifier like
CommandOrControl,Meta,Command,Control,Option,Shiftas a global shortcut. For example:import { globalShortcut } from '@mobrowser/api'; globalShortcut.register('Shift', () => { console.log('Shift key has been pressed') })
Improvements
- Improved performance of the
npm run gencommand.
Security
- Updated Node.js to version 24.14.1.
Fixes
- Fixed a bug when an attempt to register
Metaas a global shortcut throwsTypeError: Failed to parse shortcut: Meta. - Fixed a bug where bundled CMake could be extracted incorrectly on macOS, causing
CMake.appto appear damaged and fail to open.