Ввод события нажатия клавиши не отправляется - PullRequest
0 голосов
/ 02 октября 2018

Попытка отправки нажатия клавиши ввода в chrome без заголовка через протокол удаленной отладки.Вот исходный код.Любая помощь приветствуется.Кажется, он не работает с Chrome 69. Я также попробовал keyIdentifier: 'U + 000D', keyIdentifier: 'Enter' и key: '\ u000d' в дополнение к 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)
  }
}

1 Ответ

0 голосов
/ 02 октября 2018

См. Github Issue 45 , откуда вы также получили вышеуказанный код.Используя следующие работы:

await Input.dispatchKeyEvent({ type: 'char', text: "\r" })
...