← Back to Analysis

External Links Agent

external-links.check.js

What This Agent Does

The External Links Agent discovers and validates all external links on a page, checking for broken links, redirects, and safety scores of linked destinations.

Category Information

Property Value
Category Name External Links
Category Icon
Source Files src/checks/external-links.check.js
src/checks/link-analysis.check.js

Checks Performed

Link Discovery

Finds all <a href> links pointing to external domains.

Link Reachability

Verifies each external link returns a valid HTTP response.

Broken Links

Identifies links that return 404 or other error status codes.

Redirect Chains

Detects links that redirect and where they lead.

Safety Scoring

Optionally scores each external link for safety threats.

noopener/noreferrer

Checks if external links have proper security attributes.

Data Sources

Libraries Used

  • axios — HTTP client for fetching page and checking links
  • cheerio — HTML parsing to extract links

Link Discovery

const cheerio = require('cheerio');
const $ = cheerio.load(response.data);
const baseHostname = new URL(url).hostname;

// Find all external links
const externalLinks = [];
$('a[href]').each((i, el) => {
  const href = $(el).attr('href');
  try {
    const linkUrl = new URL(href, url);
    if (linkUrl.hostname !== baseHostname) {
      externalLinks.push({
        url: linkUrl.href,
        text: $(el).text().trim(),
        rel: $(el).attr('rel')
      });
    }
  } catch (e) {
    // Invalid URL, skip
  }
});

Link Validation

// Check each external link
for (const link of externalLinks) {
  try {
    const response = await axios.head(link.url, { 
      timeout: 5000,
      maxRedirects: 5
    });
    link.status = response.status;
    link.reachable = true;
  } catch (error) {
    link.status = error.response?.status || 'unreachable';
    link.reachable = false;
  }
}

Link Status Categories

Status Icon Meaning
Safe Link is reachable and passes safety checks
Warning Link works but has potential concerns
Unsafe Link points to a potentially dangerous site
Broken Link returns 404 or other error
Unreachable Link destination could not be contacted

Return Value

{
  category: 'External Links',
  icon: 'link',
  score: 0-100,
  checks: [
    {
      name: 'External Links Found',
      status: 'info',
      description: '15 external links discovered',
      severity: 'low'
    },
    {
      name: 'Broken Links',
      status: 'pass' | 'warn' | 'fail',
      description: '0 broken links found',
      severity: 'medium'
    }
  ],
  scoredLinks: [
    {
      url: 'https://example.com',
      status: 'Safe',
      score: 85
    },
    // ... more links
  ]
}