matthewwong525/WongStack / .agents/plugins/browser
browser
VerifiedThe person's own browser, for errands.
| File | Kind | Size |
|---|---|---|
| README.md | markdown | 4.4 KB |
| SKILL.md | skill md | 3.6 KB |
| VERSION | other | 6 B |
| addon/background.js | script | 1.1 KB |
| addon/check.svg | other | 591 B |
| addon/manifest.json | config | 462 B |
| references/browser-proxy.md | markdown | 5.2 KB |
| references/browser-window.md | markdown | 6.4 KB |
| references/browsing.md | markdown | 18.6 KB |
| references/login-codes.md | markdown | 5.6 KB |
| references/password-manager.md | markdown | 8.3 KB |
| references/setup.md | markdown | 6.4 KB |
| scripts/addons.mjs | script | 26.3 KB |
| scripts/browse.mjs | script | 53.5 KB |
| scripts/browser-server.mjs | script | 50.8 KB |
| scripts/connect-browser.mjs | script | 17.3 KB |
| scripts/forwarder.mjs | script | 14.5 KB |
| scripts/launch-config.py | script | 7.4 KB |
| scripts/lib/cli.mjs | script | 1.2 KB |
| scripts/lib/env.mjs | script | 614 B |
| scripts/lib/primary-root.mjsexecutable | script | 1.9 KB |
| scripts/lib/profile.mjs | script | 1.4 KB |
| scripts/login-move.mjs | script | 4.0 KB |
| scripts/mask-keys.mjs | script | 2.9 KB |
| scripts/proxy-lines.mjs | script | 4.7 KB |
| scripts/refs.mjs | script | 5.4 KB |
scripts/proxy-lines.mjs
View on GitHub// The saved first and upstream proxy lines: from the repo's keys, else this computer's saved files. Only the
// forwarder holds them; the browser sees just the local forwarder.
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
import { homedir } from 'node:os';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { primaryRoot } from './lib/primary-root.mjs';
import { parseEnv } from './lib/env.mjs';
/** The repo key of the upstream proxy line, `[http://]login:password@host:port` (../references/browser-proxy.md). */
export const PROXY_KEY = 'BROWSE_UPSTREAM_PROXY';
/** The line saved for the whole computer: the browser is shared, so a start from any repo uses it. */
export const UPSTREAM_FILE = join(homedir(), '.wong-stack', 'camoufox', 'upstream-proxy');
/** The old camofox browser's file, read when the new one is missing. */
export const OLD_UPSTREAM_FILE = join(homedir(), '.wong-stack', 'camofox', 'upstream-proxy');
/** The repo key for the proxy tried before the upstream, `[http://][login:password@]host:port`: a home proxy, such as a
* Raspberry Pi (../references/browser-proxy.md). The upstream is its backup. */
export const FIRST_KEY = 'BROWSE_FIRST_PROXY';
/** The first proxy line saved for the whole computer, by the same rules as the upstream file. */
export const FIRST_FILE = join(homedir(), '.wong-stack', 'camoufox', 'first-proxy');
/** The old camofox browser's first proxy file, read when the new one is missing. */
export const OLD_FIRST_FILE = join(homedir(), '.wong-stack', 'camofox', 'first-proxy');
/** The forwarder's route from a proxy line, or null when blank or not that shape. The last `@` splits the login, so a
* password may hold `@` or `:`; with `loginOptional`, a line with no `@` gives an address with no login. */
export function parseUpstream(line, { loginOptional = false } = {}) {
const text = line?.trim().replace(/^http:\/\//i, '').replace(/\/$/, '');
if (!text || /^[a-z][\w+.-]*:\/\//i.test(text)) return null;
const at = text.lastIndexOf('@');
if (at < 0 && !loginOptional) return null;
const address = /^(\[[0-9a-f:]+\]|[^\s:/@[\]]+):(\d+)$/i.exec(text.slice(at + 1));
const port = Number(address?.[2]);
if (!address || port < 1 || port > 65535) return null;
const host = address[1].replace(/^\[|\]$/g, '');
if (at < 0) return { host, port };
const login = text.slice(0, at);
const colon = login.indexOf(':');
if (colon < 1 || colon === login.length - 1 || /\s/.test(login)) return null;
return { host, port, username: login.slice(0, colon), password: login.slice(colon + 1) };
}
/** The first proxy from its line: the upstream's shape, with the login optional. */
export const parseFirst = line => parseUpstream(line, { loginOptional: true });
/** The key from the environment, else the primary worktree's `.env`; blank when neither holds it. */
export function repoLine(env = process.env, envFile = primaryEnvFile(), key = PROXY_KEY) {
if (env[key]?.trim()) return env[key].trim();
try {
if (envFile && existsSync(envFile)) return parseEnv(readFileSync(envFile, 'utf8'))[key]?.trim() ?? '';
} catch { /* none */ }
return '';
}
const readLine = file => { try { return readFileSync(file, 'utf8').trim(); } catch { return ''; } };
/** Saves a line only this user can read; the temporary file makes it whole or absent. */
function saveLine(file, line) {
mkdirSync(dirname(file), { recursive: true, mode: 0o700 });
const temp = `${file}.${process.pid}.tmp`;
writeFileSync(temp, `${line}\n`, { mode: 0o600 });
renameSync(temp, file);
}
/** The upstream for this start. A valid repo line wins and is saved for the computer when it differs, so a rotated
* key spreads; with none, the computer file decides, or the old camofox file while the new one is missing. */
export function resolveUpstream({ env = process.env, envFile = primaryEnvFile(), file = UPSTREAM_FILE, oldFile = OLD_UPSTREAM_FILE, key = PROXY_KEY, parse = parseUpstream } = {}) {
const line = repoLine(env, envFile, key) || (!existsSync(file) && readLine(oldFile));
if (!line) return parse(readLine(file));
const upstream = parse(line);
if (upstream && readLine(file) !== line) {
try { saveLine(file, line); } catch { /* this start still uses it */ }
}
return upstream;
}
/** The first proxy for this start, by the upstream's rules, from `BROWSE_FIRST_PROXY` and its computer file, or the old
* camofox file while the new one is missing. */
export function resolveFirst(options = {}) {
return resolveUpstream({ file: FIRST_FILE, oldFile: OLD_FIRST_FILE, ...options, key: FIRST_KEY, parse: parseFirst });
}
function primaryEnvFile() {
try { return join(primaryRoot(fileURLToPath(new URL('.', import.meta.url))).primary, '.env'); } catch { return null; }
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |