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. Can be a full URL or a path. If a path is provided, anoriginmust be specified either 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{}.
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. - 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
Here are a few ways you might use the checkLink action:
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. This is useful for testing endpoints that return rate limiting (429), authentication errors (403), or other expected non-success responses.
Doc Detective’s retry-with-backoff and HEAD-fallback logic, described above in Behavior, only runs while the response code isn’t yet accepted. As soon as a response matches statusCodes, Doc Detective stops immediately and passes. That includes a match on the very first GET, as in the example below. It doesn’t retry or fall back to HEAD merely because the code happens to be 429 or 403.
Check a link with a separate origin and URL path
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.
Values in params and originParams are embedded directly in request URLs and appear in test results, logs, and reports. Avoid storing long-lived secrets in these fields.
Check a link with query parameters
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: