Wayback Restorator

Plugins

Configure output transformations or write your own plugin.

Plugins transform restored files after built-in HTML and CSS rewriting and before the ZIP is packaged; some also transform files as they download. Built-in plugins run on every restore unless disabled, with defaults chosen for the smoothest result; flatten_frames, stylesheet_fallback and optimize_images are off by default.

Configure plugins

Each plugin has a table in the config file, named after it. Every plugin takes enabled, true or false, besides its own options:

[plugins.flatten_frames]
enabled = true

[plugins.strip_external_urls]
extensions = [".html", ".htm", ".php"]

Each option also has an environment variable and a CLI flag: PLUGIN_<PLUGIN>_<OPTION> and --plugin-<plugin>-<option>. Lists are comma-separated there:

PLUGIN_STRIP_EXTERNAL_URLS_EXTENSIONS=.html,.htm,.php \
  wayback-restorator restore 'https://web.archive.org/web/20260925084419/https://example.com/' \
  --plugin-flatten-frames-enabled --no-plugin-sitemap-enabled

In the dashboard, plugins are under Advanced settings.

Built-in plugins

Clean external references

strip_external_urls cleans references to other sites in restored HTML. It changes external links and form actions to #, removes external stylesheet, script, iframe, and frame elements, and neutralizes external media references. Same-site links are preserved.

OptionDefaultPurpose
extensions[".html", ".htm"]Additional filename matching. Files with an HTML content type are also processed.

For example, include restored .php pages:

{ "strip_external_urls": { "extensions": [".html", ".htm", ".php"] } }

Flatten framesets

flatten_frames turns frameset pages into ordinary pages. Each window a frameset reaches through its links is written over the document it shows, so existing URLs keep working: frames become CSS grid cells sized like the frameset, each holding that document's body, and links that reloaded a frame point to the page of the document they load. Nested framesets are flattened into nested grids. Sites without framesets are left untouched. It is disabled by default; enable it with enabled = true under [plugins.flatten_frames], PLUGIN_FLATTEN_FRAMES_ENABLED=true, or --plugin-flatten-frames-enabled.

OptionDefaultPurpose
extensions[".html", ".htm"]File types read as documents.

A document reached in more than one window keeps the first one. Frames whose document was not restored stay empty; the frames_missing counter reports them.

Change a path prefix

path_prefix renames an output path prefix and rewrites matching root-relative references in selected file types.

OptionDefaultPurpose
from/wp-adminSource path prefix.
to/wp-extendReplacement path prefix.
extensions[".html", ".js"]File types whose references are rewritten.

Both prefixes start with / and name a path within the restored website.

{
  "path_prefix": {
    "from": "/old-docs",
    "to": "/docs",
    "extensions": [".html", ".js", ".css"]
  }
}

This maps old-docs/index.html to docs/index.html and changes matching /old-docs/ references to /docs/ in HTML, JavaScript, and CSS files.

Generate a sitemap

sitemap writes sitemap.xml listing every restored page. Each entry's <lastmod> is the UTC time of the capture the page was restored from, so it reflects when that version of the page existed, not when it was first published. The plugin also writes a Sitemap: line to robots.txt, creating the file when it was not restored and replacing archived Sitemap: lines, which name sitemaps that are not part of the restored site.

OptionDefaultPurpose
base_urlEntry page's originSite address used for every <loc>, e.g. https://example.com/. Set it when the site is served from a different scheme, host, or path than the archived one.
extensions[".html", ".htm"]File types listed as pages.
[plugins.sitemap]
base_url = "https://example.com/"

Directory pages are listed by their clean URL: about/index.html becomes https://example.com/about/. One sitemap holds at most 50,000 URLs; the urls_omitted counter reports pages beyond that limit.

Substitute missing stylesheets

stylesheet_fallback keeps pages styled when the stylesheet they link to was never archived. Cache plugins such as LiteSpeed Cache, Autoptimize, and WP Rocket combine a theme's CSS into one file named by a hash that changes on every cache purge, so pages captured at different times link to different files and the archive often holds only some of them. Without this plugin, a page whose stylesheet is missing loses its styling.

The plugin links such a page to a restored stylesheet from the same host and directory whose file name matches once hashes (8 or more hex characters) are masked and the query is ignored. When several match, the one captured closest to the page is used. It is disabled by default; enable it with enabled = true under [plugins.stylesheet_fallback], PLUGIN_STYLESHEET_FALLBACK_ENABLED=true, or --plugin-stylesheet-fallback-enabled.

OptionDefaultPurpose
extensions[".html", ".htm"]Pages whose missing stylesheets are substituted.

The substitute is another version of the same bundle, so styles the site added or changed between the two captures can differ. The stylesheets_substituted and stylesheets_unmatched counters report linked stylesheets that were replaced and those without a restored version.

Optimize images

optimize_images shrinks restored sites with many large photos. It re-encodes JPEG, PNG, GIF, and BMP images as WebP as they download, and can downscale them, so the originals are kept neither in the working files nor in the ZIP. Transparency and GIF animation are kept, and EXIF orientation is applied to the pixels. It is disabled by default; enable it with enabled = true under [plugins.optimize_images], PLUGIN_OPTIMIZE_IMAGES_ENABLED=true, or --plugin-optimize-images-enabled.

OptionDefaultPurpose
quality85WebP quality, 1 to 100.
max_dimension0Longest side in pixels; larger images are scaled down. 0 keeps the size. Animated images keep their size.
extensions[".jpg", ".jpeg", ".png", ".gif", ".bmp"]Image types converted.
[plugins.optimize_images]
enabled = true
quality = 80
max_dimension = 1920

A converted image keeps its name with .webp appended, photo.jpg becomes photo.jpg.webp, and links in restored HTML and CSS point to the new name. Image paths built by scripts are not rewritten and stop loading. An image that cannot be decoded keeps its original bytes under the new name, which browsers still display. Images downloaded before the plugin was enabled, or with other options, are not converted again when a job resumes.

Plugin order

Enabled plugins run in registration order: flatten_frames, then path_prefix, then sitemap, then stylesheet_fallback, then strip_external_urls, then optimize_images. Check the plugins array in the result report for each plugin's counters.

Write a plugin

Plugins are part of the source code. Set up a development checkout first, then add src/wayback_restorator/plugins/replace_text.py. This example replaces a phrase in HTML output:

from dataclasses import dataclass

from .support.base import FileContext, Plugin, PluginConfig, check_options


DEFAULT_OPTIONS = {"old": "Old name", "new": "New name"}


@dataclass(frozen=True)
class ReplaceTextConfig(PluginConfig):
    old: str
    new: str


def parse(plugin_id: str, options: dict[str, object]) -> ReplaceTextConfig:
    check_options(options, set(DEFAULT_OPTIONS), f"plugin {plugin_id} options")
    settings = {**DEFAULT_OPTIONS, **options}
    if not all(isinstance(value, str) for value in settings.values()):
        raise ValueError(f"plugin {plugin_id} old and new must be strings")
    if not settings["old"]:
        raise ValueError(f"plugin {plugin_id} old must not be empty")
    return ReplaceTextConfig(plugin_id, settings["old"], settings["new"])


class ReplaceTextPlugin(Plugin):
    name = "replace_text"
    default_options = DEFAULT_OPTIONS

    def __init__(self, config: ReplaceTextConfig) -> None:
        super().__init__(config.id, (".html", ".htm"))
        self.old = config.old.encode("utf-8")
        self.new = config.new.encode("utf-8")

    def transform_file(self, context: FileContext, content: bytes) -> bytes:
        return content.replace(self.old, self.new)

Register it

In src/wayback_restorator/plugins/registry.py, add the import:

from .replace_text import ReplaceTextConfig, ReplaceTextPlugin, parse as parse_replace_text

Add an entry to the existing REGISTRY dictionary:

"replace_text": (ReplaceTextConfig, parse_replace_text, ReplaceTextPlugin),

Run it

From the development checkout:

wayback-restorator restore 'https://web.archive.org/web/20260925084419/https://example.com/' \
  --plugin-replace-text-old 'Old name' --plugin-replace-text-new 'New name'

Choose a distinct --job-id when comparing separate outputs.

Plugin hooks

HookPurpose
matches(context)Select files by extension, content type, or other context.
map_path(local_path)Rename output files with unique relative paths.
substitute(context, original_url)Return the local path of a restored file to link in place of a stylesheet, icon, or preload the page references but that was not restored.
transform_download(context, content)Transform a selected file's bytes as it downloads, before it is saved. Runs on worker threads, so keep it thread-safe.
transform_file(context, content)Transform a selected file's bytes.
site_start(context)Prepare per-site state before files are written.
site_finish(context)Finish per-site work after files are written.
report()Return the plugin's identity and counters.

FileContext provides original_url, local_path, content_type, allowed_hosts, and capture_timestamp. SiteContext provides the output directory, allowed hosts, entry_url, and files, the FileContext of every restored file.

default_options makes the options settings: a [plugins.replace_text] table, PLUGIN_REPLACE_TEXT_OLD, and --plugin-replace-text-old, typed like their defaults. A plugin runs unless disabled; set enabled_by_default = False on the class to make it opt-in.

Add a focused test in tests/test_plugins.py for your transformation and run the tests.

On this page