Embedding challenges in pages
Dynamic challenges can be embedded within a page of your web application or served on an interstitial page. Using the embedded presentation method helps ensure the branding and user experience of your web application remains consistent. We recommend choosing this presentation method if you have a React or single-page application.
HINT: Want to add an interactive or non-interactive challenge? Use the interstitial page presentation method.
Prerequisites
Before you add a client challenge, you must:
- purchase Bot Management and Fastly Next-Gen WAF for deployment on Fastly's Edge Cloud. The Essential platform for the Next-Gen WAF does not support Bot Management.
- deploy Bot Management using post-cache inspection on each CDN service where you intend to use client challenges. Compute services are not supported.
- enable client challenges on the service where you intend to use them.
Adding embedded challenges
On the page where you want the challenge to appear, complete the following steps:
To the page's
<head>, add the following JS:<script src="/_fs-ch-1T1wmsGaOgGaSxcX/challenge.js" defer></script>HINT: As the script waits for the DOM to be ready before loading the challenge, you can use
asyncorasync deferinstead ofdefer. For information about these attributes, check out Mozilla's documentation.In the location of the page where you want the challenge to appear, add the following div:
<div class="fastly-challenge"></div>(Optional) Use CSS to make all challenge types visible. By default, embedded challenges don't display on the page, unless Fastly detects suspicious activity and chooses an interactive challenge (e.g., CAPTCHA challenge).
(Optional) Set up rules to block requests from clients that failed a challenge.
Making all challenge types visible on the page
By default, embedded challenges don't display on the page unless Fastly detects suspicious activity and chooses an interactive challenge (e.g., CAPTCHA challenge). To make all challenge types visible, use the following CSS directives:
fastly-challenge[data-challenge-status="started"]fastly-challenge[data-challenge-status="processing"]fastly-challenge[data-challenge-status="complete"]fastly-challenge[data-challenge-status="error"]fastly-challenge[data-challenge-status="captcha_prompted"]Sample CSS
Below is a sample CSS that makes all challenge types visible on the page.
1234567/* Base container styling - Pre-allocate space to prevent layout shift */.fastly-challenge {content:"Powered by Fastly"; display: inline-flex; align-items: center; min-height: 32px; min-width: 140px;