Zero-dependency package for downloading and installing Electron (v2.0.16) prebuilt binary from GitHub releases
npx @tessl/cli install tessl/npm-electron-lite@2019.1.0Electron Lite is a zero-dependency npm package that provides a lightweight solution for downloading and installing the Electron (v2.0.16) prebuilt binary from GitHub releases. It enables developers to use Electron for headless browser operations, web scraping, screenshot generation, and automated web tasks without requiring the full Electron package.
The package serves as a lightweight alternative that automatically handles platform-specific Electron binary download and installation, supporting both command-line usage and programmatic API access.
npm install electron-liteconst electronLite = require('electron-lite');For accessing specific utilities through destructuring:
const { assertThrow, identity, nop, fs, path } = require('electron-lite');For accessing built-in Node.js modules:
const { fs, path, http, crypto } = require('electron-lite');# Install globally
npm install -g electron-lite
# Run Electron with arguments
electron --help
electron --version
electron /path/to/your/appconst electronLite = require('electron-lite');
// Use utility functions
const result = electronLite.identity("test value");
console.log(result); // "test value"
// Access Node.js built-in modules through electron-lite
const fs = electronLite.fs;
const path = electronLite.path;
// Use assertion utility
electronLite.assertThrow(true, "This will not throw");
// Access self-references
console.log(electronLite.local === electronLite); // true
console.log(electronLite.electron === electronLite); // true
// Check environment
if (!electronLite.isBrowser) {
console.log('Running in Node.js environment');
}/*
This example creates a screenshot of a webpage using Electron.
Save as example.js and run with:
npm install electron-lite && ./node_modules/.bin/electron . --disable-overlay-scrollbar --enable-logging
*/
const fs = require('fs');
// Initialize Electron app
let modeNext = 0;
let options;
const onNext = function (data) {
modeNext += 1;
switch (modeNext) {
case 1:
// Wait for electron to init
try {
require("app").on("ready", onNext);
} catch (ignore) {
require("electron").app.once("ready", onNext);
}
break;
case 2:
// Init options and browserWindow
options = {frame: false, height: 768, width: 1024, x: 0, y: 0};
try {
options.BrowserWindow = require("browser-window");
} catch (ignore) {
options.BrowserWindow = require("electron").BrowserWindow;
}
options.browserWindow = new options.BrowserWindow(options);
// Goto next step when webpage is loaded
options.browserWindow.webContents.once("did-stop-loading", onNext);
// Open URL
(options.browserWindow.loadUrl || options.browserWindow.loadURL).call(
options.browserWindow,
"https://electron.atom.io"
);
break;
case 3:
// Screenshot webpage
options.browserWindow.capturePage(options, onNext);
break;
case 4:
// Save screenshot
try {
data = data.toPng();
} catch (ignore) {
data = data.toPNG();
}
fs.writeFileSync("/tmp/screenshot.png", data);
console.log("Created screenshot file /tmp/screenshot.png");
process.exit(0);
break;
}
};
onNext();The package behaves differently depending on how it's used:
When run as the main module (e.g., via the electron command), the package:
When imported as a module (require('electron-lite')), the package:
The package provides a global electron command that acts as a wrapper for the Electron binary.
// CLI binary export
{
"bin": {
"electron": "lib.electron.js"
}
}CLI Features:
--help and -h flagsCore utility functions for assertions, function handling, and object manipulation.
/**
* Throws error if condition is falsy
* @param {any} passed - Condition to test
* @param {string|Error} message - Error message or error object
* @throws {Error} If passed is falsy
*/
function assertThrow(passed, message);
/**
* Returns function if exists, otherwise returns nop function
* @param {function|undefined} fnc - Function to check
* @returns {function} The function or nop
*/
function functionOrNop(fnc);
/**
* Identity function that returns input value unchanged
* @param {any} value - Value to return
* @returns {any} The input value
*/
function identity(value);
/**
* No-operation function that does nothing
* @returns {undefined}
*/
function nop();
/**
* Assigns properties from source to target for null/undefined/empty values
* @param {object} target - Target object to modify
* @param {object} source - Source object with default values
*/
function objectAssignDefault(target, source);/**
* Boolean indicating if running in browser environment
* @type {boolean}
*/
const isBrowser;When running in Node.js environment, provides direct access to all built-in modules:
// Core Node.js modules available as properties
const assert; // Node.js assert module
const buffer; // Node.js buffer module
const child_process; // Node.js child_process module
const cluster; // Node.js cluster module
const crypto; // Node.js crypto module
const dgram; // Node.js dgram module
const dns; // Node.js dns module
const domain; // Node.js domain module
const events; // Node.js events module
const fs; // Node.js fs module
const http; // Node.js http module
const https; // Node.js https module
const net; // Node.js net module
const os; // Node.js os module
const path; // Node.js path module
const querystring; // Node.js querystring module
const readline; // Node.js readline module
const repl; // Node.js repl module
const stream; // Node.js stream module
const string_decoder; // Node.js string_decoder module
const timers; // Node.js timers module
const tls; // Node.js tls module
const tty; // Node.js tty module
const url; // Node.js url module
const util; // Node.js util module
const vm; // Node.js vm module
const zlib; // Node.js zlib moduleThe package initializes a global debug utility function accessible as globalThis.debugInline.
/**
* Global debug utility that prints arguments to stderr and returns first argument
* Available as globalThis.debugInline (note: unicode escape in actual implementation)
* @param {...*} var_args - Variable arguments to debug and print
* @returns {*} First argument passed
*/
globalThis.debugInline = function(/* ...var_args */);The package automatically handles Electron binary installation through a postinstall script.
Installation Features:
external/Electron.app/Contents/MacOS/Electronexternal/electronEnvironment Configuration:
# Override Electron version (defaults to v2.0.16)
npm_config_electron_version=v3.0.0 npm install electron-lite
# Also available versions from releases.txt:
# v3.0.14, v3.1.0-beta.5, v4.0.1, v4.0.0, v2.0.16, etc.When used as CLI (main module), spawns child process for Electron execution:
/**
* Child process instance running the Electron binary
* Only available when lib.electron.js is executed as main module (CLI mode)
* Not available when required as a module
* @type {ChildProcess}
*/
local.child = child_process.spawn(/* ... */);/**
* Main module export containing all utilities and Node.js modules
*/
interface ElectronLiteModule {
// Utility functions
assertThrow: (passed: any, message: string | Error) => void;
functionOrNop: (fnc?: function) => function;
identity: (value: any) => any;
nop: () => undefined;
objectAssignDefault: (target: object, source: object) => void;
// Self-references
local: ElectronLiteModule;
electron: ElectronLiteModule;
// Module metadata (Node.js only)
__dirname?: string;
// Environment detection
isBrowser: boolean;
// Node.js built-in modules (when not in browser)
assert?: typeof import('assert');
buffer?: typeof import('buffer');
child_process?: typeof import('child_process');
crypto?: typeof import('crypto');
fs?: typeof import('fs');
http?: typeof import('http');
https?: typeof import('https');
path?: typeof import('path');
os?: typeof import('os');
// ... all other Node.js built-in modules
// Module metadata (Node.js only)
__dirname?: string;
}The package includes built-in error handling patterns:
Common error scenarios:
Supported Platforms:
Unsupported Platforms:
Runtime Dependencies: None (zero-dependency package)
Internal Tools:
busybox-i486: Included binary for Linux unzip operationsnpm_scripts.sh: Installation and build scriptreleases.txt: Predefined list of Electron release URLsnpm install electron-litenpm_scripts.sh automaticallyexternal/ directoryelectron command in node_modules/.bin/