Reputation: 71
Trying to send enter keystroke to headless chrome through remote debugging protocol. Here is the source code. Any help is appreciated. It doesn't seem to be working with Chrome 69. I have also tried keyIdentifier: 'U+000D', keyIdentifier: 'Enter' and key: '\u000d' in addition to windowsVirtualKeyCode: 13.
const CDP = require("chrome-remote-interface")
const chromeLauncher = require("chrome-launcher")
const getPort = require("get-port")
const R = require("rambdax")
const chromeFlags = [
"--disable-gpu",
"--disable-sync",
"--no-first-run",
"--headless",
"--window-size=1366,768"
]
const main = async () => {
try{
const port = await getPort()
const chrome = await chromeLauncher.launch({
chromeFlags,
port,
})
const client = await CDP({ port })
const { Page, Runtime, Input } = client
await Promise.all([
Page.enable(),
Runtime.enable(),
])
await Page.navigate({ url : 'https://www.google.com' })
await Page.loadEventFired()
await R.delay(1000)
await Input.dispatchKeyEvent({ type: 'char', text: 't' })
await R.delay(200)
await Input.dispatchKeyEvent({ type: 'char', text: 'e' })
await R.delay(200)
await Input.dispatchKeyEvent({ type: 'char', text: 's' })
await R.delay(200)
await Input.dispatchKeyEvent({ type: 'char', text: 't' })
await R.delay(200)
await Input.dispatchKeyEvent({ type: 'rawKeyDown', windowsVirtualKeyCode: 13 })
await R.delay(3000)
}catch(err){
console.log(err)
}
}
Upvotes: 1
Views: 1456
Reputation: 3925
See Github Issue 45 , where you also got the above code from. Using the following works:
await Input.dispatchKeyEvent({ type: 'char', text: "\r" })
Upvotes: 2