Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Download with headless: true works fine , but with headless: false not; plw 1.8.0 #5091

Closed
osmenia opened this issue Jan 21, 2021 · 4 comments

Comments

@osmenia
Copy link

osmenia commented Jan 21, 2021

Hi Team,

plw 1.8.0
with headless: false code works fine, but with headless: true only first element is downloaded.

plw 1.3.0
works fine with both params (headless: false & headless: true)

What could be a problem with 1.8.0?

tnx a lot

const playwright = require("playwright");

(async () => {
  const browser = await playwright.chromium.launch({ headless: false });
  const context = await browser.newContext({
    acceptDownloads: true,
  });
  const page = await context.newPage();
  await page.goto(
    "https://file-examples.com/index.php/sample-documents-download/sample-xls-download/"
  );

  const handles = await page.$$("#table-files .file-link");

  for (let num of handles) {
    const [download] = await Promise.all([
      page.waitForEvent("download"), // wait for download to start
      (await num.$("a.btn")).click(),
    ]);
    const path = await download.path();
    console.log(path);
  }
  await browser.close();
})();
@pavelfeldman
Copy link
Member

It works for me, downloads a bunch of files:

/tmp/playwright_downloads-FjfvTw/4ea77094-fdc6-4c34-84a1-fbb03511b9e6
/tmp/playwright_downloads-FjfvTw/2ad79520-533d-4e0c-bb20-24713b007e47
/tmp/playwright_downloads-FjfvTw/530c8eaa-205b-4562-bc76-d264664a3656
/tmp/playwright_downloads-FjfvTw/f0789fc3-2a20-4f28-8a78-54558f7eff61
/tmp/playwright_downloads-FjfvTw/e820f9e7-369a-4dc5-bdad-95e38fee549a
/tmp/playwright_downloads-FjfvTw/72384378-45bc-4f68-9da3-3656793f3cfa
/tmp/playwright_downloads-FjfvTw/d4b138c4-ac42-4e70-8634-013a76f76035
/tmp/playwright_downloads-FjfvTw/a616a379-bdee-42c3-ac9b-56a8972c74bd
/tmp/playwright_downloads-FjfvTw/1f24ac29-e774-4b5c-bf8e-7cfcb0f809c1
/tmp/playwright_downloads-FjfvTw/9b4585c6-abca-48f5-9676-708e99b1d0c7

What is you OS?

@osmenia
Copy link
Author

osmenia commented Jan 22, 2021

Windows 10 and Ubuntu

Test_1

@pavelfeldman
Copy link
Member

Oh, you said

with headless: false code works fine, but with headless: true only first element is downloaded.
but it looks the opposite.

Either way, what happens is that once you click on the first link, the page navigates to a grammarly ad. So you can't really click on any other links - they no longer exist, you are on a different page, there is nothing to click.

It looks like the site is using some heuristic to either show or not show the ad for you. Or maybe headless is just much faster, so it gets a chance to click all the links before the page navigates.

@pavelfeldman
Copy link
Member

Closing this issue as it isn't a bug, you should probably re-navigate to the original page after each download and click i-th link in the loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants