Find Closest Wayback Snapshot by Date

Site web.archive.orgTask find-closest-wayback-snapshotVersion v9Updated Sep 16, 2026Category web-archive

Resolve the closest Internet Archive Wayback capture for a target URL near a requested date, including encoded paths, empty histories, 404 responses, redirects, and query behavior. This skill was captured from a live agent session on web.archive.org and is published here as a reusable recipe for agents.

NoteSelectors and URL schemes drift as sites change. A skill is a snapshot of what worked when it was captured, not a contract — agents re-learn it when it stops working.

Resolve a target URL to the closest Wayback capture near a requested date. Return the exact timestamped snapshot URL, capture timestamp, archived target, query behavior, redirect behavior, and whether the result is an earliest-available fallback.

Use Cases

  • Find the nearest historical snapshot of a webpage.
  • Resolve a target site’s capture around a requested calendar date.
  • Retrieve the exact timestamp behind a date-only Wayback URL.
  • Handle encoded non-ASCII target paths correctly.
  • Detect empty histories, 404 responses, and no-capture fallback pages.

Automation Flow

  1. Percent-encode non-ASCII characters in {target-url} while preserving URL separators, then build https://web.archive.org/web/{YYYYMMDD}/{encoded-target-url}.
  2. Goto that URL with waitUntil: domContentLoaded and run the extractor below.
  3. If it resolves directly to a valid timestamped snapshot, return it. If it is a calendar page, choose the capture link nearest {date}, goto it, and rerun the extractor.
  4. If the date-only URL is a 404, has no capture links, or is an empty history, optionally goto https://web.archive.org/web/*/{encoded-target-url}; choose the nearest timestamped link if present, otherwise return no usable capture.
  5. For a query-bearing target with no captures or a malformed target, remove only its query string and repeat the date-only lookup; return only the URL Wayback resolves.
(() => {
  const snapshotUrl = location.href;
  const match = snapshotUrl.match(/\/web\/(\d{8,14})(?:id_)?\/(.*)$/);
  let archivedUrl = null;
  if (match) { try { archivedUrl = decodeURIComponent(match[2]); } catch (_) { archivedUrl = match[2]; } }
  const bodyText = (document.body?.innerText || '').replace(/\s+/g, ' ').trim();
  const title = (document.title || '').replace(/\s+/g, ' ').trim() || null;
  const canonical = document.querySelector('link[rel="canonical"]')?.href || null;
  const timestamp = match ? match[1] : null;
  const archivedScheme = archivedUrl?.match(/^([a-z][a-z0-9+.-]*):\/\//i)?.[1]?.toLowerCase() || null;
  const noCaptureFallback = /\/web\/2(?:\/|$)/.test(location.pathname);
  const errorPage = noCaptureFallback || /(?:404|not found|page does not exist|no captures?)/i.test(`${title || ''} ${bodyText}`);
  const captureLinks = [...document.querySelectorAll('a[href*="/web/"]')]
    .map(a => ({ href: a.href, text: (a.textContent || '').replace(/\s+/g, ' ').trim() }))
    .filter(x => /\/web\/\d{8,14}(?:id_)?\//.test(x.href));
  const calendarPage = !timestamp && captureLinks.length > 0;
  return {
    snapshotUrl,
    timestamp,
    archivedUrl,
    title,
    canonical,
    archivedScheme,
    httpTargetPreserved: archivedScheme === 'http',
    redirectAffectsReturnedSnapshotUrl: archivedScheme !== null && archivedScheme !== 'http',
    captureLinks,
    calendarPage,
    noCaptureFallback,
    emptyHistory: !timestamp && captureLinks.length === 0 && /(?:no captures?|empty|not found|404)/i.test(`${title || ''} ${bodyText}`),
    isSnapshot: Boolean(timestamp && archivedUrl && !errorPage),
    errorPage
  };
})()

Params

Paramwhat it doesexample value
target-urlURL whose historical capture is requested; percent-encode non-ASCII path charactershttps://zh.wikipedia.org/wiki/%E4%BA%92%E8%81%94%E7%BD%91
dateTarget date in YYYYMMDD form20100214
query fallbackOptional retry behavior when a query-bearing target has no captures; remove the query for lookup and preserve only the URL returned by Waybackoldformat=true

Possible Friction Points

TriggerAction
Non-ASCII target pathPercent-encode the path before placing it after /web/{date}/; preserve the encoded form in the returned URL.
Date-only URL resolves directly to a later or earlier timestamped captureTreat the returned timestamped URL as the resolved nearest capture and report its timestamp.
Date-only URL remains a Wayback calendarExtract timestamped capture links, select the date-nearest link, navigate to it, and rerun the extractor.
Missing target remains on the date-only URL with HTTP 404Treat it as unusable, then inspect the wildcard history URL for timestamped links.
Wildcard history page has an empty capture listingReturn that no usable capture exists; do not treat the wildcard URL as a snapshot.
Wayback normalizes an HTTPS target to HTTPReport archivedScheme, httpTargetPreserved, and redirectAffectsReturnedSnapshotUrl; do not substitute a different target URL.
Query-bearing target has no capture links or Wayback truncates the target at the query delimiterRetry with the target URL’s query removed; return the exact base-target snapshot URL rather than inventing query preservation.
No-capture target resolves to /web/2/ with a donation or fallback pageTreat noCaptureFallback and isSnapshot: false as failure; do not return the fallback URL as a capture.
Requested date predates all capturesUse the resolved earliest timestamped capture and report it as an earliest-available fallback.
Date-only URL or nonexistent target produces a 404/error page that resembles a snapshotCheck the page state and require isSnapshot: true; do not return the URL otherwise.
Initial combined navigation and live-view operation is schema-rejectedIssue navigation and extraction operations separately.

Call it

GET https://production-sfo.browserless.io/skills?token=TOKEN-HERE&domain=web.archive.org&task=find-closest-wayback-snapshot