javascript get browser is electron code example
Example 1: how to check whether we are running on electron or browser
let isElectron = require("is-electron");
if(isElectron()){
console.log("Electron aww yeahhh !");
}else{
console.log("Running in other platform as a normal browser");
}
Example 2: how to check whether we are running on electron or browser
npm install --save is-electron
Example 3: javascript get browser is electron
function isElectron() {
// Renderer process
if (typeof window !== 'undefined' && typeof window.process === 'object' && window.process.type === 'renderer') {
return true;
}
// Main process
if (typeof process !== 'undefined' && typeof process.versions === 'object' && !!process.versions.electron) {
return true;
}
// Detect the user agent when the `nodeIntegration` option is set to true
if (typeof navigator === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent.indexOf('Electron') >= 0) {
return true;
}
return false;
}
if(isElectron()){
console.log("Electron aww yeahhh !");
}else{
console.log("Running in other platform as a normal browser");
}