chromeless icon indicating copy to clipboard operation
chromeless copied to clipboard

blank page on lambda environment

Open selul opened this issue 6 years ago • 18 comments

Hello,

I'm trying to run the chromeless via AWS Lambda and i'm getting an odd error which i'm having trouble solving it. It seems that the screenshots are uploaded to S3 as white pages, i.e -> https://185387363267-us-east-1-chromeless.s3.amazonaws.com/cjelwu0zn000l01qamfomc5ky.png The script i'm running is:

const {Chromeless} = require('chromeless')

async function run() {
    const chromeless = new Chromeless({
        remote: {
            endpointUrl: 'https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev',
            apiKey: 'xxxxxxxxxx',
        },
        debug: true
    })

    const screenshot = await chromeless
        .goto('https://www.google.com')
        .screenshot()

    console.log(screenshot)

    await chromeless.end()
}

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

I've tried also this one:

const {Chromeless} = require('chromeless')

async function run() {
    const chromeless = new Chromeless({
        remote: {
            endpointUrl: 'https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev',
            apiKey: 'xxxxxxxxxx',
        },
        debug: true
    })
 const screenshot = await chromeless
        .goto('https://www.google.com')
        .type('chromeless', 'input[name="q"]')
        .press(13)
        .wait('#resultStats')
        .screenshot()

    console.log(screenshot) // prints local file path or S3 url

    await chromeless.end()
}

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

And i'm getting this error Error: wait("input[name="q"]") timed out after 10000ms followed by Chromeless Proxy disconnected due to inactivity (no commands sent for 30 seconds).

For both examples, the most relevant CloudWatch log that could be tied to both examples is: Chrome result undefined triggered here

I've tried changing the user agent, tested on personal websites with no firewall that could block access and i'm still getting the same error.

Any clue what it could be ?

  • Chromeless Version I'm using: 1.5.0
  • Serverless Version I'm using: 1.26.1
  • Operating System: MacOS Sierra

Thanks a lot for any help.

selul avatar Mar 10 '18 22:03 selul

+1

I'm also getting blank screenshots in S3 and the log message Chrome result undefined in CloudWatch. I've tried setting the user agent as described in https://github.com/graphcool/chromeless/issues/195, but it didn't help.

Using:

  • Chromeless 1.5.1
  • Serverless 1.26.1
  • Node 9.8.0
  • MacOS El Capitan

lhadjchikh avatar Mar 11 '18 00:03 lhadjchikh

Exact same issue blank jpg Chromeless 1.5.1 Serverless 1.26.1

tvpavan avatar Mar 12 '18 08:03 tvpavan

+3 ( if not +1 ) Exact same issues for blank jpg or Error: wait("input[name="q"]") timed out after 10000m

wongfei2009 avatar Mar 12 '18 09:03 wongfei2009

+4 same here

andreaskweber avatar Mar 15 '18 16:03 andreaskweber

+1 seeing the same issue.

Chromeless 1.5.1 Serverless 1.26.1

Also seeing the same log message. It appears to happen after the .goto call. The queue seems to be returning a null result, which means that the call technically is 'succeeding', so the next call (such as screenshot) continues to execute even though the url hasn't loaded.

ddura avatar Mar 15 '18 17:03 ddura

+1 chromeless 1.3.0 serverless 1.26.1

node 6.10.3

Error Message: Running remotely: {"type":"setUserAgent","useragent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36"} Running remotely: {"type":"goto","url":"https://github.com/adieuadieu/serverless-chrome/issues/120"} Running remotely: {"type":"wait","selector":"#partial-discussion-header > div.gh-header-show > h1 > span.js-issue-title"} Error: wait("#partial-discussion-header > div.gh-header-show > h1 > span.js-issue-title") timed out after 10000ms

same code runs correctly if i used local chrome

shawnliujw avatar Mar 19 '18 14:03 shawnliujw

Throwing in another +1, just got this.

chromeless 1.5.1 serverless 1.26.1

cantsin avatar Mar 20 '18 22:03 cantsin

FWIW, pinning the serverless-plugin-chrome version to 1.0.0-38, as mentioned in #387 resolved this for me.

danrubins avatar Mar 21 '18 21:03 danrubins

@dhrubins cool, it resolve my problems thanks. here is the package.json i used { "name": "chromeless-remotechrome-servie", "version": "1.3.0", "description": "The Chromeless Proxy AWS Lambda service", "homepage": "https://github.com/graphcool/chromeless", "license": "MIT", "engines": { "node": ">= 6.10.0" }, "scripts": { "deploy": "serverless deploy" }, "dependencies": { "aws4": "^1.6.0", "chromeless": "^1.3.0", "cuid": "^1.3.8", "mqtt": "^2.11.0", "source-map-support": "^0.4.15" }, "devDependencies": { "@types/cuid": "^1.3.0", "@types/node": "^8.0.15", "serverless": "^1.19.0", "serverless-offline": "^3.15.3", "serverless-plugin-chrome": "1.0.0-38", "serverless-plugin-typescript": "^1.0.0" } }

NOTE: must use node 6.10 , i used v6.10.3 , and i tried 8.9.0 , failed

shawnliujw avatar Mar 22 '18 02:03 shawnliujw

Don't forget to run npm run deploy after pinning serverless-plugin-chrome version to 1.0.0-38, like I did for a few hours.

martco avatar Mar 23 '18 16:03 martco

After pinning to 1.0.0-38 I had to run npm install to update the dependency in the package.json (shawnLiujianwei has an example above) then run npm run deploy as martco mentioned in order to update the lambda.

dmeola avatar Mar 24 '18 23:03 dmeola

+1 the same issue on 1.0.0-41 deleting node_modules, pinning to -38 and re-deploying fixed the issue

adrach avatar Apr 10 '18 04:04 adrach

After following the above, pinning to 1.0.0-38 as @dhrubins suggested and having the exact same package.json as @shawnLiujianwei, I'm still getting a blank screenshot at ~400bytes. OS is OSX if that makes any difference.

{"name":"chromeless-remotechrome-service","version":"1.3.0","description":"The Chromeless Proxy AWS Lambda service","homepage":"https://github.com/graphcool/chromeless","license":"MIT","engines":{"node":">= 6.10.0"},"scripts":{"deploy":"serverless deploy"},"dependencies":{"aws4":"^1.6.0","chromeless":"^1.3.0","cuid":"^1.3.8","mqtt":"^2.11.0","source-map-support":"^0.4.15"},"devDependencies":{"@types/cuid":"^1.3.0","@types/node":"^8.0.15","serverless":"^1.19.0","serverless-offline":"^3.15.3","serverless-plugin-chrome":"^1.0.0-38","serverless-plugin-typescript":"^1.0.0"}}

Testing code is:

const Chromeless = require('chromeless').default

async function run() {
 const chromeless = new Chromeless({
  remote: {
    endpointUrl: 'https://XXXXXXXXXX.execute-api.eu-west-1.amazonaws.com/dev',
    apiKey: 'your-api-key-here',
  },
  debug: true
})

  const screenshot = await chromeless
    .goto('https://www.instagram.com/serverlessinc/')
    .wait(5000)
    .scrollTo(0, 1200)
    .screenshot()

  console.log(screenshot) // prints local file path or S3 url

  await chromeless.end()
}

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

Console:

Connected to message broker. Running remotely: {"type":"goto","url":"https://www.instagram.com/serverlessinc/"} Running remotely: {"type":"wait","timeout":5000} Running remotely: {"type":"scrollTo","x":0,"y":1200} Running remotely: {"type":"returnScreenshot"} https://XXXXXXXXX-eu-west-1-chromeless.s3.amazonaws.com/cjgp4qyve000301p086qtqiyq.png

co851002 avatar May 02 '18 13:05 co851002

@co851002 In your package.json, try reinstalling node_modules after setting "chromeless":"1.2.0" instead of "chromeless":"^1.3.0".

mitin001 avatar May 02 '18 16:05 mitin001

@co851002 I installed and deployed using npm I installed using this package: https://nodejs.org/download/release/v6.11.2/node-v6.11.2.pkg I also used this yarn.lock: https://raw.githubusercontent.com/nsfmc/chromeless/6f0e5b4f601f96eedff42b9cfe48ff37619cd3b1/serverless/yarn.lock Did not need to delete the CloudFormation stack, redeployment worked.

Also, are you taking the screenshot immediately after using the goto command? If so, try chaining .wait(1000) to it before chaining .screenshot() so Chrome gives the page 1 second to load before capturing its screenshot.

mitin001 avatar May 02 '18 17:05 mitin001

@co851002 Hey I also noticed that you're not pinning the version of serverless-plugin-chrome to 1.0.0-38. In your package.json you have "serverless-plugin-chrome":"^1.0.0-38" but it should be "serverless-plugin-chrome":"1.0.0-38"

mitin001 avatar May 09 '18 15:05 mitin001

@mitin001 Thank you! For me, it working now.

dragg avatar May 15 '18 06:05 dragg