
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
electron-thread
Advanced tools
Electron workers using BrowserWindow headless window
This package allows you to use multithreading in Electron. This type of multithreading allows you to use NODE JS API and Electron API
Note: this module has to be used in the renderer process and the thread to be invoked in the renderer process. Also make sure you register the module in the main module import 'electron-thread' and also import import * as et from "electron-thread" like this or if you prefer to import classes separetely, you have to register the module as well import 'electron-thread';
npm install --save electron-thread
Given a file in renderer, child.worker.js:
# Import the ThreadExport class
import { ThreadExport } from "electron-thread";
# Write your methods
function getProcessId(paramOne, paramTwo) {
return `${paramOne}:${paramTwo} ${process.pid}`;
}
# Register your methods
ThreadExport.export({
getProcessId: getProcessId
});
And a renderer file where we call:
# Import the ElectronThread class
import { ElectronThread } from "electron-thread";
# initialise using your relative path to child.thread.js and resolve the path with require.resolve()
let electronThread = new ElectronThread({
module: require.resolve('./child.worker')
});
let test = async () => {
for (var i = 0; i < 10; i++) {
let r = electronThread.run<string>({
method: 'getProcessId',
parameters: ['#', i + 1]
});
r
.then(r => console.log(r))
.catch(e => console.log(e));
}
}
test();
We'll get an output something like the following:
"#:1 13560"
"#:2 21980"
"#:3 21868"
"#:4 22712"
"#:5 2476"
"#:6 15936"
"#:7 19140"
"#:8 14928"
"#:9 12992"
"#:10 22132"
Electron thread exports a main method run(options: IThreadRunOptions) and an end() method. The run() method sets up a "thread farm" of coordinated BrowserWindows.
options: IThreadLaunchOptionsIf you don't provide an options object then the following defaults will be used:
{
module : string,
options :
{
windowOptions: BrowserWindowConstructorOptions,
maxConcurrentThreads: require('os').cpus().length,
maxCallTime: Infinity,
maxRetries: 10
}
}
module You should use an absolute path to the module file, the best way to obtain the path is with require.resolve('./path/to/module').
options.windowOptions allows you to customize all the parameters passed to BrowserWindowConstructorOptions. This object supports all possible options of BrowserWindowConstructorOptions.
options.maxConcurrentThreads will set the number of child processes to maintain concurrently. By default it is set to the number of CPUs available on the current system, but it can be any reasonable number, including 1.
options.maxCallTime when set, will cap a time, in milliseconds, that any single call can take to execute in a worker. If this time limit is exceeded by just a single call then the worker running that call will be killed and any calls running on that worker will have their callbacks returned with a TimeoutError (check err.type == 'TimeoutError').
options.maxCallTime allows you to control the max number of call retries after worker termination (unexpected or timeout). By default this option is set to Infinity which means that each call of each terminated worker will always be auto requeued. When the number of retries exceeds maxRetries value, the job callback will be executed with a ProcessTerminatedError.
You initialize electron "thread farm" let electronThread ElectronThread(options: IThreadLaunchOptions).
It will close all threads and won't wait for the task to complete.
options: IThreadRunOptionsYou have to specify the exported method name and the arguments
{
method : string,
parameters : any []
}
In the worker file we export the methods
{
exportMethodName1 : method1,
exportMethodName2 : method2,
exportMethodNameN : methodN,
}
# Import the ThreadExport class
import { ThreadExport } from "electron-thread";
# Write your methods
function getProcessId(paramOne, paramTwo) {
return `${paramOne}:${paramTwo} ${process.pid}`;
}
# Register your methods
ThreadExport.export({
getProcessId: getProcessId
});
FAQs
Electron thread workers using BrowserWindow headless windows
The npm package electron-thread receives a total of 1 weekly downloads. As such, electron-thread popularity was classified as not popular.
We found that electron-thread demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.