checkLink
The checkLink action checks if a URL returns an acceptable status code. It primarily issues a browser-mimicking GET request. If the response is still 429 or 403 after retries, it retries the URL once with a HEAD request as a fallback. This action is useful for verifying that a hyperlink or image URL is valid.
You can specify the target URL directly as a string, or use an object for more options:
url: (Required in object format) The URL to check. Use an absolute URL, a path that starts with one/, or a value that starts with a variable, such as$BASE_URL/docs. A path needs anorigin, in the step or in the configuration file.origin: (Optional) Protocol and domain prepended tourlwhenurlis a path. If omitted andurlis a path, the globaloriginfrom the configuration file is used.statusCodes: (Optional) A single integer or an array of integers representing acceptable HTTP status codes, including non-2xx codes like429(rate limited),403(forbidden), or500(server error). If omitted, defaults to[200, 301, 302, 307, 308].headers: (Optional) Additional HTTP headers to include in the request. Merged on top of Doc Detective’s default browser-mimicking headers. Accepts either a key/value object or a newline-separated string. Useful for sites that allowlist specific headers or bypass tokens. Defaults to{}.params: (Optional) Query parameters to append to the resolved URL. Merged with config-leveloriginParams. Values support environment variable substitution with$VARsyntax. Defaults to{}.timeout: (Optional) Time in milliseconds each request attempt may take. Each retry gets the same time. Minimum1. Defaults to10000.
Outputs: the action exposes outputs.statusCode, the HTTP status code returned by the request. To capture it for later steps, use the step-level variables object with the expression $$statusCode.
For comprehensive options, see the
checkLinkreference.
Behavior
Each checkLink step:
- Issues a
GETrequest with browser-mimicking default headers (User-Agent,Accept,Accept-Language,Accept-Encoding,Upgrade-Insecure-Requests, and theSec-Fetch-*andSec-Ch-Ua*Client Hints set) to reduce false 429 or 403 responses from bot-protection layers. If no response arrives withintimeout, the step fails right away without retrying. - Retries up to three times (four attempts total) with exponential backoff (1 second, then 2 seconds, then 4 seconds) on
429or5xxresponses. If the server sends aRetry-Afterheader, Doc Detective waits that duration (capped at 10 seconds) instead. - If the final response is still
429or403, retries the URL once with aHEADrequest. Some web application firewalls (WAFs) rate-limit HTMLGETrequests but allowHEADrequests. If theHEADreturns an accepted status code, the step passes. - Compares the final status code against
statusCodesand reports PASS or FAIL.
Examples
The docs tests run every example in the Examples section except the relative-link example, which needs a global origin in your config. Under Query parameters, they run every example except the variable example.
Check if a link is valid (string shorthand)
Check if a link is valid (object format)
Check for a specific status code response
Check for one of a set of status code responses
Accept non-2xx status codes
Include non-2xx status codes in statusCodes to accept responses that would otherwise fail, such as rate limiting (429) or authentication errors (403). Once a response matches statusCodes, Doc Detective stops and passes without retrying or falling back to HEAD. See Behavior.
Check a link with a separate origin and URL path
Set how long each attempt may take
Use timeout to fail faster on a slow host, or to give a slow host more time. The value applies to each request attempt, including retries.
If no response arrives in time, the step fails with a message like this:
Pass custom headers (allowlist or bypass)
Use the headers field to send additional HTTP headers on top of Doc Detective’s browser-mimicking defaults. This is useful for sites that allowlist a shared secret or require a bypass token.
headers also accepts a newline-separated string, which is convenient for multi-header strings loaded from environment variables:
Check a relative link using global origin
Assuming a global origin of https://www.google.com is set in the configuration:
Query parameters
You can append query parameters to a URL using the params option. This is useful for authentication tokens or tracking parameters.
- Step-level
params: An object specifying query parameters to append to the URL. Applies to all URLs, both relative and absolute. Values support environment variable substitution with$VARsyntax. - Config-level
originParams: Default query parameters in your configuration file that apply to relative URLs resolved againstorigin. Step-levelparamsmerge on top, with step keys taking precedence on collision.
When your URL contains a fragment such as /page#section, query parameters are inserted before the fragment, giving /page?token=value#section.
Doc Detective embeds params and originParams values in request URLs. A value you write directly in these fields appears in test results, logs, and reports. To keep a secret out of output, reference an environment variable, such as "token": "$API_TOKEN". The request uses the real value, and output shows ***API_TOKEN***. See Keep secrets out of logs, reports, and captures.
Check a link with query parameters
Append a testing token to the request URL with step-level params.
Check a link from a variable
The string form and the object url both accept a $VAR reference, so you can check a link whose address comes from an environment variable loaded with loadVariables.
Combine every option
A single step can set url, origin, params, statusCodes, and headers together. It resolves a path against an origin, appends query parameters, sends a custom header, and accepts a chosen set of status codes.
Troubleshooting
checkLinkfails with 429 or 403 even though the URL works in a browsercheckLinkfails due to unrecognized certificates
checkLink fails with 429 or 403 even though the URL works in a browser
Sites behind bot protection or a web application firewall (WAF) can return 403 or 429 to non-browser traffic even when the URL works in your browser. Examples include Cloudflare, Akamai, Amazon Web Services (AWS) WAF, Imperva, PerimeterX, and Vercel deployment protection. Doc Detective already sends a browser-like header set and retries transient failures. Some WAFs still fingerprint deeper signals that header spoofing can’t influence, such as Transport Layer Security (TLS) client fingerprints or source IP reputation.
If you hit this, you have three escape hatches:
-
Widen
statusCodesto accept the WAF response code, for example"statusCodes": [200, 301, 302, 307, 308, 403, 429]. This is pragmatic but loses signal, because the check only confirms that the URL exists. -
Pass allowlist or bypass headers through the
headersfield. Common options when you control the site: -
Use a browser-driven step (
goTo) instead ofcheckLinkwhen the URL truly requires JavaScript or a full browser fingerprint.
If you own the site, add a WAF rule that allowlists a custom header and shared secret, such as X-Doc-Detective-Check. Prefer that over trying to mimic a browser.
checkLink fails due to unrecognized certificates
The checkLink action might fail for a valid URL that loads without redirects. An internal or custom certificate the testing machine doesn’t recognize is a common cause.
Example
Consider the following test configuration. It checks the validity of https://self-signed.badssl.com/, a website using a self-signed certificate:
To run the test, use the following command:
NPX
Docker
This command executes the test, but it fails, returning the following response:
This occurs because the self-signed certificate isn’t recognized by the testing machine. This behavior is expected in axios, but you can bypass it in Doc Detective by setting an environment variable.
Solution
To fix this issue, follow these steps:
-
Create a
.envfile with the following content:ignore-certificate-problems.env -
Modify your test configuration to include a
loadVariablesstep (Note:setVariablesis deprecated, useloadVariables):bad-certificate.json
Expected result
After applying these changes, the test should pass: