Chilkat for Electron
Chilkat for Electron is the Chilkat Node.js addon built for Electron, published on npm under the
@chilkat scope, one package for each Electron major version and platform. The classes, methods and
properties are the same as in Chilkat for Node.js, on Windows, Linux and macOS.
npm install. The package contains the
prebuilt addon; nothing is compiled or downloaded at install time, and no rebuild step is needed.
Jump to: Install · Packages · Quick start · One project, several platforms · Async methods · Licensing
Documentation & Samples
- 📖 Chilkat Node.js Reference Documentation — the API is the same in Electron
- 💻 Chilkat Node.js Sample Code — complete examples
- 📗 The Chilkat API in JavaScript, Async methods and Progress events on the Node.js page
- 🤖 For AI coding assistants: https://www.chilkatsoft.com/ai-docs/v/11.7.0/nodejs/guide.md
- 📝 Release Notes
Install
The package name says which Electron version and platform it is for. For Electron 45 on 64-bit Windows:
npm install @chilkat/ck-electron45-win64
Load it with require in the main process, using the name of the package you installed:
const chilkat = require('@chilkat/ck-electron45-win64');
process.versions.electron at run time), not by the
Node.js installed on your computer. The package version is the Chilkat version.
Packages
Each name links to the package on npmjs.com.
| Electron | Platform | Package |
|---|---|---|
| Electron 45 | Windows x64 | @chilkat/ck-electron45-win64 |
| Linux x64 | @chilkat/ck-electron45-linux-x64 | |
| macOS universal: Apple silicon and Intel | @chilkat/ck-electron45-mac-universal | |
| Electron 44 | Windows x64 | @chilkat/ck-electron44-win64 |
| Linux x64 | @chilkat/ck-electron44-linux-x64 | |
| macOS universal: Apple silicon and Intel | @chilkat/ck-electron44-mac-universal | |
| Electron 43 | Windows x64 | @chilkat/ck-electron43-win64 |
| Linux x64 | @chilkat/ck-electron43-linux-x64 | |
| macOS universal: Apple silicon and Intel | @chilkat/ck-electron43-mac-universal |
npm refuses to install a package on an operating system or CPU other than the one in its name (the os and cpu fields of the package). Each package also contains license.pdf and THIRD-PARTY-NOTICES.txt.
Quick start
Load Chilkat in the main process and give the pages of your application the calls they need through a preload script. main.js:
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const chilkat = require('@chilkat/ck-electron45-win64');
// Once per process. Any string starts the fully functional 30-day trial.
new chilkat.Global().UnlockBundle('Anything for 30-day trial');
// A quick call: answer directly.
ipcMain.handle('sha256', function (event, text) {
const crypt = new chilkat.Crypt2();
crypt.HashAlgorithm = 'sha256';
crypt.EncodingMode = 'hex';
return crypt.HashStringENC(text);
});
// A call that can take a while: use the Async method, so the main process stays responsive.
ipcMain.handle('httpGet', function (event, url) {
const http = new chilkat.Http();
const task = http.QuickGetStrAsync(url);
return new Promise(function (resolve, reject) {
task.Run(function () {
if (task.TaskSuccess) resolve(task.GetResultString());
else reject(new Error(task.ResultErrorText));
});
});
});
app.whenReady().then(function () {
const win = new BrowserWindow({
webPreferences: { preload: path.join(__dirname, 'preload.js') }
});
win.loadFile('index.html');
});
preload.js:
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('chilkat', {
sha256: function (text) { return ipcRenderer.invoke('sha256', text); },
httpGet: function (url) { return ipcRenderer.invoke('httpGet', url); }
});
In a page (index.html):
// in an async function:
const hash = await window.chilkat.sha256('Hello, Chilkat');
const html = await window.chilkat.httpGet('https://www.chilkatsoft.com/');
Chilkat methods do not throw when an operation fails: they return false or null, and
the object's LastErrorText property (for an Async call, the task's
ResultErrorText) explains what happened.
One project, several platforms
For an application that is built for more than one platform, list the packages as
optionalDependencies in package.json.
npm install then installs the one that matches the machine it runs on and skips the others:
"optionalDependencies": {
"@chilkat/ck-electron45-win64": "^11.7.0",
"@chilkat/ck-electron45-linux-x64": "^11.7.0",
"@chilkat/ck-electron45-mac-universal": "^11.7.0"
}
and build the package name at run time:
const major = process.versions.electron.split('.')[0];
const platform = {
win32: 'win64',
darwin: 'mac-universal',
linux: 'linux-x64'
}[process.platform];
const chilkat = require('@chilkat/ck-electron' + major + '-' + platform);
Async methods
A Chilkat method call is synchronous: it blocks the process it is called in until it returns, and a blocked
main process freezes every window of the application. Quick operations (JSON, XML, hashing, encoding) are fine.
For network and file operations, use the method's Async form, as
httpGet does in the quick start: it returns a chilkat.Task, and
task.Run(callback) runs the call on a background thread and calls the function when it has
finished. Progress and cancellation go through the task's PercentDone property and
Cancel() method. The details are on the Node.js page:
Async methods.
Licensing
This is the full-version Chilkat product. Chilkat is
fully functional for a 30-day evaluation; passing any
string to UnlockBundle starts the trial, and a purchased unlock code removes the time limit. The
license terms are in license.pdf in every package. For questions,
contact Chilkat support.