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!
- Ensure you have Node.js 24.14.0 or higher.
- Install Playwright as a peer dependency: Scriptwriter requires
playwright@^1.60.0.- For global installs:
npm i -g playwright - For local project:
npm install playwright - In a monorepo: install in the project's
node_modulesor a parent workspace
- For global installs:
- Install Scriptwriter:
npm i -g scriptwriter. - Or clone this repo, install, and use
npm linkornpm start.
Scriptwriter uses a "nearest" resolution strategy to find the installed Playwright package:
- Current working directory — Searches
node_modules/playwrightin the directory wherescriptwriteris run - Parent directories — Traverses up the directory tree looking for installed Playwright
- Installation location — Falls back to Playwright installed alongside Scriptwriter
This means you can:
- Run Scriptwriter from a project with its own Playwright installation
- Use a global Playwright with
scriptwriter -g - Use Playwright from any parent directory in a monorepo or nested project structure
scriptwriter --no-headlesswill launch the repl and Chromium.- Use
awaitright away:await page.goto('https://github.com') - The prompt will change on load:
github.com ~> .helplists the global commands.- Pressing
Tabtwice will display autocomplete help. - Save and load your repl sessions!
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-textutil.inspectdump.json: savesJSON.stringify(obj, null, ' ')for readable JSON.ansi: saves an ANSI-coloredutil.inspectdump 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.
- director = node repl instance
- scriptwriter.code = prettier.format
- scriptwriter.color = kleur
- scriptwriter.error = pretty-error
- scriptwriter.escapes = ansi-escapes
- scriptwriter.importGlobal = import-global
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.
- Open keychain access.
- In the top menu, choose
Keychain Access > Certificate Assistant > Create a Certificate. - Name it
Playwright. - Change the
Certificate TypetoCode Signing. - Click
create. - Right click your new certificate and choose
Get Info. - Open
Trustdisclosure. - Change
When using this certificate:toAlways Trust. - Start Scriptwriter.
- When Chromium starts, right click the icon in the menu bar, choose
Options > Show in Finder. - Right click Chromium and select
New Terminal Here. - In the terminal type
pwdand copy the path. - Use the following to assign the certificate:
sudo codesign -s Playwright -f <PATH_TO_CHROMIUM> --deep.