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
Agent runtime
No
Yes
Manual
.jsh scripts
Agent runtime
No
Yes
Shell command
playwright-cli eval
Browser page
Yes
No
Manual
.bsh scripts
Browser page
Yes
No
URL navigation

NODE

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

Not Available

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:

Not Available

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

Not Available

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:

Capabilities

Not Available

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

Access the DOM or page cookies
playwright-cli eval
Call an API with page's auth session
playwright-cli eval
Run shell commands from JS
.jsh script or node -e
Read/write files on the VFS
.jsh script or node -e
Create a reusable named command
.jsh script
Auto-trigger on page navigation
.bsh script
One-off data processing
node -e "..."
Scrape a page into a file
playwright-cli eval + pipe to file
Modify a page's appearance on load
.bsh script

EXAMPLES

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 };
  }));
"

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.