LibreCrawl Documentation

repository·main·Indexed 19 days ago

https://github.com/phialsbasement/librecrawl

A web-based, multi-tenant open-source crawler for SEO analysis and website auditing. It provides insights into page elements, links, and performance. The tool supports JavaScript rendering via Playwright and offers two running modes: Standard Mode with a tier-based authentication system and Local Mode for personal use. It includes a plugin system allowing developers to extend functionality using JavaScript lifecycle hooks and a dedicated API.

Tokens
17.7K
Snippets
49
Records
74
Agent score
73%

What's inside LibreCrawl

  1. Understand LibreCrawl Running Modes

    main

    LibreCrawl operates in two primary modes depending on your deployment needs:

    Standard Mode

    • Use Case: Public-facing demos or shared hosting.
    • Features: Full authentication (login/register) and a tier-based access system (Guest, User, Extra, Admin).
    • Restrictions: Guest users are limited to 3 crawls per 24 hours based on IP.

    Local Mode

    • Use Case: Personal use, single-user self-hosting, or local development.
    • Features: All users are automatically granted Admin tier access.
    • Restrictions: No rate limits or tier restrictions applied.
  2. How LibreCrawl plugins work

    main

    LibreCrawl plugins are standalone .js files dropped into the plugins folder that register themselves via the LibreCrawlPlugin API. Each plugin creates a new tab in the interface.

    Plugins operate based on Lifecycle Hooks that respond to user actions (like activating a tab) or crawl events (like data updates or crawl completion). They receive a data object containing the results of the current crawl, allowing for custom analysis, visualization, or reporting.

    LibreCrawlPlugin.register({
      id: 'my-plugin',
      name: 'My Plugin',
      tab: {
        label: 'My Tab',
        icon: '🔥',
      },
      onTabActivate(container, data) {
        container.innerHTML = `<div>${data.urls.length} URLs found</div>`;
      }
    });
  3. Install LibreCrawl via Docker (Recommended)

    main

    For controlled environments, use Docker and Docker Compose.

    1. Clone the repository.
    2. Create a .env file from the example.
    3. Run the container.

    Note on Modes:

    • Local Mode: Set LOCAL_MODE=true in .env for easy personal use (no authentication required).
    • Production Mode: Set LOCAL_MODE=false, configure HOST_BINDING=0.0.0.0, and provide a SECRET_KEY (a long random string generated via python -c "import secrets; print(secrets.token_hex(32))").
    # Clone the repository
    git clone https://github.com/PhialsBasement/LibreCrawl.git
    cd LibreCrawl
    
    # Copy environment file
    cp .env.example .env
    
    # Start LibreCrawl
    docker compose up -d
  4. Install and register a LibreCrawl plugin

    main

    To add a custom plugin to LibreCrawl, follow these steps:

    1. Create a new .js file in the web/static/plugins/ directory (e.g., my-plugin.js).
    2. Use the LibreCrawlPlugin.register() method to define your plugin's configuration and lifecycle hooks.
    3. Refresh the LibreCrawl application. Your plugin will automatically appear as a new tab in the UI.
    LibreCrawlPlugin.register({
      id: 'my-plugin',
      name: 'My Plugin',
      tab: {
        label: 'My Tab',
        icon: '🔥',
      },
      onTabActivate(container, data) {
        // Implementation
      }
    });
  5. Develop LibreCrawl Plugins

    main

    You can extend LibreCrawl by dropping .js files into /web/static/plugins/. Each file will automatically create a new tab in the UI.

    Plugins use the LibreCrawlPlugin.register() method. They receive real-time data from the crawler, including urls, links, issues, and stats.

    Lifecycle Hooks:

    • onLoad(): Called when the plugin loads.
    • onTabActivate(container, data): Called when the tab becomes active. The container is the DOM element where you render your UI.
    • onTabDeactivate(): Called when switching away from the tab.
    • onDataUpdate(data): Called during live crawls as data updates.
    • onCrawlComplete(data): Called when the crawl finishes.

    Utilities (this.utils):

    • this.utils.showNotification(message, type): Show alerts ('success', 'error', 'info').
    • this.utils.formatUrl(url)
    • this.utils.escapeHtml(text)

    Styling Tip: To ensure proper scrolling, wrap your content in a div with the .plugin-content class and a specific max-height:

    <div class="plugin-content" style="padding: 20px; overflow-y: auto; max-height: calc(100vh - 280px);">
      <!-- Content -->
    </div>
    LibreCrawlPlugin.register({
      id: 'my-plugin',
      name: 'My Plugin',
      tab: {
        label: 'My Tab',
        icon: '🔥',
      },
      onTabActivate(container, data) {
        container.innerHTML = `
          <div class="plugin-content" style="padding: 20px; overflow-y: auto; max-height: calc(100vh - 280px);">
            <h2 class="plugin-header">My Custom Analysis</h2>
            <p>Found ${data.urls.length} URLs!</p>
          </div>
        `;
      },
      onDataUpdate(data) {
        if (this.isActive) {
          // Update UI
        }
      }
    });
  6. Quick Start LibreCrawl (Automatic Installation)

    main

    The easiest way to run LibreCrawl is using the provided startup scripts. These scripts automatically handle Docker detection, dependency installation via pip, Playwright browser installation for JavaScript rendering, and starting the application in local mode.

    Windows:

    start-librecrawl.bat

    Linux/Mac:

    chmod +x start-librecrawl.sh
    ./start-librecrawl.sh

    Once finished, the application will be available at http://localhost:5000.

    # Linux/Mac
    chmod +x start-librecrawl.sh
    ./start-librecrawl.sh
  7. Style LibreCrawl plugins

    main

    To ensure your plugin matches the LibreCrawl UI and scrolls correctly, use the following guidelines:

    Required Container Styling: Always wrap your content in a container with overflow-y: auto and a calculated max-height to prevent layout breaking:

    container.innerHTML = `
      <div class="plugin-content" style="padding: 20px; overflow-y: auto; max-height: calc(100vh - 280px);">
        <!-- Your content here -->
      </div>
    `;

    Available CSS Classes:

    • .plugin-content: Main container.
    • .plugin-header: Header section.
    • .data-table: Pre-styled tables.
    • .stat-card: Statistic cards.
    • .score-good, .score-needs-improvement, .score-poor: Semantic score indicators.
    container.innerHTML = `
      <div class="plugin-content" style="padding: 20px; overflow-y: auto; max-height: calc(100vh - 280px);">
        <h2 class="plugin-header">My Header</h2>
        <div class="stat-card">Stat Value</div>
        <div class="score-good">Good Score</div>
      </div>
    `;
  8. Install LibreCrawl via Python

    main

    To run LibreCrawl directly using Python (requires Python 3.8+):

    1. Clone or download the repository.
    2. Install dependencies: pip install -r requirements.txt.
    3. (Optional) For JavaScript rendering support: playwright install chromium.
    4. Run the application:
      • Standard Mode (with authentication and tier system): python main.py
      • Local Mode (admin tier for all, no rate limits): python main.py --local or python main.py -l.

    Access the app at http://localhost:5000 (Local) or http://<your-ip>:5000 (Network).

    pip install -r requirements.txt
    playwright install chromium
    python main.py --local
  9. Export crawled data in multiple formats

    main

    LibreCrawl supports exporting crawled data (URLs, links, and issues) in CSV, JSON, and XML formats. The export logic handles complex data types (like analytics or tags) by summarizing them for CSV or preserving them for JSON/XML.

    Supported Export Types

    • URLs: Includes metadata like status codes, titles, and SEO tags.
    • Links: Includes source_url, target_url, anchor_text, is_internal, target_domain, target_status, and placement.
    • Issues: Includes url, type, category, issue, and details.

    Data Handling in CSV

    To ensure CSV compatibility, complex fields are transformed:

    • analytics: Converted to a comma-separated list of detected tools (e.g., GA4, GTM, FB).
    • og_tags/twitter_tags: Converted to a count (e.g., 15 tags).
    • h2/h3: Converted to a comma-separated string of the first 3 headings.
    • internal_links/external_links: Converted to a descriptive string (e.g., 10 internal links).
  10. Database schema and storage location

    main

    LibreCrawl uses SQLite for authentication and user data.

    • Storage Path: The database file is located at data/users.db relative to the project root. This directory is intended for Docker volume persistence.
    • Core Tables:
      • users: Stores credentials, verification status, and tier.
      • user_settings: Stores JSON-serialized user preferences.
      • crawl_history: Tracks user-initiated crawl sessions.
      • guest_crawls: Tracks IP-based crawl activity for unauthenticated users.
      • verification_tokens: Manages email verification lifecycle.
  11. Configure LibreCrawl Settings

    main

    Settings can be adjusted via the UI to customize crawling behavior:

    • Crawler settings: Depth (up to 5M URLs), delays, and external link handling.
    • Request settings: User agent, timeouts, proxy, and robots.txt compliance. Add a Google API key here to increase PageSpeed Insights rate limits.
    • JavaScript rendering: Configure the browser engine, wait times, and viewport size.
    • Filters: Define file types and URL patterns to include or exclude.
    • Export options: Choose between CSV, JSON, or XML formats.
    • Custom CSS: Apply custom themes to the UI.
    • Issue exclusion: Define patterns to ignore during SEO issue detection.
  12. Detect broken images during crawl

    main

    The crawler automatically performs HEAD requests on image URLs found on a page to detect broken links. This is done in batches (up to 50 images per page) using a thread pool to avoid blocking the main crawl loop.

    If broken images are found, they are added to the result object under the broken_images key:

    "broken_images": [
        {"url": "https://example.com/broken.png", "status": 404}
    ]