-
Notifications
You must be signed in to change notification settings - Fork 8
Add JS Asset Auditor plugin with Playwright CLI #633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ChristianPavilonis
wants to merge
13
commits into
main
Choose a base branch
from
feature/js-asset-auditor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
89fab0b
Add JS Asset Auditor engineering spec
jevansnyc d8a0d84
Address PR feedback on JS Asset Auditor spec
ChristianPavilonis ee6ec58
Add JS Asset Auditor command and slug generation utility
ChristianPavilonis cc23410
Add processing script and expand heuristic filters for JS Asset Auditor
ChristianPavilonis 36c75d4
Add Playwright CLI for deterministic JS asset auditing
ChristianPavilonis 7a69522
Update JS Asset Auditor spec to reflect Playwright CLI architecture
ChristianPavilonis f50a198
Move JS Asset Auditor into Claude Code plugin structure
ChristianPavilonis 36535a5
Add plugin marketplace index for js-asset-auditor
ChristianPavilonis bbf3b1b
Make publisher domain optional in JS Asset Auditor CLI
ChristianPavilonis 3473fa7
Update JS Asset Auditor spec for plugin structure and optional domain
ChristianPavilonis ba1a8c2
Add integration detection and config generation to JS Asset Auditor
ChristianPavilonis e0c7e0c
Default to headed browser to avoid bot detection
ChristianPavilonis 66951b9
Fix JS asset auditor review feedback
ChristianPavilonis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
366 changes: 366 additions & 0 deletions
366
docs/superpowers/specs/2026-04-01-js-asset-auditor-design.md
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,304 @@ | ||
| #!/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 | ||
| // --domain <domain> Override publisher domain used for slug generation | ||
| // --settle <ms> Settle window after page load (default: 6000) | ||
| // --first-party <h> Additional first-party hosts (comma-separated) | ||
| // --no-filter Bypass heuristic filtering | ||
| // --headless Run browser headlessly | ||
| // --output <path> Output file path (default: js-assets.toml) | ||
| // --config [path] Generate trusted-server.toml (default path: trusted-server.toml) | ||
| // --force Overwrite config file when used with --config | ||
| // | ||
| // Prerequisites: | ||
| // cd packages/js-asset-auditor && npm install && npx playwright install chromium | ||
|
|
||
| import { existsSync, readFileSync, writeFileSync } from "node:fs"; | ||
| import { resolve } from "node:path"; | ||
| import { processAssets } from "./process.mjs"; | ||
|
|
||
| const USAGE = | ||
| "Usage: audit-js-assets <url> [--diff] [--domain <domain>] [--settle <ms>] [--first-party <hosts>] [--no-filter] [--headless] [--output <path>] [--config [path]] [--force]"; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Config reading | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| export function readPublisherDomain(repoRoot, configPath = "trusted-server.toml") { | ||
| const resolvedPath = resolve(repoRoot, configPath); | ||
| const content = readFileSync(resolvedPath, "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 match = line.match(/^domain\s*=\s*"([^"]+)"/); | ||
| if (match) return match[1]; | ||
| } | ||
| } | ||
|
|
||
| throw new Error( | ||
| `Could not find [publisher].domain in ${configPath}`, | ||
| ); | ||
| } | ||
|
|
||
| function inferDomainFromTarget(target) { | ||
| try { | ||
| const host = new URL(target).hostname; | ||
| return host.startsWith("www.") ? host.slice(4) : host; | ||
| } catch { | ||
| return target; | ||
| } | ||
| } | ||
|
|
||
| function exitWithUsage(message) { | ||
| console.error(message); | ||
| console.error(USAGE); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| function requireFlagValue(argv, index, flag) { | ||
| const value = argv[index + 1]; | ||
| if (!value || value.startsWith("--")) { | ||
| exitWithUsage(`${flag} requires a value`); | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // CLI argument parsing | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| export 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 = requireFlagValue(argv, i, "--domain"); | ||
| i += 1; | ||
| } else if (arg === "--diff") { | ||
| args.diff = true; | ||
| } else if (arg === "--settle") { | ||
| const settleValue = requireFlagValue(argv, i, "--settle"); | ||
| const parsedSettle = Number.parseInt(settleValue, 10); | ||
| if (!Number.isFinite(parsedSettle) || parsedSettle < 0) { | ||
| exitWithUsage("--settle requires a non-negative integer value"); | ||
| } | ||
| args.settle = parsedSettle; | ||
| i += 1; | ||
| } else if (arg === "--first-party") { | ||
| const firstPartyValue = requireFlagValue(argv, i, "--first-party"); | ||
| args.firstParty = firstPartyValue.split(",").filter(Boolean); | ||
| i += 1; | ||
| } else if (arg === "--no-filter") { | ||
| args.noFilter = true; | ||
| } else if (arg === "--headless") { | ||
| args.headless = true; | ||
| } else if (arg === "--output") { | ||
| args.output = requireFlagValue(argv, i, "--output"); | ||
| i += 1; | ||
| } else if (arg === "--config") { | ||
| const next = argv[i + 1]; | ||
| if (next && !next.startsWith("--")) { | ||
| args.config = next; | ||
| i += 1; | ||
| } else { | ||
| args.config = "trusted-server.toml"; | ||
| } | ||
| } else if (arg === "--force") { | ||
| args.force = true; | ||
| } else if (!arg.startsWith("--") && !args.url) { | ||
| args.url = arg.startsWith("http") ? arg : `https://${arg}`; | ||
| } else { | ||
| exitWithUsage(`Unknown argument: ${arg}`); | ||
| } | ||
| } | ||
|
|
||
| if (!args.url) { | ||
| exitWithUsage("Missing required <url> argument"); | ||
| } | ||
|
|
||
| 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 (error) { | ||
| if (error?.code === "ENOENT") { | ||
| domain = inferDomainFromTarget(args.url); | ||
| console.error( | ||
| `No trusted-server.toml found, inferring publisher domain from target URL: ${domain}`, | ||
| ); | ||
| } else { | ||
| console.error( | ||
| `Failed to read publisher domain from trusted-server.toml: ${error.message}`, | ||
| ); | ||
| process.exit(1); | ||
| } | ||
| } | ||
| } | ||
|
ChristianPavilonis marked this conversation as resolved.
|
||
|
|
||
| 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 (error) { | ||
| if (error.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 error; | ||
| } | ||
|
|
||
| try { | ||
| const context = await browser.newContext(); | ||
| const page = await context.newPage(); | ||
|
|
||
| const scriptUrls = []; | ||
| page.on("response", (response) => { | ||
| const request = response.request(); | ||
| if (request.resourceType() === "script") { | ||
| scriptUrls.push(request.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( | ||
| (script) => script.src, | ||
| ), | ||
| ); | ||
|
|
||
| console.error( | ||
| `Found ${scriptUrls.length} network scripts, ${headScriptUrls.length} head scripts`, | ||
| ); | ||
|
|
||
| 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)`); | ||
|
|
||
| if (args.config) { | ||
| const { detectIntegrations, generateConfig } = await import("./detect.mjs"); | ||
| const detection = detectIntegrations(scriptUrls); | ||
|
|
||
| if (detection.integrations.length > 0) { | ||
| const fileExists = existsSync(args.config); | ||
|
|
||
| if (fileExists && !args.force) { | ||
| console.error( | ||
| `${args.config} already exists. Use --force to overwrite.`, | ||
| ); | ||
| } 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((integration) => ({ | ||
| id: integration.id, | ||
| label: integration.label, | ||
| category: integration.category, | ||
| extracted: integration.extracted, | ||
| todos: integration.todos, | ||
| })); | ||
| } | ||
|
|
||
| console.log(JSON.stringify(result.summary)); | ||
| } finally { | ||
| if (browser?.isConnected()) { | ||
| await browser.close(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const isDirectExecution = | ||
| process.argv[1] && | ||
| new URL(process.argv[1], "file://").href === import.meta.url; | ||
|
|
||
| if (isDirectExecution) { | ||
| main(); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.