Browse Source

Fix #49, prep for release

George Baugh 1 năm trước cách đây
mục cha
commit
7626f61ebb
5 tập tin đã thay đổi với 24 bổ sung12 xóa
  1. 1 1
      README.md
  2. 4 0
      conf/Changes
  3. 1 1
      dist.ini
  4. 17 9
      lib/Playwright.pm
  5. 1 1
      package.json

+ 1 - 1
README.md

@@ -13,7 +13,7 @@ A little node webserver written in [express][xp] is spun up which exposes the en
 We ensure the node deps are installed in a BEGIN block, and then spin up the proxy server.
 You then use playwright more or less as normal; see the POD in Playwright.pm for more details.
 
-See example.pl for usage examples.
+See [example.pl](https://github.com/teodesian/playwright-perl/blob/main/example.pl) in the toplevel of this project on gitHub for usage examples.
 
 [pw]:https://github.com/microsoft/playwright
 [srd]:https://metacpan.org/pod/Selenium::Remote::Driver

+ 4 - 0
conf/Changes

@@ -1,5 +1,9 @@
 Revision history for Playwright
 
+1.250 2022-08-14 TEODESIAN
+    - Update for playwright v1.25
+    - Added ability to pass --port to spawn OR use existing pw server on provided port.
+
 1.210 2022-05-11 TEODESIAN
     - Update for playwright v1.21
     - Changed versioning to match the version of playwright it's tested against

+ 1 - 1
dist.ini

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

+ 17 - 9
lib/Playwright.pm

@@ -91,11 +91,6 @@ From there it's recommended you use the latest version of node:
     nvm install node
     nvm use node
 
-=head2 Questions?
-
-Feel free to join the Playwright slack server, as there is a dedicated #playwright-perl channel which I, the module author, await your requests in.
-L<https://aka.ms/playwright-slack>
-
 =head2 Documentation for Playwright Subclasses
 
 The documentation and names for the subclasses of Playwright follow the spec strictly:
@@ -212,6 +207,12 @@ 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 Running multiple clients against the same playwright server
+
+To save on memory, this is a good idea.  Pass the 'port' argument to the constructor, and we'll re-use anything listening on that port locally, and be sure to use it when starting up.
+
+This will also set the cleanup flag to false, so be sure you run `reap_playwright_servers` when you are sure that all testing on this server is done.
+
 =head2 Taking videos, Making Downloads
 
 We spawn browsers via BrowserType.launchServer() and then connect to them over websocket.
@@ -436,14 +437,14 @@ sub BEGIN {
 sub new ( $class, %options ) {
 
     #XXX yes, this is a race, so we need retries in _start_server
-    my $port = Net::EmptyPort::empty_port();
+    my $port = $options{port} // Net::EmptyPort::empty_port();
     my $timeout = $options{timeout} // 30;
     my $self = bless(
         {
             ua      => $options{ua} // LWP::UserAgent->new(),
             port    => $port,
             debug   => $options{debug},
-            cleanup => $options{cleanup} // 1,
+            cleanup => ( $options{cleanup} || !$options{port} ) // 1,
             pid     => _start_server( $port, $timeout, $options{debug}, $options{cleanup} // 1 ),
             parent  => $$,
             timeout => $timeout,
@@ -615,7 +616,7 @@ sub quit ($self) {
 
     # Prevent destructor from firing in child processes so we can do things like async()
     # This should also prevent the waitpid below from deadlocking due to two processes waiting on the same pid.
-    return unless $$ == $self->{parent};
+    return unless $$ == $self->{parent} // 'bogus';
 
     # Prevent destructor from firing in the event the caller instructs it to not fire
     return unless $self->{cleanup};
@@ -625,6 +626,7 @@ sub quit ($self) {
 
     $self->{killed} = 1;
     print "Attempting to terminate server process...\n" if $self->{debug};
+
     Playwright::Util::request( 'GET', 'shutdown', $self->{port}, $self->{ua} );
 
     # 0 is always WCONTINUED, 1 is always WNOHANG, and POSIX is an expensive import
@@ -654,10 +656,16 @@ sub DESTROY ($self) {
 sub _start_server ( $port, $timeout, $debug, $cleanup ) {
     $debug = $debug ? '--debug' : '';
 
+    # Check if the port is already live, and short-circuit if this is the case.
+    if ( Net::EmptyPort::wait_port( $port, 1 ) ) {
+        print "Re-using playwright server on port $port...\n" if $debug;
+        return;
+    }
+
     $ENV{DEBUG} = 'pw:api' if $debug;
     my $pid = fork // confess("Could not fork");
     if ($pid) {
-        print "Waiting for port to come up...\n" if $debug;
+        print "Waiting for playwright server on port $port to come up...\n" if $debug;
         Net::EmptyPort::wait_port( $port, $timeout )
           or confess("Server never came up after 30s!");
         print "done\n" if $debug;

+ 1 - 1
package.json

@@ -6,7 +6,7 @@
   "private": true,
   "dependencies": {
     "express": "^4.17",
-    "playwright": "^1.21.1",
+    "playwright": "^1.25.0",
     "uuid": "^8.3"
   }
 }