How to get full log of packaged electron app error? - electron

How can i know what node module is causing my packaged app to crash?the path is cut short.
Is there a way to get this error to terminal or file?
UPDATE:
i know the error comes from importing my workspace with yarn workspaces,
i commented this and packaged the app and works but i dont know whats wrong.it works when i just build it and run from terminal.
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const { format } = require('url');
const { organizeFiles } = require('#movepics/script'); THIS ONE
let mainWindow;
function createWindow() {...

Since you don't have a console to display on in a production environment, you need to output the logs to a log file instead of a console. And then you can have an "upload logs" option (or just view it, if it's on your device not on a customer's device).
To do this use the "electron-log" npm package.
const log = require('electron-log');
log.info('Hello, log');
log.warn('Some problem appears');
Caveat: Make sure you comply with the law regarding logs, as, mostly, logs have to be uploaded anonymously

So i was messing around with what i discovered and it seems cuz i have a exe file inside my package(yarn workspace) it causes this error, i just deleted the exe and now it works.
Conclusion i have to learn how to make a package with prebuilt binaries inside or make the installer of electron download the binary.

Related

Electron-Builder Linux updates - APPIMAGE env is not defined

I am on an Electron + Create React App stack.
I am using Electron Updater (https://github.com/develar/electron-updater) for auto updates.
Platform: Linux, Format: AppImage.
When my app checks for updates, I get the following error:
APPIMAGE env is not defined.
Has someone experienced the same issue? Suggestions required.
Please don't use electron-updater anymore, since it is no longer supported according to its GitHub page.
Most often, this occurs when you are trying to use the auto updater in development mode (or non-packaged AppImage mode). It only works in a packed production build.
For me however, this also occurred in a packed AppImage, and turned out to be caused by using the webpack DefinePlugin, like this:
plugins: [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
},
...
Removing the process.env definition allowed APPIMAGE to be defined once again in the distributed package. It seems the rest of the definitions can be left in place safely without breaking the auto-updater.
If removing this definition is not possible for your use-case, according to some users it's possible to simply override it at the beginning of your main thread (not renderer thread) file like this:
process.env.APPIMAGE = path.join(__dirname, 'dist', `MyApp-${app.getVersion()}.AppImage`)
... obviously with the correct file name in the 3rd argument of Path.join.
This override approach didn't seem to do anything for me though, so I myself went with simply removing process.env from the DefinePlugin definitions, but it may help in other cases.
try to use electron-builder for building your app cause this module is is in maintainance only mode.
the autoUpdate for linux is not possible, you can do that only for mac and windows try to read this documentation.

Spectron opens Empty terminals during test run

During execution spectron opens two terminal windows that are blank. First window is the application as I wanted it to be, other windows look like terminals without anything inside.
Currently i focus to the first window using focus().
Github issue link : https://github.com/electron/spectron/issues/60
Does anyone have any idea what's going on ? is it a ChromeDriver issue?
I've had the same issue (just to clarify, on Windows only).
Apparently, was introduced as a workaround for Spectron on Windows:
The launcher binary written in go was frequently marked as a trojan or virus. A simple bat file should seen as more innocuous. See #93 for the problem as well as this bat file.
Unfortunately, a consequence of using a .bat file is the unavoidable spawning of these extra empty consoles.
The only known workaround is using .focus() like you mentioned.
A combination of focus() with setAlwaysOnTop(true) helps.
chaiAsPromised.transferPromiseness = app.transferPromiseness;
return app.start().then( async () => {
await app.browserWindow.focus();
await app.browserWindow.setAlwaysOnTop(true);
});
});
Maybe rework launcher.bat to use the start command?
something like:
Start "" "%SPECTRON_NODE_PATH%" "%SPECTRON_LAUNCHER_PATH%" %*
Just eyeballing it.
Not sure about managing the exit fail codes but IIRC that does not leave up shell.
Full disclosure, I do not have this app and this is a drive-by answer. Hope it helps.

Electron: details.webContentsId dissapears in release (session.webRequest.onBeforeRequest event)

I am working in an Electron project in where I have several webviews to load different websites that share the same session (of the type “persist:id”). I have developed an adblock system that works at the level of the webview that works in the following way:
let mySession = session.fromPartition(‘persist:id’);
session.webRequest.onBeforeRequest(['*://*./*'], (details, cb) => {
if (adBlockActiveForSession(details.webContentsId)){
// adblock operations
}
}
This works in the development and with production flag. However, when I create a release/executable, it doesn't work. I noticed that, in the release, details doesn't have “webContentsId”, but it does in development.
Also I have check the documentation and it says that the webContentsId is an optional value in the onBeforeRequest callback.
why it works in development but not when I create a release? When can webContentsId be access in the parameter details and when it can’t? There is some flag I should use when doing the release package? Should I consider this a bug? has someone experienced the same issue?
Thank you
note: In order to insure that the webview has its webContent id, before loading an url I load an empty site, and after dom ready, I start to do the real url loadings.
Operating system:
development in Ubuntu, Mac, release in Mac, Windows. Both releases have the same problem.
Expected behavior
onBeforeRequest should return the information of the webContent that has created the request. That information is inside details.webContentsId
Actual behavior
onBeforeRequest returns it when working in development version and with the production on, however, when doing a package to create a release onBeforeRequest doesn’t return the webContentsId of the webContent that did the request

How to pass an argument to electron when using electron-builder?

I'm building an application with Electron and packaging with Electron Builder. When running electron, I want to pass this command line argument: --enable-mixed-sandbox.
Is it possible? How?
This:
app.commandLine.appendSwitch('enable-mixed-sandbox')
wouldn't work due to:
Note that it is not enough to call
app.commandLine.appendSwitch('--enable-sandbox'), as electron/node
startup code runs after it is possible to make changes to chromium
sandbox settings. The switch must be passed to electron on the
command-line:
electron --enable-sandbox app.js
It is not possible to have the OS sandbox active only for some renderers, if --enable-sandbox is enabled, normal electron windows
cannot be created.
You can use app.commandLine.appendSwitch in your applications main script (the one that opens the Electron window)
Example for your switch would be
app.commandLine.appendSwitch('enable-mixed-sandbox')
another way of doing it, you can use spectron to start the app in debug mode. which allows you to pass any arguments you want.
const Application = require('spectron').Application
// Returns a promise that resolves to a Spectron Application once the app has loaded.
// Takes a Ava test. Makes some basic assertions to verify that the app loaded correctly.
function createApp (t) {
return new Application({
path: 'path/to/app',
args: ['-r', '--enable-mixed-sandbox'],
env: {NODE_ENV: 'test'},
waitTimeout: 10e3
})
}
https://github.com/electron/spectron#new-applicationoptions
I got a response on that issue I raised and linked to in the comments:
app.enableMixedSandbox() // Experimental macOS Windows
See here for documentation.

How to detect that the Electron app is running for the first time?

I'm developing an App using the latest version of Electron-builder (using AutoUpadate).
Is there any way to know that the App is running for the first time after installation?
Ps: I have tried using electron-config but the user data files are not deleted after uninstall, and I needed to do some things with every installation (even if it's on the same machine).
Check for the squirrel-firstrun flag:
var cmd = process.argv[1];
if (cmd == '--squirrel-firstrun') {
// Running for the first time.
}
(you don't need to install anything for this to work)
Ref.
Your app could, in case that it doesn't exist, write a folder/file (with filename based on a timestamp?).
When app starts, always look for the file.
If there is no file, means its first time, do what you want and write file.
If there is a file means it's not the first time.
Don't know if there is something at Electron API!

Resources