Learn what Playwright can do in each of the various browsers it supports. By default, Scriptwriter loads Chromium and creates a Chrome Devtools Protocol (CDP) client for more repl fun!
playwright@^1.60.0.
npm i -g playwrightnpm install playwrightnode_modules or a parent workspacenpm i -g scriptwriter.npm link or npm start.Scriptwriter uses a “nearest” resolution strategy to find the installed Playwright package:
node_modules/playwright in the directory where scriptwriter is runThis means you can:
scriptwriter -gscriptwriter --no-headless will launch the repl and Chromium.await right away: await page.goto('https://github.com')github.com ~>.help lists the global commands.Tab twice will display autocomplete help.Scriptwriter now supports the .dump command to serialize and save objects to disk in multiple formats.
Usage:
.dump <object> [type] [depth]
Examples:
.dump page json
.dump browser ansi 2
.dump myData txt 3
Supported output types:
txt (default): saves a plain-text util.inspect dump.json: saves JSON.stringify(obj, null, ' ') for readable JSON.ansi: saves an ANSI-colored util.inspect dump for terminal-style output.For the ansi output type, use a suitable editor viewer such as the VS Code extension ANSI Colors to get proper syntax highlighting for .ansi files.
You can use cli flags to set the config scriptwriter --help:
Usage
$ scriptwriter [--no-headless] [--device <name>] [--config <file>]
[--browser <browser>] [--no-js] [--no-csp]
Options
--no-headless, --no-h Run as headless=false
--device, -d Load a device profile from Playwright
--config, -c Pass a config file to Scriptwriter
--browser, -b Change browsers (default: chromium)
--no-js Disable JavaScript
--no-csp Bypass CSP
--aom, -a Launch with Accessibility Object Model (AOM) enabled
--user, -u Launch with a Persistent Context
Examples
$ scriptwriter
$ scriptwriter --no-headless
$ scriptwriter --device 'iPhone X'
$ scriptwriter --config ./config.js
$ scriptwriter -c ./config.json --no-h
$ scriptwriter --no-js --b firefox
You can also load a config from a file. File values are deep-merged into the runtime config so nested launch and context options work as expected.
// iphonex.json
{
"launch": {
"headless": true,
"args": ["--some-blink-specific-tag-name"]
},
"context": {},
"device": "iPhone X"
}
scriptwriter --config iphonex.json
You can load your own commands. Scriptwriter exposes some helpful utility functions.
Example:
// my-command.js
scriptwriter.completion = '.louder';
director.defineCommand('louder', {
help: `make something louder`,
async action(str) {
const { log, color } = scriptwriter;
log(color.red(`${str.toUpperCase()}!!`));
director.displayPrompt();
},
});
// in the scriptwriter repl
> .load my-command.js
> .louder test
TEST!!
On a mac, you may get the firewall popup.
Keychain Access > Certificate Assistant > Create a Certificate.Playwright.Certificate Type to Code Signing.create.Get Info.Trust disclosure.When using this certificate: to Always Trust.Options > Show in Finder.New Terminal Here.pwd and copy the path.sudo codesign -s Playwright -f <PATH_TO_CHROMIUM> --deep.