Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
89fab0b
Add JS Asset Auditor engineering spec
jevansnyc Apr 1, 2026
d8a0d84
Address PR feedback on JS Asset Auditor spec
ChristianPavilonis Apr 10, 2026
ee6ec58
Add JS Asset Auditor command and slug generation utility
ChristianPavilonis Apr 10, 2026
cc23410
Add processing script and expand heuristic filters for JS Asset Auditor
ChristianPavilonis Apr 10, 2026
36c75d4
Add Playwright CLI for deterministic JS asset auditing
ChristianPavilonis Apr 13, 2026
7a69522
Update JS Asset Auditor spec to reflect Playwright CLI architecture
ChristianPavilonis Apr 13, 2026
f50a198
Move JS Asset Auditor into Claude Code plugin structure
ChristianPavilonis Apr 13, 2026
36535a5
Add plugin marketplace index for js-asset-auditor
ChristianPavilonis Apr 13, 2026
bbf3b1b
Make publisher domain optional in JS Asset Auditor CLI
ChristianPavilonis Apr 13, 2026
3473fa7
Update JS Asset Auditor spec for plugin structure and optional domain
ChristianPavilonis Apr 13, 2026
ba1a8c2
Add integration detection and config generation to JS Asset Auditor
ChristianPavilonis Apr 13, 2026
e0c7e0c
Default to headed browser to avoid bot detection
ChristianPavilonis Apr 13, 2026
66951b9
Fix JS asset auditor review feedback
ChristianPavilonis Apr 21, 2026
00ce787
Fix JS Asset Auditor review blockers
ChristianPavilonis Apr 24, 2026
5b3481a
audit detects more prebid script patterns, and detects bidders
ChristianPavilonis Apr 27, 2026
4773d13
Address JS asset auditor review feedback
ChristianPavilonis May 5, 2026
dd859bf
Update docs for JS Asset Auditor
ChristianPavilonis May 5, 2026
c8cf17f
Address JS asset auditor review feedback
ChristianPavilonis May 6, 2026
8e84249
Merge branch 'main' into feature/js-asset-auditor
aram356 May 10, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"plugins": [
{
"name": "js-asset-auditor",
"description": "Audit publisher pages for third-party JS assets and generate js-assets.toml entries using Playwright",
"path": "packages/js-asset-auditor"
}
]
}
6 changes: 5 additions & 1 deletion .claude/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@
"Bash(git diff:*)",
"Bash(git log:*)",
"Bash(git status:*)",
"Bash(node scripts/js-asset-slug.mjs:*)",
"mcp__plugin_chrome-devtools-mcp_chrome-devtools__new_page",
"mcp__plugin_chrome-devtools-mcp_chrome-devtools__performance_stop_trace",
"mcp__plugin_chrome-devtools-mcp_chrome-devtools__navigate_page",
"mcp__plugin_chrome-devtools-mcp_chrome-devtools__list_network_requests",
"mcp__plugin_chrome-devtools-mcp_chrome-devtools__evaluate_script",
"mcp__plugin_chrome-devtools-mcp_chrome-devtools__close_page",
"mcp__plugin_chrome-devtools-mcp_chrome-devtools__performance_stop_trace"
]
},
"enabledPlugins": {
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ src/*.html
/guest-profiles
/benchmark-results/**

# JS Asset Auditor plugin
/packages/js-asset-auditor/node_modules/

# Playwright browser tests
/crates/integration-tests/browser/node_modules/
/crates/integration-tests/browser/test-results/
Expand Down
366 changes: 366 additions & 0 deletions docs/superpowers/specs/2026-04-01-js-asset-auditor-design.md

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions packages/js-asset-auditor/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "js-asset-auditor",
"version": "1.0.0",
"description": "Audit publisher pages for third-party JS assets and generate js-assets.toml entries using Playwright",
"author": {
"name": "StackPop"
},
"license": "MIT",
"keywords": ["js-assets", "audit", "playwright", "ad-tech", "proxy"]
}
11 changes: 11 additions & 0 deletions packages/js-asset-auditor/bin/audit-js-assets
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env node

// Plugin bin/ wrapper — resolves lib/audit.mjs relative to plugin root,
// not the user's working directory.

import { fileURLToPath } from "node:url";
import { dirname, resolve } from "node:path";

const pluginRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
const { main } = await import(resolve(pluginRoot, "lib/audit.mjs"));
main();
279 changes: 279 additions & 0 deletions packages/js-asset-auditor/lib/audit.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
#!/usr/bin/env node

// JS Asset Auditor CLI
//
// Standalone Playwright-based tool that sweeps a publisher page for third-party
// JS assets and generates js-assets.toml entries.
//
// Usage:
// node packages/js-asset-auditor/lib/audit.mjs https://www.publisher.com [options]
// audit-js-assets https://www.publisher.com [options] (when plugin bin/ is in PATH)
//
// Options:
// --diff Compare against existing js-assets.toml
// --settle <ms> Settle window after page load (default: 6000)
// --first-party <h> Additional first-party hosts (comma-separated)
// --no-filter Bypass heuristic filtering
// --headed Run browser visibly for debugging
// --output <path> Output file path (default: js-assets.toml)
Comment thread
ChristianPavilonis marked this conversation as resolved.
//
// Prerequisites:
// cd packages/js-asset-auditor && npm install && npx playwright install chromium

import { readFileSync, writeFileSync } from "node:fs";
import { resolve } from "node:path";
import { processAssets } from "./process.mjs";

// ---------------------------------------------------------------------------
// Config reading
// ---------------------------------------------------------------------------

function readPublisherDomain(repoRoot) {
const content = readFileSync(
Comment thread
ChristianPavilonis marked this conversation as resolved.
Outdated
resolve(repoRoot, "trusted-server.toml"),
"utf-8",
);
const lines = content.split("\n");
let inPublisher = false;
for (const line of lines) {
if (/^\[publisher\]/.test(line)) {
inPublisher = true;
continue;
}
if (/^\[/.test(line)) {
inPublisher = false;
continue;
}
if (inPublisher) {
const m = line.match(/^domain\s*=\s*"([^"]+)"/);
if (m) return m[1];
}
}
throw new Error(
"Could not find [publisher].domain in trusted-server.toml",
);
}

// ---------------------------------------------------------------------------
// CLI argument parsing
// ---------------------------------------------------------------------------

function parseArgs(argv) {
const args = {
url: null,
domain: null,
diff: false,
settle: 6000,
firstParty: [],
noFilter: false,
headless: false,
output: "js-assets.toml",
config: null,
force: false,
};

for (let i = 2; i < argv.length; i++) {
const arg = argv[i];
if (arg === "--domain") {
args.domain = argv[++i];
} else if (arg === "--diff") {
args.diff = true;
} else if (arg === "--settle") {
args.settle = parseInt(argv[++i], 10);
} else if (arg === "--first-party") {
args.firstParty = argv[++i].split(",").filter(Boolean);
Comment thread
ChristianPavilonis marked this conversation as resolved.
Outdated
} else if (arg === "--no-filter") {
args.noFilter = true;
} else if (arg === "--headless") {
args.headless = true;
} else if (arg === "--output") {
args.output = argv[++i];
} else if (arg === "--config") {
// --config with optional path: default to "trusted-server.toml"
const next = argv[i + 1];
if (next && !next.startsWith("--")) {
args.config = argv[++i];
} else {
args.config = "trusted-server.toml";
Comment thread
ChristianPavilonis marked this conversation as resolved.
Outdated
}
} else if (arg === "--force") {
args.force = true;
} else if (!arg.startsWith("--") && !args.url) {
args.url = arg.startsWith("http") ? arg : `https://${arg}`;
} else {
console.error(`Unknown argument: ${arg}`);
process.exit(1);
}
}

if (!args.url) {
console.error(
"Usage: audit-js-assets <url> [--diff] [--settle <ms>] [--first-party <hosts>] [--no-filter] [--headless] [--output <path>] [--config [path]] [--force]",
);
process.exit(1);
}

return args;
}

// ---------------------------------------------------------------------------
// Main
// ---------------------------------------------------------------------------

export async function main() {
const args = parseArgs(process.argv);
const repoRoot = process.cwd();

// Resolve publisher domain: --domain flag > trusted-server.toml > infer from URL
let domain = args.domain;
if (!domain) {
try {
domain = readPublisherDomain(repoRoot);
} catch {
// No config file — infer from target URL
try {
const host = new URL(args.url).hostname;
domain = host.startsWith("www.") ? host.slice(4) : host;
} catch {
domain = args.url;
}
console.error(`No trusted-server.toml found, using domain: ${domain}`);
}
}
Comment thread
ChristianPavilonis marked this conversation as resolved.
Outdated

let chromium;
try {
({ chromium } = await import("playwright"));
} catch {
console.error(
"Playwright not installed. Run:\n cd packages/js-asset-auditor && npm install",
);
process.exit(1);
}

console.error(`Launching browser...`);
let browser;
try {
browser = await chromium.launch({ headless: args.headless });
} catch (err) {
if (err.message.includes("Executable doesn't exist")) {
console.error(
"Chromium not installed. Run:\n cd packages/js-asset-auditor && npx playwright install chromium",
);
process.exit(1);
}
throw err;
}

try {
const context = await browser.newContext();
const page = await context.newPage();

const scriptUrls = [];
page.on("response", (response) => {
const req = response.request();
if (req.resourceType() === "script") {
scriptUrls.push(req.url());
}
});

console.error(`Navigating to ${args.url}...`);
await page.goto(args.url, { waitUntil: "load", timeout: 30000 });

console.error(`Waiting ${args.settle}ms for page to settle...`);
await page.waitForTimeout(args.settle);

const headScriptUrls = await page.evaluate(() =>
Array.from(
document.head.querySelectorAll("script[src]"),
).map((s) => s.src),
);

console.error(
`Found ${scriptUrls.length} network scripts, ${headScriptUrls.length} head scripts`,
);

await browser.close();

console.error("Processing assets...");
const result = processAssets(
{ networkUrls: scriptUrls, headUrls: headScriptUrls },
{
domain,
target: args.url,
output: args.output,
diff: args.diff,
firstParty: args.firstParty,
noFilter: args.noFilter,
},
);

if (result.error) {
console.error(result.error);
process.exit(1);
}

writeFileSync(args.output, result.toml);
const count =
result.summary.mode === "init"
? result.summary.surfaced
: result.summary.new.length;
console.error(`Wrote ${args.output} (${count} entries)`);

// Integration detection & config generation
if (args.config) {
const { detectIntegrations, generateConfig } = await import(
"./detect.mjs"
);
const detection = detectIntegrations(scriptUrls);

if (detection.integrations.length > 0) {
// Check if config file already exists
let fileExists = false;
try {
readFileSync(args.config);
fileExists = true;
} catch {
// File doesn't exist — safe to write
}
Comment thread
ChristianPavilonis marked this conversation as resolved.
Outdated

if (fileExists && !args.force) {
Comment thread
ChristianPavilonis marked this conversation as resolved.
Outdated
console.error(
`${args.config} already exists. Use --force to overwrite.`,
);
Comment thread
ChristianPavilonis marked this conversation as resolved.
Outdated
} else {
const configToml = generateConfig(domain, args.url, detection);
writeFileSync(args.config, configToml);
console.error(
`Wrote ${args.config} (${detection.integrations.length} integrations detected)`,
);
}
} else {
console.error("No integrations detected — skipping config generation");
}

result.summary.integrations = detection.integrations.map((i) => ({
id: i.id,
label: i.label,
category: i.category,
extracted: i.extracted,
todos: i.todos,
}));
}

console.log(JSON.stringify(result.summary));
} finally {
if (browser.isConnected()) {
await browser.close();
}
}
}

// Run when invoked directly
const isDirectExecution =
process.argv[1] &&
new URL(process.argv[1], "file://").href === import.meta.url;

if (isDirectExecution) {
main();
}
Loading
Loading