gpt4 book ai didi

javascript - 使用 Nightmare 将消息从渲染器进程发送到 Node 进程

转载 作者:行者123 更新时间:2023-12-03 07:23:48 26 4
gpt4 key购买 nike

如何在 Nightmare 中将消息从渲染器进程(网页)发送到主进程( Node )?有ipc Electron and Nightmare 中的 是建立在 Electron 之上的,所以我认为这是可能的,但我不知道如何实现。

类似的事情:

http://example.com

<script type="text/javascript">
window.postMessage('aaaaaaaa', '*');
</script>

index.js

let nightmare = new Nightmare();
nightmare.on('message', function(e) {
console.log(e.data); // will output aaaaaaaa
});

nightmare.goto('http://example.com').then(function() {
console.log('loaded');
});

最佳答案

如果您尝试从页面获取数据,为什么不使用.evaluate()?像这样的东西:

nightmare.goto('http://example.com')
.evaluate(function(){
var element = document.querySelector('some-element.query');
return element.value;
})
.then(function(value){
console.log(value);
});
<小时/>

对于您最初的示例,除非在 Nightmare 上允许插件到它所 package 的 Electron 实例,否则您无法发送任意事件。 Nightmare #354 中讨论过向 Nightmare 核心添加任意事件。 ,我试图在 Nightmare 中修复 #367 。确定添加任意事件应该是#425下的插件。插件 PR 尚未被接受,但插件 fork is already completed 的插件.

关于javascript - 使用 Nightmare 将消息从渲染器进程发送到 Node 进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36091760/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com