我尝试在节点服务器上的电子项目中使用通知。因此,我使用以下命令在我的app文件夹中安装了节点通知程序模块。
$ npm install --save node-notifier之后,我添加按钮到我的网页,以显示通知消息。
当用户单击按钮时,在js方法下面运行:
<script type = "text/javascript">
const notifier = require('node-notifier')
const path = require('path');
document.getElementById('notify').onclick = (event) => {
notifier.notify ({
title: 'My awesome title',
message: 'Hello from electron, Mr. User!',
icon: path.join('','images/images.png'), // Absolute path (doesn't work on balloons)
sound: true, // Only Notification Center or Windows Toasters
wait: true // Wait with callback, until user action is taken against notification
}, function (err, response) {
// Response is response from notification
});
notifier.on('click', function (notifierObject, options) {
console.log("You clicked on the notification")
});
notifier.on('timeout', function (notifierObject, options) {
console.log("Notification timed out!")
});
}
</script>但当我单击“通知”按钮时,会得到如下所示的错误:
Uncaught TypeError: _crypto.default.randomFillSync is not a function
rng @ Project\MyElectronProject\node_modules\uuid\dist\rng.js:19
v4 @ Project\MyElectronProject\node_modules\uuid\dist\v4.js:17
getPipeName @ Project\MyElectronProject\node_modules\node-notifier\notifiers\toaster.js:51
notifyRaw@ Project\MyElectronProject\node_modules\nodenotifier\notifiers\toaster.js:60
document.getElementById.onclick @notification_index.html:16 以上错误是在rng.js中抛出的rng函数。
function rng() {
if (poolPtr > rnds8Pool.length - 16) {
debugger;
_crypto.default.randomFillSync(rnds8Pool);
poolPtr = 0;
}不存在randomFillSync方法。我不明白这个错误,你以前见过这个错误吗?谢谢你的建议。
我在项目中使用的节点版本: v16.13.1
发布于 2022-01-06 10:35:05
节点通知器是nodejs模块,不能在浏览器脚本中使用.
我认为您应该在主进程中调用节点通知程序,然后从呈现程序进程到主进程进行通信。
https://stackoverflow.com/questions/70603828
复制相似问题