question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Possible issue with downloads

See original GitHub issue
  • Playwright Version: 0.15.0
  • Operating System: Mac

TL;DR: downloads work. Just not all the time and I was trying to debug why.

Downloading on file.io

Upload a file to https://file.io as a good way to test this feature. Once you click on the link of an uploaded file, the file downloads and the link no longer works.

// starting up chromium (also tried firefox) with accept downloads
const headless = false;
const playwrightLaunch = await playwright['chromium'].launch({headless});
const context = await playwrightLaunch.newContext({acceptDownloads: true});
page = await context.newPage();
await page.goto('https://file.io', {waitUntil: 'networkidle'});

// created a file for upload
let filename = path.resolve(__dirname, 'hello.zzz');
fs.writeFileSync(filename, 'foo');
const input = await page.$('input[name="file"]');
await input.setInputFiles(filename);

// tried to download. 
let [ download1 ] = await Promise.all([
  page.waitForEvent('download'),
  page.click('span.lead a[target="_blank"]')
]);
console.log(await download1.path());

This times out. Also added some debugging to crPage.js:

_addSessionListeners() {
    this._eventListeners = [
        // ...
        helper_1.helper.addEventListener(this._client, 'Page.downloadProgress', event => {
            console.log('event: ' + JSON.stringify(event));
            return this._onDownloadProgress(event);
        }),
        // ...

The output of my test was a total byte of 0. This is never updated.

_onDownloadWillBegin
event: {"guid":"05ea81aa-7849-4308-9b96-6510ed05fb1d","totalBytes":0,"receivedBytes":0,"state":"inProgress"}
_onDownloadProgress inProgress
{"guid":"05ea81aa-7849-4308-9b96-6510ed05fb1d","totalBytes":0,"receivedBytes":0,"state":"inProgress"}
event: {"guid":"05ea81aa-7849-4308-9b96-6510ed05fb1d","totalBytes":0,"receivedBytes":11,"state":"inProgress"}
_onDownloadProgress inProgress
{"guid":"05ea81aa-7849-4308-9b96-6510ed05fb1d","totalBytes":0,"receivedBytes":11,"state":"inProgress"}

My guess is that there is some logic happening that if the totalBytes != receivedBytes that the state is inProgress.

Downloading from GitHub

page = await context.newPage();
page.goto('https://github.com/microsoft/playwright/releases', {waitUntil: 'networkidle'});

let [ download2 ] = await Promise.all([
  page.waitForEvent('download'),
  page.click('a[href="/microsoft/playwright/archive/v0.13.0.zip"]')
]);

console.log(await download2.path());

Output:

path /var/folders/ft/1c7_rwcx16xcckqq1sl43b2m0000gn/T/playwright_downloads-Ql10tO
event: {"guid":"80c57044-121f-4819-aa4f-9d0477be0305","totalBytes":0,"receivedBytes":0,"state":"inProgress"}
_onDownloadProgress inProgress
{"guid":"80c57044-121f-4819-aa4f-9d0477be0305","totalBytes":0,"receivedBytes":0,"state":"inProgress"}
event: {"guid":"80c57044-121f-4819-aa4f-9d0477be0305","totalBytes":0,"receivedBytes":0,"state":"inProgress"}
_onDownloadProgress inProgress
{"guid":"80c57044-121f-4819-aa4f-9d0477be0305","totalBytes":0,"receivedBytes":0,"state":"inProgress"}
event: {"guid":"80c57044-121f-4819-aa4f-9d0477be0305","totalBytes":0,"receivedBytes":1573114,"state":"inProgress"}
_onDownloadProgress inProgress
{"guid":"80c57044-121f-4819-aa4f-9d0477be0305","totalBytes":0,"receivedBytes":1573114,"state":"inProgress"}
event: {"guid":"80c57044-121f-4819-aa4f-9d0477be0305","totalBytes":0,"receivedBytes":1573114,"state":"inProgress"}
_onDownloadProgress inProgress
{"guid":"80c57044-121f-4819-aa4f-9d0477be0305","totalBytes":0,"receivedBytes":1573114,"state":"inProgress"}
event: {"guid":"80c57044-121f-4819-aa4f-9d0477be0305","totalBytes":1573114,"receivedBytes":1573114,"state":"inProgress"}
_onDownloadProgress inProgress
{"guid":"80c57044-121f-4819-aa4f-9d0477be0305","totalBytes":1573114,"receivedBytes":1573114,"state":"inProgress"}
event: {"guid":"80c57044-121f-4819-aa4f-9d0477be0305","totalBytes":1573114,"receivedBytes":1573114,"state":"completed"}
_onDownloadProgress completed
{"guid":"80c57044-121f-4819-aa4f-9d0477be0305","totalBytes":1573114,"receivedBytes":1573114,"state":"completed"}
_reportFinished

Describe the bug

This is possibly a bug or this is working as-intended. If this is as-intended, then there should be documentation what situation why. When downloading, files, I sometimes will do a HEAD call on the file, that provides me a content-length header. When I do it for GitHub, I get a content-length of 1573114 (curl -v -X HEAD https://codeload.github.com/microsoft/playwright/zip/v0.13.0). When I do it for file.io, it invalidates the download. Anyway, I did make a HEAD call against the link, there is no content-length. Anyway, I think it has something to do with that.

Example test code: https://github.com/cnishina/protractor-experiments/tree/master/playwright-files

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
yury-scommented, Apr 25, 2020

Thanks for the investigation! This is similar to the other new page downloads that we currently don’t report correctly (e.g. alt+click). I’ve added a new test for this specific case #1984

1reaction
pavelfeldmancommented, Apr 25, 2020

Oh, that’s a great investigation, thanks @cnishina , @rwoll . I don’t think we have tests for downloads that also specify other targets.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix file download errors - Google Chrome Help
If you get an error message on Chrome when you try to download apps, themes, extensions, or other files, try these fixes.
Read more >
What to do if you can't download or save files | Firefox Help
Clearing the download history can fix some problems with downloading files: ... In the Downloads window, click Clear Downloads. Close the Downloads window....
Read more >
Unable to download item please try again … - Apple Community
"Unable to download item please try again later: I'm not trying to download anything that's the problem. Just randomly occurs whenever it feels...
Read more >
10060 - Downloads stuck at "Starting..." - chromium - Monorail
I found the workaround. Just delete the "Web Data" sqlite file. It appear to look just fine when I inspected all tables and...
Read more >
Files Fail To Download - Bug Reporting - Giant Bomb
A possible workaround could be downthemall for firefox, it lets you resume and there is also a "force download" that got me through...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found