1

Using chromeless to run tests every 5 minutes to verify I can log into a website and that content is available.

Code looks like this:

const { Chromeless } = require('chromeless')

async function run() {
  const chromeless = new Chromeless({
    remote: {
      endpointUrl: 'https://abc1234567.execute-api.us-west-2.amazonaws.com/dev',
      apiKey: 'abc123xyz987'
    }
  })

  const screenshot = await chromeless
    .clearCookies()
    .setUserAgent('some-user-agent')
    .goto('https://www.example.com')
    .type('username', 'input[name="username"]')
    .type('super_secret', 'input[name="password"]')
    .click('#loginButton')
    .wait('#TitleTagOnceLoggedIn')
    .screenshot()

  console.log(screenshot)

  const report = await chromeless
    .setUserAgent('some-user-agent')
    .goto('https://www.example.com/only/accessible/if/logged/in')
    .wait('#TitleTagForPageWhenLoggedIn')
    .screenshot()
  console.log(report)

  await chromeless.end()
}

run().catch(console.error.bind(console))

This works fine, however once every 10-20 times I run it, I receive the following error

Chromeless Proxy disconnected due to inactivity (no commands sent for 30 seconds).

In the cloudwatch logs from my lambda function I get a similar error

Timing out. No requests received for 30 seconds

How can I set this to retry if I get the inactivity errors?

Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
maafk
  • 6,176
  • 5
  • 35
  • 58

1 Answers1

0

Convert

await chromeless.end()

to

chromeless.end().catch(callback).then(callback)

and move it into a non-async function, e.g. function end (callback) {...}.

Then have your code wait for run to finish executing and then execute end with a callback handling the result. See https://github.com/graphcool/chromeless/issues/259

Andrey Mitin
  • 26
  • 1
  • 5