Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
karma-electron
Advanced tools
Karma launcher and preprocessor for Electron
This was written to allow for directly testing in Electron where we might want require
to work automatically
Features:
node_modules
, __filename
, relative paths for require
)Requirements:
karma>=1.1.0
to work within electron's
security policy for shared context between parent/child windows
Notices:
electron@{0.x,1,5,6,7,8,9,11,12,14,15,20}
and should support the latest versionelectron
application
electron's
documentation on Selenium and WebDrivercontextIsolation
has been set to true
by default, which limits interaction with require
and postMessage
To resolve these issues, please see the latest Getting Started instructions
For more information, see https://github.com/twolfson/karma-electron/issues/50
We have corrected inaccuracies with file://
behavior from Electron. For example:
__filename
is now Karma's context.html
require
resolve from Karma's context.html
directoryWe have transferred support for this to the option client.loadScriptsViaRequire
which loads scripts via require
and has the original expected Node.js behavior
For more information, see https://github.com/twolfson/karma-electron/issues/11
On a project that has been set up with karma init
already, install the module via:
# Install our module and `electron`
npm install karma-electron electron
Then, configure the module with the following:
Note: Due to electron@12
postMessage
limitations, we set BrowserWindow#webPreferences.nativeWindowOpen
to true
by default (see #50 for more info)
// Inside `karma.conf.js`
browsers: ['Electron']
// DEV: `useIframe: false` is for launching a new window instead of using an iframe
// In Electron, iframes don't get `nodeIntegration` priveleges yet windows do
client: {
useIframe: false
}
Then, we can run Karma:
karma start
By default, we try to use the minimal Electron configuration to avoid any assumptions about your repo
As a result, we need to define a custom launcher to match your Electron configuration
To add Node.js integration support (e.g. require
), use the following:
// Inside `karma.conf.js`
// Define our custom launcher for Node.js support
customLaunchers: {
CustomElectron: {
base: 'Electron',
browserWindowOptions: {
// DEV: More preferentially, should link your own `webPreferences` from your Electron app instead
webPreferences: {
// Preferred `preload` mechanism to expose `require`
preload: __dirname + '/path/to/preload.js'
// Alternative non-preload mechanism to expose `require`
// nodeIntegration: true,
// contextIsolation: false
// nativeWindowOpen is set to `true` by default by `karma-electron` as well, see #50
}
}
}
}
// Use our custom launcher
browsers: ['CustomElectron']
// DEV: preprocessors is for backfilling `__filename` and local `require` paths
preprocessors: {
'**/*.js': ['electron']
},
// DEV: `useIframe: false` is for launching a new window instead of using an iframe
// In Electron, iframes don't get `nodeIntegration` priveleges yet windows do
client: {
useIframe: false
}
Then, we can run Karma:
karma start
electron
electron
Example:
ELECTRON_BIN=/usr/bin/electron karma start
We support the following configurations:
Object
- Container for configuring child windows loaded from Karma
String
- Override __filename
to be another path (e.g. /path/to/my-index.html
)
__dirname
and module.filename
as those are derived from __filename
__filename
will point to Karma's context.html
Boolean
- Load scripts via require
instead of <script src=
__filename
, __dirname
, and module
to match the script instead of Karma's context.html
false
and we directly load the original scripts contentExample:
// Inside `karma.conf.js`
module.exports = function (config) {
config.set({
client: {
// DEV: These 2 options aren't typically used together
// This is for demonstration purposes
// Override top level `__filename` to be `/home/.../my-electron-app/index.html`
// where `__dirname` is `/home/.../my-electron-app`
__filenameOverride: __dirname + '/index.html',
// Use `require` instead of `<script src=` to load scripts
loadScriptsViaRequire: true
}
});
};
We support configuration via Karma's custom launcher inheritance:
Array
- List of Chromium flags to alter Electron's behavior
String
- Directory to store cookies/localStorage information
/tmp/karma-5355024
)String
- Path to a main Electron process file to require before calling app.on('ready')
Object
- Parameters to pass to new BrowserWindow
Object
- Parameters to pass to BrowserWindow.loadURL
Example:
// Inside `karma.conf.js`
module.exports = function (config) {
config.set({
// Specify usage of our custom launcher
browsers: ['CustomElectron'],
// Define a custom launcher which inherits from `Electron`
customLaunchers: {
CustomElectron: {
base: 'Electron',
userDataDir: __dirname + '/.electron',
browserWindowOptions: {
show: true
// nativeWindowOpen is set to `true` by default by `karma-electron` as well, see #50
},
require: __dirname + '/main-fixtures.js'
}
}
});
};
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint via npm run lint
and test via npm test
.
Support this project and others by twolfson via donations.
http://twolfson.com/support-me
As of Mar 03 2016, Todd Wolfson has released this repository and its contents to the public domain.
It has been released under the UNLICENSE.
FAQs
Karma launcher and preprocessor for Electron
The npm package karma-electron receives a total of 1,544 weekly downloads. As such, karma-electron popularity was classified as popular.
We found that karma-electron 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.