electron 尝试运行executeJavascript()时出错

vxqlmq5t  于 2022-12-28  发布在  Electron
关注(0)|答案(1)|浏览(543)

你好,我希望能够插入一个用python编写的函数的结果,我在变量data中得到了这个结果,但是当我尝试插入这个变量的值时,命令document.getElementById("h1-fs-s5").innerHTML在尝试连接时没有执行数据的值,并且出现了一个错误。
下面是代码的一部分:

subpy.stdout.on('data',function(data){
          console.log("data: ",data.toString('utf8'));
            mainWindow.webContents.executeJavaScript(` document.getElementById("h1-fs-s5").innerHTML = "${data.toString('utf8')}" ; `);
          });

下面是我的错误:

(node:2208) UnhandledPromiseRejectionWarning: Error: Script failed to execute, this normally means an error was thrown. Check the renderer console for the error.
    at WebFrame.<computed> (C:\Users\cantr\Desktop\Stage ing├®nieur KOMILFO SPORT\Sail Vision\Dashboard\node_modules\electron\dist\resources\electron.asar\renderer\api\web-frame.js:64:33)
    at WebFrame.executeJavaScript (C:\Users\cantr\Desktop\Stage ing├®nieur KOMILFO SPORT\Sail Vision\Dashboard\node_modules\electron\dist\resources\electron.asar\common\api\deprecate.js:114:32)
    at C:\Users\cantr\Desktop\Stage ing├®nieur KOMILFO SPORT\Sail Vision\Dashboard\node_modules\electron\dist\resources\electron.asar\renderer\web-frame-init.js:11:43
    at C:\Users\cantr\Desktop\Stage ing├®nieur KOMILFO SPORT\Sail Vision\Dashboard\node_modules\electron\dist\resources\electron.asar\renderer\ipc-renderer-internal-utils.js:7:40
    at new Promise (<anonymous>)
    at EventEmitter.<anonymous> (C:\Users\cantr\Desktop\Stage ing├®nieur KOMILFO SPORT\Sail Vision\Dashboard\node_modules\electron\dist\resources\electron.asar\renderer\ipc-renderer-internal-utils.js:7:9)
    at EventEmitter.emit (events.js:200:13)
    at Object.onMessage (C:\Users\cantr\Desktop\Stage ing├®nieur KOMILFO SPORT\Sail Vision\Dashboard\node_modules\electron\dist\resources\electron.asar\renderer\init.js:42:16)
(node:2208) UnhandledPromiseRejectionWarning: Error: Script failed to execute, this normally means an error was thrown. Check the renderer console for the error.
    at WebFrame.<computed> (C:\Users\cantr\Desktop\Stage ing├®nieur KOMILFO SPORT\Sail Vision\Dashboard\node_modules\electron\dist\resources\electron.asar\renderer\api\web-frame.js:64:33)
    at WebFrame.executeJavaScript (C:\Users\cantr\Desktop\Stage ing├®nieur KOMILFO SPORT\Sail Vision\Dashboard\node_modules\electron\dist\resources\electron.asar\common\api\deprecate.js:114:32)
    at C:\Users\cantr\Desktop\Stage ing├®nieur KOMILFO SPORT\Sail Vision\Dashboard\node_modules\electron\dist\resources\electron.asar\renderer\web-frame-init.js:11:43
    at C:\Users\cantr\Desktop\Stage ing├®nieur KOMILFO SPORT\Sail Vision\Dashboard\node_modules\electron\dist\resources\electron.asar\renderer\ipc-renderer-internal-utils.js:7:40
    at new Promise (<anonymous>)
    at EventEmitter.<anonymous> (C:\Users\cantr\Desktop\Stage ing├®nieur KOMILFO SPORT\Sail Vision\Dashboard\node_modules\electron\dist\resources\electron.asar\renderer\ipc-renderer-internal-utils.js:7:9)
    at EventEmitter.emit (events.js:200:13)
    at Object.onMessage (C:\Users\cantr\Desktop\Stage ing├®nieur KOMILFO SPORT\Sail Vision\Dashboard\node_modules\electron\dist\resources\electron.asar\renderer\init.js:42:16)  
(node:2208) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2208) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2208) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process 
with a non-zero exit code.
(node:2208) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process 
with a non-zero exit code.

此致,

xmq68pz9

xmq68pz91#

问题出在python程序返回的数据类型上,所以我通过parseInt(data)函数转换数据,使其工作,而不是使用toString('utf8')

相关问题