diff --git a/src/commands/scrape.ts b/src/commands/scrape.ts index 95ec98f411..a106053b10 100644 --- a/src/commands/scrape.ts +++ b/src/commands/scrape.ts @@ -11,6 +11,7 @@ import type { } from '../types/scrape'; import { getClient } from '../utils/client'; import { handleScrapeOutput } from '../utils/output'; +import { getOrigin } from '../utils/url'; import { executeMap } from './map'; import { getStatus } from './status'; @@ -400,10 +401,12 @@ export async function handleAllScrapeCommand( const fs = await import('fs'); const path = await import('path'); - process.stderr.write(`Mapping ${siteUrl}...\n`); + // Map from origin so non-root URLs (e.g. pasted subpage) work reliably + const mapUrl = getOrigin(siteUrl); + process.stderr.write(`Mapping ${mapUrl}...\n`); const mapResult = await executeMap({ - urlOrJobId: siteUrl, + urlOrJobId: mapUrl, apiKey: options.apiKey, apiUrl: options.apiUrl, search, @@ -423,7 +426,7 @@ export async function handleAllScrapeCommand( process.exit(1); } - process.stderr.write(`Found ${totalFound} pages on ${siteUrl}\n`); + process.stderr.write(`Found ${totalFound} pages on ${mapUrl}\n`); // Detect if user passed any explicit flags (non-interactive mode) const hasExplicitFlags = diff --git a/src/utils/url.ts b/src/utils/url.ts index 4623c36e0e..63e90fa213 100644 --- a/src/utils/url.ts +++ b/src/utils/url.ts @@ -37,3 +37,16 @@ export function normalizeUrl(url: string): string { } return `https://${url}`; } + +/** + * Get the origin (scheme + host) from a URL. + * Use for map operations when a non-root URL is passed - mapping works best from the site root. + */ +export function getOrigin(url: string): string { + try { + const parsed = new URL(normalizeUrl(url)); + return `${parsed.protocol}//${parsed.host}`; + } catch { + return url; + } +}