Ver código fonte

Add a brief note on proper usage of download classes

George S. Baugh 4 anos atrás
pai
commit
b3a567a69f
3 arquivos alterados com 21 adições e 2 exclusões
  1. 3 0
      conf/Changes
  2. 1 1
      dist.ini
  3. 17 1
      lib/Playwright.pm

+ 3 - 0
conf/Changes

@@ -1,5 +1,8 @@
 Revision history for Playwright
 
+0.015 2021-09-13 TEODESIAN
+    - Add a note on proper usage of Download classes to the POD.
+
 0.014 2021-09-09 TEODESIAN
     - Add cleanup option to Playwright::new, and bin/reap_playwright_servers to assist in cleanup when doing manual investigations.
     - Fix issue with reference to eval() rather than evaluate()

+ 1 - 1
dist.ini

@@ -1,5 +1,5 @@
 name = Playwright
-version = 0.014
+version = 0.015
 author = George S. Baugh <george@troglodyne.net>
 license = MIT
 copyright_holder = Troglodyne LLC

+ 17 - 1
lib/Playwright.pm

@@ -200,7 +200,7 @@ Be aware that this will prevent debug => 1 from printing extra messages from pla
 
 A convenience script has been provided to clean up these orphaned instances, `reap_playwright_servers` which will kill all extant `playwright_server` processes.
 
-=head2 Taking videos
+=head2 Taking videos, Making Downloads
 
 We spawn browsers via BrowserType.launchServer() and then connect to them over websocket.
 This means you can't just set paths up front and have videos recorded, the Video.path() method will throw.
@@ -213,6 +213,22 @@ Instead you will need to call the Video.saveAs() method after closing a page to
     $page->close();
     $video->saveAs('video/example.webm');
 
+It's a similar story with Download classes:
+
+    # Do stuff
+    ...
+    # Wait on Download
+    my $promise = $page->waitForEvent('download')
+    # Do some thing triggering a download
+    ...
+
+    my $download = $handle->await( $promise );
+    $download->saveAs('somefile.extension');
+
+Remember when doing an await() with playwright-perl you are waiting on a remote process on a server to complete, which can time out.
+You may wish to spawn a subprocess using a different tool to download very large files.
+If this is not an option, consider increasing the timeout on the LWP object used by the Playwright object (it's the 'ua' member of the class).
+
 =head1 INSTALLATION NOTE
 
 If you install this module from CPAN, you will likely encounter a croak() telling you to install node module dependencies.