feat: automatic bot protection#5
Merged
RobertBoes merged 18 commits intomainfrom Apr 1, 2026
Merged
Conversation
Clear currentToken after returning it so subsequent calls wait for the next token, preventing an infinite spin in the upcoming runTokenLoop.
- Fix onCleanup registered after early-return guard (widget leak on v-if cycle) - Fix rejectAbort overwritten each loop iteration (promise leak) - Add try/catch in async watch for widget loading failures - Add onError callback to runTokenLoop to distinguish abort from real errors - Import BotProtectionWidget from @formrelay/core/bot-protection (correct entrypoint) - Wrap Nuxt composable in effectScope for proper watcher cleanup after await - Add tests for onError callback and widget loading failure
- Add .catch() to fire-and-forget loop() call in runTokenLoop - Fix unsafe error cast in fetchSchema — wrap non-FormRelayError in FormRelayError - Add edge case tests: reset during active bot protection, runTokenLoop called twice on container reinit, botToken cleared on v-if container destroy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
botProtectionContaineroption touseFormRelay— pass a template ref and the SDK handles widget loading, token acquisition, expiry renewal, reset re-initialization, and cleanup automatically@formrelay/core/bot-protectionentrypoint withloadBotProtectionWidget(dynamic import switch by protection type) andrunTokenLoop(infinite token acquisition loop with abort handle)@formrelay/nuxtpasses the new option through to the Vue composableTest plan
createCallbackWidgetconsuminggetToken()— 8 tests passingloadBotProtectionWidget— 5 tests (turnstile, recaptcha v2/v3, return value, unknown type)runTokenLoop— 5 tests (initial token, subsequent tokens, stop, post-stop guard, rejection exit)