Zenika / alpine-chrome

Chrome Headless docker images built upon alpine official image
https://hub.docker.com/r/zenika/alpine-chrome
Apache License 2.0
1.83k stars 242 forks source link

Unable to download a file with Playwright inside the container (the process hangs) #107

Closed ilyanoskov closed 4 years ago

ilyanoskov commented 4 years ago

Describe the bug I am trying to download a file programmatically. The script runs fine outside of the container, but fails to download the file when I run it inside the container. All other steps in the Playwright script execute OK.

this is how I run my container :

docker container run -it --rm --ipc=host --security-opt seccomp=chrome.json -v $(pwd)/src:/usr/src/app/src ilyaanoskov/file-downloader node src/index

What is the expected behavior? The expected behavior is that the script downloads the file locally to a /tmp folder (just like Playwright does) and then I upload this file to S3

What is the actual behavior? The script fails to download the file, hanging in the process

Logs

  pw:api   attempting page.click action +6ms
  pw:api     waiting for element to be displayed, enabled and not moving +1ms
  pw:api     element is displayed and does not move +110ms
  pw:api     scrolling into view if needed +0ms
  pw:api     done scrolling +40ms
  pw:api     checking that element receives pointer events at (435,360.09) +235ms
  pw:api     element does receive pointer events, continuing input action +155ms
  pw:api     performing page.click action +1ms
  pw:api     page.click action done +57ms
  pw:api     waiting for scheduled navigations to finish +4ms
  pw:api     navigations have finished +40ms
  pw:api <= page.click succeeded +1ms
  pw:api <= page.waitForEvent failed +29s
(node:8) UnhandledPromiseRejectionWarning: TimeoutError: Timeout 30000ms exceeded during page.waitForEvent.
Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.
    at ProgressController.run (/usr/src/app/node_modules/playwright/lib/progress.js:72:30)
    at Page.waitForEvent (/usr/src/app/node_modules/playwright/lib/extendedEventEmitter.js:30:35)
    at /usr/src/app/src/index.js:57:10
(node:8) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
(node:8) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
jlandure commented 4 years ago

Hi @ilyanoskov

First, thank you for using this image and opening a bug. šŸ‘

I will look at this issue in 4 hours.

šŸ¤” I do not understand why you got an TimeoutError. Can you share to me the js file you're running with playwright? šŸ“ Thanks again.

ilyanoskov commented 4 years ago

@jlandure thanks for the fast response.

The script is very straightforward, it's just navigating to a page and clicking "download file" button.

Here is a part of the script that times out:

 const [ download ] = await Promise.all([
    page.waitForEvent('download'), // <-- start waiting for the download
    page.click('/div/div[2]/div[2]/button') // <-- perform the action that directly or indirectly initiates it.
  ]);

  const url = await download.url();
  const path = await download.path();

It executes fine outside of the container, but not inside.

Unfortunately the page I am trying to download the file on is behind a login, so you won't be able to reproduce it with my script. However, you could just try running the playwright script to download any file from anywhere (like pastebin.com) and see whether it actually downloads one?

ilyanoskov commented 4 years ago

@jlandure do you have any pointers in which direction I could look? I am trying to make this work or abandon the solution :) Thanks a lot in advance

jlandure commented 4 years ago

Hi @ilyanoskov

Sorry for the delay. šŸ˜Š

Did you find a solution for your problem? Do you have a working example outside the container to help me reproduce your problem?

Thanks again. šŸ‘

ilyanoskov commented 4 years ago

@jlandure I was able to use the official Microsoft playwright docker container for this. worked flawlessly!