-
Notifications
You must be signed in to change notification settings - Fork 15k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to detect if running in electron? #2288
Comments
|
There is also |
What if we are running the process without node integration? I think so far I've been relaying on the navigator.userAgent , is there a better way to do it? |
Atom/Electron also exposes module object to the renderer Javascript context. Currently async.js detects Electron as NodeJs, where as it should be detected as browser, as suggested by https://github.com/atom/electron-starter#why-does-my_favorite_library-not-work--do-weird-stuff The detection snippet is from electron/electron#2288
For some reason, setting the element's contentEditable value to true within a keyboard event, while the element has focus, did not allow pasting with clipboard, unless the element gets clicked explicitly.
Seems this has been merged, but I noticed this project gives a nice function for it, instead of using the conditional clauses directly in the code: https://github.com/cheton/is-electron |
I've always been a little unhappy with using As electron is revealed in the user agent I would suggest doing the following (tested working in 1.7.5):
Also, your App name is revealed in the user agent string, which is helpful if you have code for different variants of your app. |
For information: The first two methods arn't working for me, but @richjeffery's method is working fine. Things have probably changed since 2015. |
It is not advisable to use
IMO we should all use @richjeffery's solution or the Electron team should make a global property available to all contexts for non-spoofable detection. |
When running code inside electron browser windows, process.browser is undefined. This adds is-electron.js to check if the environment is running inside an electron browser window with nodeIntegration set to true which is a valid browser environment. See: https://github.com/uber/luma.gl/blob/master/src/utils/is-electron.js https://github.com/uber/luma.gl/blob/master/src/utils/is-browser.js https://github.com/cheton/is-electron electron/electron#2288
These 3 work for me after @zcbenz suggestion : if (process.versions.hasOwnProperty('electron')) {
// Electron specific code
}else{
} if (typeof (process.versions.electron) === 'string') {
// Electron specific code
}else{
} var WHY = (process.versions.hasOwnProperty('electron')) ? /*expression for Electron*/ : /*other expression*/;` But I can see the advantage over this, of |
When running code inside electron browser windows, process.browser is undefined. This adds is-electron.js to check if the environment is running inside an electron browser window with nodeIntegration set to true which is a valid browser environment. See: https://github.com/uber/luma.gl/blob/master/src/utils/is-electron.js https://github.com/uber/luma.gl/blob/master/src/utils/is-browser.js https://github.com/cheton/is-electron electron/electron#2288
When running code inside electron browser windows, process.browser is undefined. This adds is-electron.js to check if the environment is running inside an electron browser window with nodeIntegration set to true which is a valid browser environment. See: https://github.com/uber/luma.gl/blob/master/src/utils/is-electron.js https://github.com/uber/luma.gl/blob/master/src/utils/is-browser.js https://github.com/cheton/is-electron electron/electron#2288
When running code inside electron browser windows, process.browser is undefined. This adds is-electron.js to check if the environment is running inside an electron browser window with nodeIntegration set to true which is a valid browser environment. See: https://github.com/uber/luma.gl/blob/master/src/utils/is-electron.js https://github.com/uber/luma.gl/blob/master/src/utils/is-browser.js https://github.com/cheton/is-electron electron/electron#2288
When running code inside electron browser windows, process.browser is undefined. This adds is-electron.js to check if the environment is running inside an electron browser window with nodeIntegration set to true which is a valid browser environment. See: https://github.com/uber/luma.gl/blob/master/src/utils/is-electron.js https://github.com/uber/luma.gl/blob/master/src/utils/is-browser.js https://github.com/cheton/is-electron electron/electron#2288
## [1.30.2](v1.30.1...v1.30.2) (2020-03-22) ### Bug Fixes * **ui:** Display correct track error message when using electron app ([#294](#294)) ([4f97ccd](4f97ccd)), closes [#224](#224) [/github.com/electron/electron/issues/2288#issuecomment-337858978](https://github.com//github.com/electron/electron/issues/2288/issues/issuecomment-337858978) [/github.com//issues/224#issuecomment-601430390](https://github.com//github.com/openwhyd/openwhyd/issues/224/issues/issuecomment-601430390)
Just to clarify things for those just finding this: the above discussions do not mention if the approach applies to main or renderer scripts.
|
Assuming that I'm responsible for writing the main process code, I've used a preload script in which I have a context bridge import { contextBridge } from "electron";
contextBridge.exposeInMainWorld("electron", {
hello: "hello",
}); And then i check for the existence of |
@sarimabbas |
When running code inside electron browser windows, process.browser is undefined. This adds is-electron.js to check if the environment is running inside an electron browser window with nodeIntegration set to true which is a valid browser environment. See: https://github.com/uber/luma.gl/blob/master/src/utils/is-electron.js https://github.com/uber/luma.gl/blob/master/src/utils/is-browser.js https://github.com/cheton/is-electron electron/electron#2288
Somehow the userAgent was " " for me so I couldn't use that to detect Electron while keeping My solution was to define a property on When creating the window: const window = new BrowserWindow({
webPreferences: {
preload: "window-preload.js", // Appropriate path to the file in your own project
},
}); In // In the app, if window.isElectron is defined and true, we know we're running in Electron
Object.defineProperty(window, "isElectron", { get: () => true }); In the app: console.log("Running in Electron?", window.isElectron); |
When running code inside electron browser windows, process.browser is undefined. This adds is-electron.js to check if the environment is running inside an electron browser window with nodeIntegration set to true which is a valid browser environment. See: https://github.com/uber/luma.gl/blob/master/src/utils/is-electron.js https://github.com/uber/luma.gl/blob/master/src/utils/is-browser.js https://github.com/cheton/is-electron electron/electron#2288
I hear the application name I give one of my projects is also exposed through the userAgent? if so how do I check agains it, i now have a function that sets a true or false flag if the page is loaded by electron, but i only check the one user agent string, which is i think a recipe for disaster at some point, and i would need more proof in my code to know it's the electron version of my application which is opened by the user, this is my code thus far:
and console.log is commented, it's there for debug ofc. |
When running code inside electron browser windows, process.browser is undefined. This adds is-electron.js to check if the environment is running inside an electron browser window with nodeIntegration set to true which is a valid browser environment. See: https://github.com/uber/luma.gl/blob/master/src/utils/is-electron.js https://github.com/uber/luma.gl/blob/master/src/utils/is-browser.js https://github.com/cheton/is-electron electron/electron#2288
Hi I, got solution // main process // preload.js // renderer process (your React world) |
This commit introduces native operating system file dialogs in the desktop application replacing the existing web-based dialogs. It lays the foundation for future enhancements such as: - Providing error messages when saving or executing files, addressing #264. - Creating system restore points, addressing #50. Documentation updates: - Update `desktop-vs-web-features.md` with added functionality. - Update `README.md` with security feature highlights. - Update home page documentation to emphasize security features. Other supporting changes include: - Integrate IPC communication channels for secure Electron dialog API interactions. - Refactor `IpcRegistration` for more type-safety and simplicity. - Introduce a Vue hook to encapsulate dialog functionality. - Improve errors during IPC registration for easier troubleshooting. - Move `ClientLoggerFactory` for consistency in hooks organization and remove `LoggerFactory` interface for simplicity. - Add tests for the save file dialog in the browser context. - Add `Blob` polyfill in tests to compensate for the missing `blob.text()` function in `jsdom` (see jsdom/jsdom#2555). Improve environment detection logic: - Treat test environment as browser environments to correctly activate features based on the environment. This resolves issues where the environment is misidentified as desktop, but Electron preloader APIs are missing. - Rename `isDesktop` environment identification variable to `isRunningAsDesktopApplication` for better clarity and to avoid confusion with desktop environments in web/browser/test environments. - Simplify `BrowserRuntimeEnvironment` to consistently detect non-desktop application environments. - Improve environment detection for Electron main process (electron/electron#2288).
How do I detect in JavaScript whether the App is running inside an electron frame work not?
The text was updated successfully, but these errors were encountered: