javascript
NAME
javascript — JavaScript execution environments in SLICC
DESCRIPTION
SLICC provides three distinct JavaScript execution environments, each with different capabilities, globals, and intended use cases. Choosing the right one depends on whether you need DOM access, shell integration, filesystem operations, or automatic triggering on navigation.
node -e.jsh scriptsplaywright-cli eval.bsh scriptsNODE
Run JavaScript in the agent's runtime using node -e "<code>" or by writing a script file and executing it with node script.js.
Capabilities
fetch()— make HTTP requests (browser global)fs— VFS bridge for reading/writing filesprocess.argv— access command-line arguments- Top-level
async/await - Full computation (JSON parsing, string manipulation, math, etc.)
Not Available
document,window, DOM APIs- Page cookies or localStorage
require()orimport— no module system
Use For
Data processing, API calls, file manipulation, computation, one-off transformations.
Usage
node -e "const r = await fetch('https://api.example.com/data'); console.log(await r.json())"
JSH SCRIPTS
.jsh files are JavaScript shell scripts that are auto-discovered as commands anywhere on the VFS. Place a file named greet.jsh on the filesystem and it becomes the shell command greet.
Capabilities
Same runtime as node, plus additional globals:
exec(command)— run shell commands, returns{ stdout, stderr, exitCode }process.argv,process.env,process.exit()fs.readFile(),fs.writeFile(),fs.readDir(),fs.exists(),fs.stat(),fs.mkdir(),fs.rm(),fs.fetchToFile()console.log()writes to stdout;console.error()writes to stderr- Top-level
await(script body is wrapped in an async function)
Not Available
- DOM,
window,document require()orimport- npm packages or
node_modules
Use For
Reusable tools, skill scripts, API clients, multi-step automations that combine shell commands with JavaScript logic.
Discovery
Scripts in /workspace/skills/ are scanned first (skill-shipped scripts take priority). The first .jsh found for a given basename wins. Use which <command> to locate a discovered script.
Critical Rule
Never use .then() — the async wrapper exits before promise chains resolve. Always use await.
See man jsh for full details on globals, discovery, and skill integration.
PAGE CONTEXT (playwright-cli eval)
Execute JavaScript inside the actual web page using playwright-cli eval "<expression>" or playwright-cli eval-file <path>. The code runs via CDP Runtime.evaluate in the target tab's page context.
Capabilities
document,window— full DOM access- Page's cookies and localStorage/sessionStorage
- Same-origin
fetch()with the page's credentials - All Web APIs available to the page (MutationObserver, IntersectionObserver, etc.)
Not Available
- VFS access (
fs) exec()or shell commandsprocessglobal
Use For
Scraping page content, interacting with web applications, calling cookie-authenticated APIs, reading/writing localStorage, extracting structured data from the DOM.
Requires
--tab=<id> to target a specific tab (use playwright-cli tab-list to find tab IDs).
Usage
playwright-cli eval "document.title"
playwright-cli eval "JSON.stringify(Object.fromEntries(document.cookie.split('; ').map(c => c.split('='))))"
playwright-cli eval-file /workspace/scrape-prices.js --tab=ABC123
BSH SCRIPTS
.bsh files are browser-navigation scripts that auto-execute when the browser navigates to a matching URL. They run in the target browser page context (like playwright-cli eval) but are triggered automatically rather than manually.
URL Matching
The filename determines which hostnames trigger the script:
- Wildcard:
-.example.com.bsh— leading dash becomes*., matching any subdomain - Exact:
login.example.com.bsh— matches only that hostname - @match directives: optional lines in the first 10 lines further restrict by full URL pattern
Capabilities
- Full DOM access (
document,window) - Page cookies, localStorage, sessionStorage
- All Web APIs
Not Available
process,fs,exec()— no agent runtime globals
Use For
Auto-injecting observers on page load, modifying pages automatically, auto-login flows, form pre-filling, data extraction triggered by navigation.
Discovery
The BshWatchdog scans /workspace/ and /shared/ recursively every 10 seconds. Scripts execute once per navigation match; only top-level navigations trigger (iframes are ignored).
See man bsh for full details on matching rules and execution behavior.
CHOOSING THE RIGHT ENVIRONMENT
playwright-cli evalplaywright-cli eval.jsh script or node -e.jsh script or node -e.jsh script.bsh scriptnode -e "..."playwright-cli eval + pipe to file.bsh scriptEXAMPLES
Node: Fetch and process JSON
node -e "
const resp = await fetch('https://api.github.com/repos/anthropics/claude-code');
const data = await resp.json();
console.log(data.full_name + ': ' + data.stargazers_count + ' stars');
"
JSH: A reusable API client
File: /workspace/skills/my-skill/weather.jsh → command: weather
// weather.jsh — fetch current weather for a city
const city = process.argv[2];
if (!city) {
console.error('usage: weather <city>');
process.exit(1);
}
const resp = await fetch(`https://wttr.in/${encodeURIComponent(city)}?format=j1`);
const data = await resp.json();
const current = data.current_condition[0];
console.log(`${city}: ${current.temp_F}°F, ${current.weatherDesc[0].value}`);
Page Context: Extract table data
playwright-cli eval "
const rows = [...document.querySelectorAll('table tbody tr')];
JSON.stringify(rows.map(r => {
const cells = [...r.querySelectorAll('td')];
return { name: cells[0]?.textContent, value: cells[1]?.textContent };
}));
"
BSH: Auto-dismiss cookie banners
File: /workspace/-.example.com.bsh
// @match *://*.example.com/*
//
// Dismiss the cookie consent banner automatically
setTimeout(() => {
const btn = document.querySelector('[data-testid="cookie-accept"], .cookie-banner button');
if (btn) btn.click();
}, 1000);
SEE ALSO
man jsh — .jsh script authoring, globals, and discovery rules.
man bsh — .bsh browser scripts, URL matching, and auto-execution.
man playwright-cli — full browser automation CLI including eval, screenshots, and interaction.
man commands — complete list of available shell commands.