Content Validation

Validate page content before capturing. Fail the request if specific conditions aren't met.

Configuration

{
  "options": {
    "fail_on_error": true,
    "fail_if_missing": ["Login", "Dashboard"],
    "fail_if_contains": ["Access Denied", "404", "Error"]
  }
}

Parameters

Parameter Type Default Description
fail_on_error boolean false Fail on JavaScript console errors
fail_if_missing array Fail if any text is NOT found on page
fail_if_contains array Fail if any text IS found on page

Fail on Console Errors

Detect JavaScript errors on the page:

{
  "url": "https://example.com",
  "options": {
    "fail_on_error": true
  }
}

When enabled, any console.error() output or uncaught exceptions will cause the request to fail.

Error Response

{
  "error": {
    "type": "target_error",
    "code": "console_error",
    "message": "Page had console errors: Uncaught TypeError: Cannot read property 'foo' of undefined",
    "retryable": false
  }
}

Fail if Missing

Ensure required content is present:

{
  "url": "https://app.example.com/dashboard",
  "options": {
    "fail_if_missing": ["Welcome back", "Dashboard"]
  }
}

The request fails if ANY of the specified strings are not found on the page.

Use Cases

  • Verify login was successful
  • Ensure data loaded correctly
  • Check for expected content

Error Response

{
  "error": {
    "type": "target_error",
    "code": "content_check_failed",
    "message": "Required text not found: 'Dashboard'",
    "retryable": true
  }
}

Fail if Contains

Detect error states or unwanted content:

{
  "url": "https://example.com",
  "options": {
    "fail_if_contains": ["404", "Page not found", "Access Denied", "Error"]
  }
}

The request fails if ANY of the specified strings are found on the page.

Use Cases

  • Detect 404 pages
  • Catch authentication failures
  • Identify error messages
  • Prevent capturing error states

Error Response

{
  "error": {
    "type": "target_error",
    "code": "content_check_failed",
    "message": "Forbidden text found: 'Access Denied'",
    "retryable": true
  }
}

Combining Validations

Use multiple validations together:

{
  "url": "https://app.example.com/report",
  "options": {
    "fail_on_error": true,
    "fail_if_missing": ["Report Generated", "Download PDF"],
    "fail_if_contains": ["Error", "Loading...", "Please wait"]
  }
}

This ensures: 1. No JavaScript errors 2. Report is fully generated 3. No error messages or loading states

Case Sensitivity

Text matching is case-sensitive by default:

{
  "options": {
    "fail_if_missing": ["Dashboard"]
  }
}
  • ✓ Matches: "Dashboard", "My Dashboard"
  • ✗ Doesn't match: "dashboard", "DASHBOARD"

Partial Matching

Matches are partial — the text can appear anywhere:

{
  "options": {
    "fail_if_contains": ["Error"]
  }
}
  • ✓ Matches: "Error", "Error occurred", "An Error was found"
  • ✗ Doesn't match: "error", "ERROR"

Common Patterns

Authenticated Dashboard

{
  "url": "https://app.example.com/dashboard",
  "network": {
    "cookies": [{ "name": "session", "value": "xxx", "domain": "app.example.com" }]
  },
  "options": {
    "fail_if_missing": ["Welcome"],
    "fail_if_contains": ["Sign in", "Login"]
  }
}

E-commerce Product Page

{
  "url": "https://store.example.com/product/123",
  "options": {
    "fail_if_missing": ["Add to Cart", "Price"],
    "fail_if_contains": ["Out of Stock", "Product not found", "404"]
  }
}

Blog Post

{
  "url": "https://blog.example.com/post/my-article",
  "options": {
    "fail_if_contains": ["Post not found", "404", "This page doesn't exist"]
  }
}

Data Dashboard

{
  "url": "https://analytics.example.com",
  "wait": {
    "until": "networkidle"
  },
  "options": {
    "fail_on_error": true,
    "fail_if_missing": ["Chart", "Data loaded"],
    "fail_if_contains": ["Loading", "Fetching data", "Error loading"]
  }
}

Handling Validation Failures

Validation failures return target_error with content_check_failed:

{
  "error": {
    "type": "target_error",
    "code": "content_check_failed",
    "message": "Required text not found: 'Dashboard'",
    "retryable": true
  }
}

Retry Strategy

Since these errors are marked retryable: true, you can retry with: - Longer wait times - Different wait conditions - Cookie refresh for auth issues

{
  "url": "https://example.com",
  "wait": {
    "until": "networkidle",
    "delay": 2000
  },
  "options": {
    "fail_if_missing": ["Dashboard"]
  }
}

Examples

Verify Login Success

curl -X POST https://api.renderscreenshot.com/v1/screenshot \
  -H "Authorization: Bearer rs_live_xxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://app.example.com/dashboard",
    "network": {
      "cookies": [{
        "name": "session",
        "value": "user_session_token",
        "domain": "app.example.com"
      }]
    },
    "options": {
      "fail_if_missing": ["Welcome back"],
      "fail_if_contains": ["Sign in", "Invalid credentials"]
    }
  }' \
  --output dashboard.png

Capture Only Successful Pages

curl -X POST https://api.renderscreenshot.com/v1/screenshot \
  -H "Authorization: Bearer rs_live_xxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/page",
    "options": {
      "fail_on_error": true,
      "fail_if_contains": ["404", "Not Found", "Error", "500"]
    }
  }' \
  --output page.png

See Also

Was this page helpful?