javascript - 打印后 Electron 崩溃

标签 javascript node.js electron

我有一段代码可以打开一个新的弹出窗口并触发打印。打印效果很好,但是当我关闭弹出窗口时,应用程序崩溃,并从终端显示“This is probably not a problem with npm. There is likely additional logging output above.”错误

var img = jQuery("#imgWrap").html();
var popup = window.open();
console.log(popup);
popup.focus();
popup.document.write(img);
popup.print();
这是完整的日志记录输出
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'start'
1 verbose cli ]
2 info using npm@6.14.8
3 info using node@v14.11.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle electron-photobooth@1.0.0~prestart: electron-photobooth@1.0.0
6 info lifecycle electron-photobooth@1.0.0~start: electron-photobooth@1.0.0
7 verbose lifecycle electron-photobooth@1.0.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle electron-photobooth@1.0.0~start: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\a_bee\Documents\apps\ElectronPhotobooth\node_modules\.bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\TortoiseSVN\bin;C:\Program Files\nodejs\;C:\Users\a_bee\AppData\Local\Microsoft\WindowsApps;;C:\Users\a_bee\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\a_bee\AppData\Roaming\npm
9 verbose lifecycle electron-photobooth@1.0.0~start: CWD: C:\Users\a_bee\Documents\apps\ElectronPhotobooth
10 silly lifecycle electron-photobooth@1.0.0~start: Args: [ '/d /s /c', 'electron .' ]
11 silly lifecycle electron-photobooth@1.0.0~start: Returned: code: 3221226505  signal: null
12 info lifecycle electron-photobooth@1.0.0~start: Failed to exec start script
13 verbose stack Error: electron-photobooth@1.0.0 start: `electron .`
13 verbose stack Exit status 3221226505
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:314:20)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:314:20)
13 verbose stack     at maybeClose (internal/child_process.js:1047:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
14 verbose pkgid electron-photobooth@1.0.0
15 verbose cwd C:\Users\a_bee\Documents\apps\ElectronPhotobooth
16 verbose Windows_NT 10.0.18363
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
18 verbose node v14.11.0
19 verbose npm  v6.14.8
20 error code ELIFECYCLE
21 error errno 3221226505
22 error electron-photobooth@1.0.0 start: `electron .`
22 error Exit status 3221226505
23 error Failed at the electron-photobooth@1.0.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 3221226505, true ]

最佳答案

对此进行了更多的努力,所以我尝试更改我正在使用的Electron的版本。在Electron 9.3.1上,它可以使用以下代码工作:

const electron = require('electron');
const BrowserWindow = electron.remote.BrowserWindow; 
let win = BrowserWindow.getFocusedWindow();

function print(){
   win.webContents.print({}, function(response){
     console.log(response);
   });
}

关于javascript - 打印后 Electron 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63912937/

相关文章:

javascript - 何时在 JavaScript 中使用双非 (!!) 运算符

javascript - 使用 chartjs 在圆环图中标记问题

node.js - 如何在hubot中没有脚本目录的脚本中发送消息?

node.js - 用于 SPA 应用程序的 .NET Core Docker 镜像

javascript - regEx忽略项目顶层的build和dist目录?

javascript - Electron:在 mainWindow 加载时使用 mainWindow.webContents.send

javascript - 删除元素后的 jQuery 动画

node.js - 使用 Passport 注册并使用 Sequelize 保存不起作用(意外的 ' ')

javascript - 引用错误: document is not defined at compile/Electron

javascript - 如何在flexslider的每张幻灯片中显示6张图片?