我有以下代碼:nightmare.js如何實現像window.callPhantom()函數的功能?
var nightmare = Nightmare(option)
nightmare
.goto('some url')
.evaluate(() => {
window.callback = function(cid) {
// do some stuff
// should screenshot at this point.
}
})
.screenshot('./png.png') //Doesn't get accurate png here
.end()
我想是在瀏覽器中添加範圍回調,並在瀏覽器的範圍,如果它存在在某些時候我會調用回調函數。在那個回調函數中,我會調用主進程在該回調函數結束時截圖。
它像phantom.js中的window.callPhantom
。但我無法找到如何在nightmare.js中做到這一點。
任何想法?
從瀏覽器發送的事件和[上偵聽事件](https://github.com/segmentio/nightmare#onevent-callback)在惡夢可能是一種選擇,我還沒有嘗試過不過。還有一個圖書館[噩夢 - 自定義事件](https://github.com/rosshinkley/nightmare-custom-event)添加自定義事件。 – pcworld