gpt4 book ai didi

javascript - NightmareJS 不打开浏览器

转载 作者:行者123 更新时间:2023-11-29 23:35:09 24 4
gpt4 key购买 nike

我目前正在制作一个 electron 应用程序,我在项目中包含了 Nightmare。

  var nightmare = Nightmare({ show: true })

nightmare
.goto('http://yahoo.com')
.type('input[title="Search"]', 'github nightmare')
.click('.searchsubmit').then(nightmare.show())

这就是我希望在打开浏览器窗口时看到的代码,请访问 yahoo.com。

我怎么放show:true还是headless?

终端:

$ DEBUG=nightmare* electron .
nightmare queuing process start +0ms
nightmare queueing action "goto" for http://yahoo.com +3ms
nightmare queueing action "type" +2ms
nightmare queueing action "click" +0ms
nightmare running +0ms

我还更改了包含整个代码段的代码:

ipc.on('launchBrowser', function(event, data){
var nightmare = Nightmare({ show: true })

nightmare
.goto('http://yahoo.com')
.type('input[title="Search"]', 'github nightmare')
.click('.searchsubmit').then(() => { });
});

它没有按预期工作是因为我没有明确使用 node.js,而是电子?

最佳答案

如果你没有收到它的值,我认为你不能在“then”中调用带有 () 的函数

也许它会抛出某种错误,即使您不需要 nightmare.show() 因为您在创建实例时设置了属性

要么像这样改变:

  var nightmare = Nightmare({ show: true })

nightmare
.goto('http://yahoo.com')
.type('input[title="Search"]', 'github nightmare')
.click('.searchsubmit').then(nightmare.show)

或者这个:

  var nightmare = Nightmare({ show: true })

nightmare
.goto('http://yahoo.com')
.type('input[title="Search"]', 'github nightmare')
.click('.searchsubmit').then(() => { nightmare.show(); });

或完全删除 nightmare.show()

  var nightmare = Nightmare({ show: true })

nightmare
.goto('http://yahoo.com')
.type('input[title="Search"]', 'github nightmare')
.click('.searchsubmit').then(() => { //Something cool });

关于javascript - NightmareJS 不打开浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46467492/

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