Skip to content

redirect-behavior check flags window.location in code examples as JS redirects #4

@fviolette

Description

@fviolette

Pages that contain window.location in code snippets are incorrectly classified as js-redirect.

See the following examples:

https://docs.contentsquare.com/en/web/artificial-pageviews/
https://docs.contentsquare.com/en/web/sending-pageviews/
https://docs.contentsquare.com/en/csq-sdk-android/experience-analytics/troubleshooting/

Should afdocs strip <code> and <pre> block contents before applying JS_REDIRECT_PATTERNS to the response body?

const JS_REDIRECT_PATTERNS =
/window\.location\s*[=.]|document\.location\s*[=.]|location\.href\s*=|location\.replace\s*\(|<meta[^>]+http-equiv\s*=\s*["']?refresh["']?/i;


Test run for reproduction

pnpm exec afdocs check https://docs.contentsquare.com/en/csq-sdk-android/experience-analytics/troubleshooting/ \
    --sampling none \
    --checks redirect-behavior \
    --format json

Output

{
  "url": "https://docs.contentsquare.com/en/csq-sdk-android/experience-analytics/troubleshooting/",
  "timestamp": "2026-03-17T20:29:46.930Z",
  "specUrl": "https://agentdocsspec.com/spec/",
  "results": [
    {
      "id": "redirect-behavior",
      "category": "url-stability",
      "status": "fail",
      "message": "1 JavaScript redirect(s) detected across 1 pages",
      "details": {
        "totalPages": 1,
        "testedPages": 1,
        "sampled": false,
        "noRedirectCount": 0,
        "sameHostCount": 0,
        "crossHostCount": 0,
        "jsRedirectCount": 1,
        "fetchErrors": 0,
        "pageResults": [
          {
            "url": "https://docs.contentsquare.com/en/csq-sdk-android/experience-analytics/troubleshooting",
            "status": 200,
            "classification": "js-redirect"
          }
        ],
        "discoveryWarnings": []
      }
    }
  ],
  "summary": {
    "total": 1,
    "pass": 0,
    "warn": 0,
    "fail": 1,
    "skip": 0,
    "error": 0
  }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions