electron js detect if a program 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: javascript get browser is electron
function isElectron() {
if (typeof window !== 'undefined' && typeof window.process === 'object' && window.process.type === 'renderer') {
return true;
}
if (typeof process !== 'undefined' && typeof process.versions === 'object' && !!process.versions.electron) {
return 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");
}