http://qs321.pair.com?node_id=11116743

1nelly1 has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
I installed WWW::Mechanize::Chrome on Windows with Strawberry Perl. Just for your information, I had to force installation of Log::Log4perl as already discussed here.
According to the author the method saveResources_future is a rough prototype. However for my purpose it is already working fine. But I can't get the method to save the files in the intended directory which I pass to the method via target_dir option. The files are always saved in the current working directory. The target_file option works well. Is this my fault or because the method is still a prototype? I would just like to save the files somewehere else no matter where the target_file is stored and what their relation is to the target_file.

Another problem I faced is that the tab=>'current' option is not working. If Chrome is still open then I get the error message 'error when connectingInternal Exception' at line 993 in Chrome.pm. I just realized that when using $mech->get there seem to be started two instances of Chrome at once. One with 'about:blank' and the other with the desired page. If I have Chrome already open before start of WWW::Mechanize::Firefox then those 'about:blank' pages are added to the first instance. tab=>'current' might not work because it might refer to the second instance. And at the end WWW:Mechanize:Chrome tries to close the first instance but is not successful when there are more tabs already open. Then there seems to be the error message 'Couldn't kill browser child 4360 with SIGKILL: Invalid argument' at line 1740 in Chrome.pm.
Best regards
1nelly1

Replies are listed 'Best First'.
Re: saveResources_future and tab in WWW::Mechanize::Chrome
by Corion (Patriarch) on May 13, 2020 at 09:51 UTC

    This is weird. The documentation says:

    my $file_map = $mech->saveResources_future( target_file => 'this_page.html', target_dir => 'this_page_files/', )->get();

    ... and the target_dir value is used to create the directory where to save the resources. Can you maybe show some code that demonstrates the behaviour?

    Despite my regression tests, tab => 'current' seems to be broken for many people. This is still an issue under investigation unfortunately.

      Dear Corion,
      I only tested the code from the documentation (exactly as written above). And 'this_page.html' and all files will be placed in the working directory. I can change target_file location and save somewehere else but whatever location I use for target_dir, all files are always saved in the working directory.
      I am still using WWW::Mechanize::Firefox and would like to migrate to Chrome. Just for your information, I was not able to install WWW::Mechanize::Chrome with ActiveState Perl running despite your advice to force the installation of Imager::File::PNG if screenshots are not necessary. I tried to force the installation of Imager::File::PNG as well as WWW::Mechanize::Chrome using cpanm but it did not work. Now I am using Strawberry Perl
      Best regards
      1nelly1

        Thank you for making me revisit my assumptions!

        Indeed, the parameter for specifying the download directory was never used. This will be fixed in the next release of WWW::Mechanize::Chrome, which I will likely release this evening.

      Dear Corion,
      regarding the tab problem I just want to emphasize that I have two separate Chrome windows when calling $mech->get.
      Best regards
      1nelly1