Playwright.pm 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. package Playwright;
  2. use strict;
  3. use warnings;
  4. #ABSTRACT: Perl client for Playwright
  5. use 5.006;
  6. use v5.28.0; # Before 5.006, v5.10.0 would not be understood.
  7. use File::ShareDir();
  8. use File::Basename();
  9. use Cwd();
  10. use LWP::UserAgent();
  11. use Sub::Install();
  12. use Net::EmptyPort();
  13. use JSON::MaybeXS();
  14. use File::Which();
  15. use Capture::Tiny qw{capture_merged capture_stderr};
  16. use Carp qw{confess};
  17. use Playwright::Base();
  18. use Playwright::Util();
  19. # Stuff closet full of skeletons at BEGIN time
  20. use Playwright::ModuleList();
  21. no warnings 'experimental';
  22. use feature qw{signatures};
  23. =head1 SYNOPSIS
  24. use Playwright;
  25. my $handle = Playwright->new();
  26. my $browser = $handle->launch( headless => 0, type => 'chrome' );
  27. my $page = $browser->newPage();
  28. my $res = $page->goto('http://somewebsite.test', { waitUntil => 'networkidle' });
  29. my $frameset = $page->mainFrame();
  30. my $kidframes = $frameset->childFrames();
  31. # Grab us some elements
  32. my $body = $page->select('body');
  33. # You can also get the innerText
  34. my $text = $body->textContent();
  35. $body->click();
  36. $body->screenshot();
  37. my $kids = $body->selectMulti('*');
  38. =head1 DESCRIPTION
  39. Perl interface to a lightweight node.js webserver that proxies commands runnable by Playwright.
  40. Checks and automatically installs a copy of the node dependencies in the local folder if needed.
  41. Currently understands commands you can send to all the playwright classes defined in api.json (installed wherever your OS puts shared files for CPAN distributions).
  42. See L<https://playwright.dev/versions> and drill down into your relevant version (run `npm list playwright` )
  43. for what the classes do, and their usage.
  44. All the classes mentioned there will correspond to a subclass of the Playwright namespace. For example:
  45. # ISA Playwright
  46. my $playwright = Playwright->new();
  47. # ISA Playwright::BrowserContext
  48. my $ctx = $playwright->newContext(...);
  49. # ISA Playwright::Page
  50. my $page = $ctx->newPage(...);
  51. # ISA Playwright::ElementHandle
  52. my $element = $ctx->select('body');
  53. See example.pl for a more thoroughly fleshed-out display on how to use this module.
  54. =head2 Getting Started
  55. When using the playwright module for the first time, you may be told to install node.js libraries.
  56. It should provide you with instructions which will get you working right away.
  57. However, depending on your node installation this may not work due to dependencies for node.js not being in the expected location.
  58. To fix this, you will need to update your NODE_PATH environment variable to point to the correct location.
  59. =head2 Questions?
  60. 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.
  61. L<https://aka.ms/playwright-slack>
  62. =head2 Documentation for Playwright Subclasses
  63. The documentation and names for the subclasses of Playwright follow the spec strictly:
  64. Playwright::BrowserContext => L<https://playwright.dev/docs/api/class-browsercontext>
  65. Playwright::Page => L<https://playwright.dev/docs/api/class-page>
  66. Playwright::ElementHandle => L<https://playwright.dev/docs/api/class-elementhandle>
  67. ...And so on. These classes are automatically generated during module build based on the spec hash built by playwright.
  68. See generate_api_json.sh and generate_perl_modules.pl if you are interested in how this sausage is made.
  69. You can check what methods are installed for each subclass by doing the following:
  70. use Data::Dumper;
  71. print Dumper($instance->{spec});
  72. There are two major exceptions in how things work versus the upstream Playwright documentation, detailed below in the C<Selectors> section.
  73. =head2 Selectors
  74. The selector functions have to be renamed from starting with $ for obvious reasons.
  75. The renamed functions are as follows:
  76. =over 4
  77. =item $ => select
  78. =item $$ => selectMulti
  79. =item $eval => evaluate
  80. =item $$eval => evalMulti
  81. =back
  82. These functions are present as part of the Page, Frame and ElementHandle classes.
  83. =head2 Scripts
  84. The evaluate() and evaluateHandle() functions can only be run in string mode.
  85. To maximize the usefulness of these, I have wrapped the string passed with the following function:
  86. const fun = new Function (toEval);
  87. args = [
  88. fun,
  89. ...args
  90. ];
  91. As such you can effectively treat the script string as a function body.
  92. The same restriction on only being able to pass one arg remains from the upstream:
  93. L<https://playwright.dev/docs/api/class-page#pageevalselector-pagefunction-arg>
  94. You will have to refer to the arguments array as described here:
  95. L<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments>
  96. You can also pass Playwright::ElementHandle objects as returned by the select() and selectMulti() routines.
  97. They will be correctly translated into DOMNodes as you would get from the querySelector() javascript functions.
  98. Calling evaluate() and evaluateHandle() on Playwright::Element objects will automatically pass the DOMNode as the first argument to your script.
  99. See below for an example of doing this.
  100. =head3 example of evaluate()
  101. # Read the console
  102. $page->on('console',"return [...arguments]");
  103. my $promise = $page->waitForEvent('console');
  104. #TODO This request can race, the server framework I use to host the playwright spec is *not* FIFO (YET)
  105. sleep 1;
  106. $page->evaluate("console.log('hug')");
  107. my $console_log = $handle->await( $promise );
  108. print "Logged to console: '".$console_log->text()."'\n";
  109. # Convenient usage of evaluate on ElementHandles
  110. # We pass the element itself as the first argument to the JS arguments array for you
  111. $element->evaluate('arguments[0].style.backgroundColor = "#FF0000"; return 1;');
  112. =head2 Asynchronous operations
  113. The waitFor* methods defined on various classes fork and exec, waiting on the promise to complete.
  114. You will need to wait on the result of the backgrounded action with the await() method documented below.
  115. # Assuming $handle is a Playwright object
  116. my $async = $page->waitForEvent('console');
  117. $page->evaluate('console.log("whee")');
  118. my $result = $handle->await( $async );
  119. my $logged = $result->text();
  120. =head2 Getting Object parents
  121. Some things, like elements naturally are children of the pages in which they are found.
  122. Sometimes this can get confusing when you are using multiple pages, especially if you let the ref to the page go out of scope.
  123. Don't worry though, you can access the parent attribute on most Playwright::* objects:
  124. # Assuming $element is a Playwright::ElementHandle
  125. my $page = $element->{parent};
  126. =head2 Firefox Specific concerns
  127. By default, firefox will open PDFs in a pdf.js window.
  128. To suppress this behavior (such as in the event you are await()ing a download event), you will have to pass this option to launch():
  129. # Assuming $handle is a Playwright object
  130. my $browser = $handle->launch( type => 'firefox', firefoxUserPrefs => { 'pdfjs.disabled' => JSON::true } );
  131. =head2 Leaving browsers alive for manual debugging
  132. Passing the cleanup => 0 parameter to new() will prevent DESTROY() from cleaning up the playwright server when a playwright object goes out of scope.
  133. Be aware that this will prevent debug => 1 from printing extra messages from playwright_server itself, as we redirect the output streams in this case so as not to fill your current session with prints later.
  134. A convenience script has been provided to clean up these orphaned instances, `reap_playwright_servers` which will kill all extant `playwright_server` processes.
  135. =head2 Taking videos, Making Downloads
  136. We spawn browsers via BrowserType.launchServer() and then connect to them over websocket.
  137. This means you can't just set paths up front and have videos recorded, the Video.path() method will throw.
  138. Instead you will need to call the Video.saveAs() method after closing a page to record video:
  139. # Do stuff
  140. ...
  141. # Save video
  142. my $video = $page->video;
  143. $page->close();
  144. $video->saveAs('video/example.webm');
  145. It's a similar story with Download classes:
  146. # Do stuff
  147. ...
  148. # Wait on Download
  149. my $promise = $page->waitForEvent('download')
  150. # Do some thing triggering a download
  151. ...
  152. my $download = $handle->await( $promise );
  153. $download->saveAs('somefile.extension');
  154. Remember when doing an await() with playwright-perl you are waiting on a remote process on a server to complete, which can time out.
  155. You may wish to spawn a subprocess using a different tool to download very large files.
  156. 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).
  157. =head2 Doing arbitrary requests
  158. When you either want to test APIs (or not look like a scraper/crawler) you'll want to issue arbitrary requests, such as POST/HEAD/DELETE et cetera.
  159. Here's how you go about that:
  160. print "HEAD http://google.com : \n";
  161. my $fr = $page->request();
  162. my $resp = $fr->fetch("http://google.com", { method => "HEAD" });
  163. print Dumper($resp->headers());
  164. print "200 OK\n" if $resp->status() == 200;
  165. The request() method will give you a Playwright::APIRequestContext object, which you can then call whichever methods you like upon.
  166. When you call fetch (or get, post, etc) you will then be returned a Playwright::APIResponse object.
  167. =head3 Differences in behavior from Selenium::Remote::Driver
  168. By default selenium has its selector methods obeying a timeout and waits for an element to appear.
  169. It then explodes when and element can't be found.
  170. To replicate this mode of operation, we have provided the try_until helper:
  171. # Args are $object, $method, @args
  172. my $element = Playwright::try_until($page, 'select', $selector) or die ...;
  173. This will use the timeouts described by pusht/popt (see below).
  174. =head2 Perl equivalents for playwright-test
  175. This section is intended to be read alongside the playwright-test documentation to aid understanding of common browser testing techniques.
  176. The relevant documentation section will be linked for each section.
  177. =head3 Annotations
  178. L<https://playwright.dev/docs/test-annotations/>
  179. Both L<Test::More> and L<Test2::V0> provide an equivalent to all the annotations but slow():
  180. =over 4
  181. =item B<skip or fixme> - Test::More::skip or Test2::Tools::Basic::skip handle both needs
  182. =item B<fail> - Test::More TODO blocks and Test2::Tools::Basic::todo
  183. =item B<slow> - Has no equivalent off the shelf. Playwright::pusht() and Playwright::popt() are here to help.
  184. # Examples assume you have a $page object.
  185. # Timeouts are in milliseconds
  186. Playwright::pusht($page,5000);
  187. # Do various things...
  188. ...
  189. Playwright::popt($page);
  190. See L<https://playwright.dev/docs/api/class-browsercontext#browser-context-set-default-timeout> for more on setting default timeouts in playwright.
  191. By default we assume the timeout to be 30s.
  192. =back
  193. =head3 Assertions
  194. As with before, most of the functionality here is satisfied with perl's default testing libraries.
  195. In particular, like() and cmp_bag() will do most of what you want here.
  196. =head3 Authentication
  197. Much of the callback functionality used in these sections is provided by L<Test::Class> and it's fixtures.
  198. =head3 Command Line
  199. Both C<prove> and C<yath> have similar functionality, save for retrying flaky tests.
  200. That said, you shouldn't do that; good tests don't flake.
  201. =head3 Configuration
  202. All the configuration here can simply be passed to launch(), newPage() or other methods directly.
  203. =head3 Page Objects
  204. This is basically what L<Test::Class> was written for specifically; so that you could subclass testing of common components across pages.
  205. =head3 Parallelizing Tests
  206. Look into L<Test::Class::Moose>'s Parallel runmode, C<prove>'s -j option, or L<Test2::Aggregate>.
  207. =head3 Reporters
  208. When using C<prove>, consider L<Test::Reporter> coupled with App::Prove::Plugins using custom TAP::Formatters.
  209. Test2 as of this writing (October 2012) supports formatters and plugins, but no formatter plugins have been uploaded to CPAN.
  210. See L<Test2::Manual::Tooling::Formatter> on writing a formatter yourself, and then a L<Test2::Plugin> using it.
  211. =head3 Test Retry
  212. C<prove> supports tests in sequence via the --rules option.
  213. It's also got the handy --state options to further micromanage test execution over multiple iterations.
  214. You can use this to retry flaking tests, but it's not a great idea in practice.
  215. =head3 Visual Comparisons
  216. Use L<Image::Compare>.
  217. =head3 Advanced Configuration
  218. This yet again can be handled when instantiating the various playwright objects.
  219. =head3 Fixtures
  220. L<Test::Class> and it's many variants cover the subject well.
  221. =head1 INSTALLATION NOTE
  222. If you install this module from CPAN, you will likely encounter a croak() telling you to install node module dependencies.
  223. Follow the instructions and things should be just fine.
  224. If you aren't, please file a bug!
  225. =head1 CONSTRUCTOR
  226. =head2 new(HASH) = (Playwright)
  227. Creates a new browser and returns a handle to interact with it.
  228. =head3 INPUT
  229. debug (BOOL) : Print extra messages from the Playwright server process. Default: false
  230. timeout (INTEGER) : Seconds to wait for the playwright server to spin up and down. Default: 30s
  231. cleanup (BOOL) : Whether or not to clean up the playwright server when this object goes out of scope. Default: true
  232. =cut
  233. our ( $spec, $server_bin, $node_bin, %mapper );
  234. sub _check_node {
  235. # Check that node is installed
  236. $node_bin = File::Which::which('node');
  237. confess("node must exist, be in your PATH and executable") unless $node_bin && -x $node_bin;
  238. my $path2here = File::Basename::dirname( Cwd::abs_path( $INC{'Playwright.pm'} ) );
  239. # Make sure it's possible to start the server
  240. $server_bin = File::Which::which('playwright_server');
  241. confess("Can't locate playwright_server!
  242. Please ensure it is installed in your PATH.
  243. If you installed this module from CPAN, it should already be.")
  244. unless $server_bin && -x $server_bin;
  245. # Attempt to start the server. If we can't do this, we almost certainly have dependency issues.
  246. my ($output) = capture_merged { system($node_bin, $server_bin, '--check') };
  247. return if $output =~ m/OK/;
  248. warn $output if $output;
  249. confess( "playwright_server could not run successfully.
  250. See the above error message for why.
  251. It's likely to be unmet dependencies, or a NODE_PATH issue.
  252. Install of node dependencies must be done manually.
  253. Run the following:
  254. npm i express playwright uuid
  255. sudo npx playwright install-deps
  256. export NODE_PATH=\"\$(pwd)/node_modules\".
  257. If you still experience issues, run the following:
  258. NODE_DEBUG=module playwright_server --check
  259. This should tell you why node can't find the deps you have installed.
  260. ");
  261. }
  262. sub _build_classes {
  263. foreach my $class ( keys(%$spec) ) {
  264. $mapper{$class} = sub {
  265. my ( $self, $res ) = @_;
  266. my $class = "Playwright::$class";
  267. return $class->new(
  268. handle => $self,
  269. id => $res->{_guid},
  270. type => $class,
  271. parent => $self,
  272. );
  273. };
  274. }
  275. }
  276. sub BEGIN {
  277. our $SKIP_BEGIN;
  278. _check_node() unless $SKIP_BEGIN;
  279. }
  280. sub new ( $class, %options ) {
  281. #XXX yes, this is a race, so we need retries in _start_server
  282. my $port = Net::EmptyPort::empty_port();
  283. my $timeout = $options{timeout} // 30;
  284. my $self = bless(
  285. {
  286. ua => $options{ua} // LWP::UserAgent->new(),
  287. port => $port,
  288. debug => $options{debug},
  289. cleanup => $options{cleanup} // 1,
  290. pid => _start_server( $port, $timeout, $options{debug}, $options{cleanup} // 1 ),
  291. parent => $$,
  292. timeout => $timeout,
  293. },
  294. $class
  295. );
  296. $self->_check_and_build_spec();
  297. _build_classes();
  298. return $self;
  299. }
  300. sub _check_and_build_spec ($self) {
  301. return $spec if ref $spec eq 'HASH';
  302. $spec = Playwright::Util::request(
  303. 'GET', 'spec', $self->{port}, $self->{ua},
  304. );
  305. confess("Could not retrieve Playwright specification. Check that your playwright installation is correct and complete.") unless ref $spec eq 'HASH';
  306. return $spec;
  307. }
  308. =head1 METHODS
  309. =head2 launch(HASH) = Playwright::Browser
  310. The Argument hash here is essentially those you'd see from browserType.launch(). See:
  311. L<https://playwright.dev/docs/api/class-browsertype#browsertypelaunchoptions>
  312. There is an additional "special" argument, that of 'type', which is used to specify what type of browser to use, e.g. 'firefox'.
  313. =cut
  314. sub launch ( $self, %args ) {
  315. Playwright::Base::_coerce(
  316. $spec->{BrowserType}{members},
  317. args => [ \%args ],
  318. command => 'launch'
  319. );
  320. delete $args{command};
  321. my $msg = Playwright::Util::request(
  322. 'POST', 'session', $self->{port}, $self->{ua},
  323. type => delete $args{type},
  324. args => [ \%args ]
  325. );
  326. return $Playwright::mapper{ $msg->{_type} }->( $self, $msg )
  327. if ( ref $msg eq 'HASH' )
  328. && $msg->{_type}
  329. && exists $Playwright::mapper{ $msg->{_type} };
  330. return $msg;
  331. }
  332. =head2 server (HASH) = MIXED
  333. Call Playwright::BrowserServer methods on the server which launched your browser object.
  334. Parameters:
  335. browser : The Browser object you wish to call a server method upon.
  336. command : The BrowserServer method you wish to call
  337. The most common use for this is to get the PID of the underlying browser process:
  338. my $browser = $playwright->launch( browser => chrome );
  339. my $process = $playwright->server( browser => $browser, command => 'process' );
  340. print "Browser process PID: $process->{pid}\n";
  341. BrowserServer methods (at the time of writing) take no arguments, so they are not processed.
  342. =cut
  343. sub server ( $self, %args ) {
  344. return Playwright::Util::request(
  345. 'POST', 'server', $self->{port}, $self->{ua},
  346. object => $args{browser}{guid},
  347. command => $args{command},
  348. );
  349. }
  350. =head2 await (HASH) = Object
  351. Waits for an asynchronous operation returned by the waitFor* methods to complete and returns the value.
  352. =cut
  353. sub await ( $self, $promise ) {
  354. my $obj = Playwright::Util::await($promise);
  355. return $obj unless $obj->{_type};
  356. my $class = "Playwright::$obj->{_type}";
  357. return $class->new(
  358. type => $obj->{_type},
  359. id => $obj->{_guid},
  360. handle => $self
  361. );
  362. }
  363. =head2 pusht(Playwright::Page, INTEGER timeout, BOOL navigation) = null
  364. Like pushd/popd, but for default timeouts used by a Playwright::Page object and it's children.
  365. If the 'navigation' option is high, we set the NavigationTimeout rather than the DefaultTimeout.
  366. By default 'navigation' is false.
  367. If we popt to the bottom of the stack, we will set the timeout back to 1 second.
  368. =cut
  369. sub pusht($object,$timeout, $navigation=0) {
  370. $object->{timeouts} //= [];
  371. push(@{$object->{timeouts}}, $timeout);
  372. return $object->setDefaultNavigationTimeout($timeout) if $navigation;
  373. return $object->setDefaultTimeout($timeout);
  374. }
  375. =head2 popt(Playwright::Page, BOOL navigation) = null
  376. The counterpart to pusht() which returns the timeout value to it's previous value.
  377. =cut
  378. sub popt ($object, $navigation=0) {
  379. $object->{timeouts} //= [];
  380. my $last_timeout = pop(@{$object->{timeouts}}) // 1000;
  381. return $object->setDefaultNavigationTimeout($last_timeout) if $navigation;
  382. return $object->setDefaultTimeout($last_timeout);
  383. }
  384. =head2 try_until(Object, STRING method, LIST args), try_until_die(...)
  385. Try to execute the provided method upon the provided Playwright::* object until it returns something truthy.
  386. Quits after the timeout (or 1s, if pusht is not used before this) defined on the object is reached.
  387. Use this for methods which *don't* support a timeout option, such as select().
  388. =cut
  389. sub try_until ($object, $method, @args) {
  390. my ($ctr, $result, $timeout) = (0);
  391. $timeout = $object->{timeouts}[-1] if ref $object->{timeouts} eq 'ARRAY';
  392. $timeout = $timeout / 1000 if $timeout;
  393. $timeout //= 1;
  394. while (!$result) {
  395. $result = $object->$method(@args);
  396. last if $result;
  397. sleep 1;
  398. $ctr++;
  399. last if $ctr >= $timeout;
  400. };
  401. return $result;
  402. }
  403. =head2 quit, DESTROY
  404. Terminate the browser session and wait for the Playwright server to terminate.
  405. Automatically called when the Playwright object goes out of scope.
  406. =cut
  407. sub quit ($self) {
  408. # Prevent double destroy after quit()
  409. return if $self->{killed};
  410. # Prevent destructor from firing in child processes so we can do things like async()
  411. # This should also prevent the waitpid below from deadlocking due to two processes waiting on the same pid.
  412. return unless $$ == $self->{parent};
  413. # Prevent destructor from firing in the event the caller instructs it to not fire
  414. return unless $self->{cleanup};
  415. # Make sure we don't mash the exit code of things like prove
  416. local $?;
  417. $self->{killed} = 1;
  418. print "Attempting to terminate server process...\n" if $self->{debug};
  419. Playwright::Util::request( 'GET', 'shutdown', $self->{port}, $self->{ua} );
  420. # 0 is always WCONTINUED, 1 is always WNOHANG, and POSIX is an expensive import
  421. # When 0 is returned, the process is still active, so it needs more persuasion
  422. foreach (0..3) {
  423. return unless waitpid( $self->{pid}, 1) == 0;
  424. sleep 1;
  425. }
  426. # Advanced persuasion
  427. print "Forcibly terminating server process...\n" if $self->{debug};
  428. kill('TERM', $self->{pid});
  429. #XXX unfortunately I can't just do a SIGALRM, because blocking system calls can't be intercepted on win32
  430. foreach (0..$self->{timeout}) {
  431. return unless waitpid( $self->{pid}, 1 ) == 0;
  432. sleep 1;
  433. }
  434. warn "Could not shut down playwright server!";
  435. return;
  436. }
  437. sub DESTROY ($self) {
  438. $self->quit();
  439. }
  440. sub _start_server ( $port, $timeout, $debug, $cleanup ) {
  441. $debug = $debug ? '--debug' : '';
  442. $ENV{DEBUG} = 'pw:api' if $debug;
  443. my $pid = fork // confess("Could not fork");
  444. if ($pid) {
  445. print "Waiting for port to come up...\n" if $debug;
  446. Net::EmptyPort::wait_port( $port, $timeout )
  447. or confess("Server never came up after 30s!");
  448. print "done\n" if $debug;
  449. return $pid;
  450. }
  451. # Orphan the process in the event that cleanup => 0
  452. if (!$cleanup) {
  453. print "Detaching child process...\n";
  454. chdir '/';
  455. require POSIX;
  456. die "Cannot detach playwright_server process for persistence" if POSIX::setsid() < 0;
  457. require Capture::Tiny;
  458. capture_merged { exec( $node_bin, $server_bin, "--port", $port, $debug ) };
  459. die("Could not exec!");
  460. }
  461. exec( $node_bin, $server_bin, "--port", $port, $debug );
  462. }
  463. 1;