david-dick / firefox-marionette

This is a client module to automate the Mozilla Firefox browser via the Marionette protocol
https://metacpan.org/dist/Firefox-Marionette
Other
12 stars 3 forks source link

File downloads always timeout #13

Closed aluaces closed 2 years ago

aluaces commented 2 years ago

Hi, when downloading a file that is not directly opened by firefox, even the download finishes in a few seconds, the script does not return until it timeouts., and the exception breaks my loop.

This is a minimal example:

$firefox->go("https://github.com/david-dick/firefox-marionette/archive/refs/heads/master.zip")

does not return immediately.

david-dick commented 2 years ago

Hmmm... this is an interesting one. By setting the page load strategy to "none" ("eager" isn't good enough), you can get the download to work, but nothing else.

Example code follows;

#! /usr/bin/perl

use strict;
use warnings;
use Firefox::Marionette();

my $firefox = Firefox::Marionette->new(
    capabilities => Firefox::Marionette::Capabilities->new( page_load_strategy => 'none' ),
    debug => 1,
    );
$firefox->go("https://github.com/david-dick/firefox-marionette/archive/refs/heads/master.zip");
while(!$firefox->downloads()) { sleep 1 }
while($firefox->downloading()) { sleep 1 }
foreach my $path ($firefox->downloads()) {
   warn "$path has been downloaded";
}
$firefox->quit();

I don't think there is anything this module can do to fix this unfortunately. Would be willing to discuss any alternative. Maybe a documentation patch to show the above code option?

Thoughts?

aluaces commented 2 years ago

Thanks for the analysis, I'm going to see if I can track why this is happening (after all, your example downloading a metacpan distribution works perfectly), and if not, suggest that change in the documentation.

Would be acceptable for it to be in a CAVEATS section at the end of the POD?

david-dick commented 2 years ago

If you run my code above (debug turned on), but with the page_load_strategy set to "eager", you can see firefox hanging after the get request is sent. There's very little my module can do at that point.

aluaces commented 2 years ago

Sorry, I'm new to this and I didn't want to imply your module was to blame. What I wanted to say is: if marionette blocks, then I could ask its developers for an explanation about it. The other unknown is why it is blocking on downloads as this one on github (but it is not the only place, it happened to me for the first time in a complete different page) but not on metacpan.org. Maybe they could say.

Indeed I executed your code the first time you posted it, but surprisingly when activating the display no downlading icon was shown, and the program exited succesfully, although after several minutes.

Now I'm executing it in a different computer and your example works as I imagine you intended: the download icon is there (after I put visible=>1) and it exits as soon as the download is done. I'm trying it again on the other computer and seeing if I can spot the difference, or if I made some mistake.

david-dick commented 2 years ago

That is very interesting. Another option you can use is to see the entire network exchange with the following notation;


my $firefox = Firefox::Marionette->new( devtools => 1 );

Click the Network tab on the Developer Tools window to view the network trace.

If you have a URL that works and downloads a file but doesn't hang firefox, please let me know.

david-dick commented 2 years ago

Documentation fixed.