NAME
Playwright - Perl client for Playwright
VERSION
version 0.004
SYNOPSIS
use JSON::PP;
use Playwright;
my $handle = Playwright->new();
my $browser = $handle->launch( headless => JSON::PP::false, type => 'chrome' );
my $page = $browser->newPage();
my $res = $page->goto('http://google.com', { waitUntil => 'networkidle' });
my $frameset = $page->mainFrame();
my $kidframes = $frameset->childFrames();
DESCRIPTION
Perl interface to a lightweight node.js webserver that proxies commands runnable by Playwright. Checks and automatically installs a copy of the node dependencies in the local folder if needed.
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).
See https://playwright.dev/#version=master&path=docs%2Fapi.md&q= for what the classes do, and their usage.
There are two major exceptions in how things work versus the documentation.
Selectors
The selector functions have to be renamed from starting with $ for obvious reasons. The renamed functions are as follows:
These functions are present as part of the Page, Frame and ElementHandle classes.
Scripts
The evaluate() and evaluateHandle() functions can only be run in string mode. To maximize the usefulness of these, I have wrapped the string passed with the following function:
const fun = new Function (toEval);
args = [
fun,
...args
];
As such you can effectively treat the script string as a function body. The same restriction on only being able to pass one arg remains from the upstream: https://playwright.dev/#version=master&path=docs%2Fapi.md&q=pageevaluatepagefunction-arg
You will have to refer to the arguments array as described here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments
Asynchronous operations
The waitFor* methods defined on various classes will return an instance of AsyncData, a part of the Async module. You will then need to wait on the result of the backgrounded action with the await() method documented below.
# Assuming $handle is a Playwright object
my $async = $page->waitForEvent('console');
$page->evaluate('console.log("whee")');
my $result = $handle->await( $async );
my $logged = $result->text();
INSTALLATION NOTE
If you install this module from CPAN, you will likely encounter a croak() telling you to install node module dependencies. Follow the instructions and things should be just fine.
CONSTRUCTOR
new(HASH) = (Playwright)
Creates a new browser and returns a handle to interact with it.
INPUT
debug (BOOL) : Print extra messages from the Playwright server process
METHODS
launch(HASH) = Playwright::Browser
The Argument hash here is essentially those you'd see from browserType.launch(). See: https://playwright.dev/#version=v1.5.1&path=docs%2Fapi.md&q=browsertypelaunchoptions
There is an additional "special" argument, that of 'type', which is used to specify what type of browser to use, e.g. 'firefox'.
await (AsyncData) = Object
Waits for an asynchronous operation returned by the waitFor* methods to complete and returns the value.
quit, DESTROY
Terminate the browser session and wait for the Playwright server to terminate.
Automatically called when the Playwright object goes out of scope.
BUGS
Please report any bugs or feature requests on the bugtracker website https://github.com/teodesian/playwright-perl/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
AUTHORS
Current Maintainers:
George S. Baugh <teodesian@gmail.com>
COPYRIGHT AND LICENSE
Copyright (c) 2020 Troglodyne LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.