【问题标题】:Electron crashes when making an HTTPS request inside an addeventlistener callback function在 addeventlistener 回调函数中发出 HTTPS 请求时,Electron 崩溃
【发布时间】:2017-07-11 14:24:48
【问题描述】:

我正在制作一个基本的 Electron 应用程序,用于将用户登录到系统中。用户名和密码由用户通过表单文本输入提供,当点击“登录”按钮时,程序会发出几个 https 请求,让用户登录。

我有一个附加到“登录”按钮的事件侦听器,该按钮在单击按钮时触发。它的回调函数应该获取输入的用户名和密码,并发出必要的 https 请求以使用户登录。但是,当 https 请求在回调函数内部时,Electron 中的渲染器进程崩溃(显示白屏和“开发工具已断开连接”)。

下面是一些描述问题的伪代码:

//This case crashes Electron
button.addEventListener('click', function() {
    username = document.getElementById('username').value;
    password = document.getElementById('password').value;

    req = https.request(options, function(res) {
        //Login stuff here, including a post request
        //that sends the username and password to a server
    });
    req.end();
});  

当我将 https 请求移出回调函数并将用户名和密码硬编码到程序中时,一切正常。

工作案例的伪代码:

//This case does not crash Electron
username = "someUsername"
password = "somePassword"

req = https.request(options, function(res) {
    //Login stuff here, including another post request
    //that sends to username and password to a server
});

我希望能够动态获取用户名和密码,并发出必要的 https 请求以将用户登录到系统。我一直在四处寻找有关此的任何信息一段时间,但我找不到遇到类似问题的人。

任何帮助将不胜感激。谢谢!

【问题讨论】:

    标签: javascript node.js https crash electron


    【解决方案1】:

    已解决

    我的按钮被标记为“type='submit'”并将其切换为“type='button'”解决了问题。

    【讨论】:

      猜你喜欢
      • 2018-05-03
      • 1970-01-01
      • 2022-12-03
      • 2017-01-01
      • 2013-06-30
      • 1970-01-01
      • 1970-01-01
      • 2021-05-31
      • 1970-01-01
      相关资源
      最近更新 更多