2
このコードをテストして結果がアサートされるまで待ちます。問題がどこにあるかわからない場合は、最後にPromise.resolve()を返しますが、コードが実行される前にend
を記録してください。async/Chromeリモートインターフェイスの問題を待ちます
Page.loadEventFired
の前にawait
を付ける必要がありますか?
const CDP = require('chrome-remote-interface')
async function x() {
const protocol = await CDP()
const timeout = ms => new Promise(resolve => setTimeout(resolve, ms))
// See API docs: https://chromedevtools.github.io/devtools-protocol/
const { Page, Runtime, DOM } = protocol
await Promise.all([Page.enable(), Runtime.enable(), DOM.enable()])
Page.navigate({ url: 'http://example.com' })
// wait until the page says it's loaded...
return Page.loadEventFired(async() => {
console.log('Page loaded! Now waiting a few seconds for all the JS to load...')
await timeout(3000) // give the JS some time to load
protocol.close()
console.log('Processing page source...')
console.log('Doing some fancy stuff here ...')
console.log('All done.')
return Promise.resolve()
})
}
(async function() {
console.log('start')
await x()
console.log('end')
})()
これは簡単でした。ありがとう! async/awaitを完全に取得しようとするともう少し時間がかかるでしょう。 – Patrick