feat: auto-submit iframe challenge answers via postMessage#43
Open
feat: auto-submit iframe challenge answers via postMessage#43
Conversation
When a url/iframe challenge (e.g. OAuth, CAPTCHA) completes inside an iframe, the iframe can now signal completion via postMessage and the client auto-submits the challenge answers without manual user action.
- Fix TypeScript implicit any error by adding type annotations - Only auto-submit when all challenges are url/iframe type - Collect answers positionally from each iframe via postMessage - Use 'challengeanswer' (lowercase) as message type
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
useIframeChallengeAutoAnswerhook that listens forpostMessageevents fromurl/iframechallenges (OAuth, CAPTCHA, mintpass, etc.){type: 'challengeanswer', challengeAnswer: '...'}, the hook auto-submits the answers — no manual "click done" neededusePublishComment,usePublishVote,usePublishCommentEdit,usePublishCommentModeration,usePublishSubplebbitEditurl/iframetype. If there's a mix of iframe + non-iframe challenges, the user must submit manually.How it works
url/iframetypemessageevent listener for each, matching by originpublishChallengeAnswers(answers)with the full arrayBackwards compatible in both directions: old clients without the listener still show "click done"; old challenge servers without postMessage cause the listener to never fire.
Iframe challenge integration guide
Challenge pages (e.g. mintpass) need to add this snippet to auto-submit their result back to the parent plebbit client:
Some iframe challenges handle verification entirely within the iframe itself. In that case, post an empty answer string to notify the subplebbit that the challenge is done:
Notes for challenge developers
challengeAnsweris a single string (one answer per iframe)typemust be exactly'challengeanswer'(all lowercase, matching plebbit event naming convention)window.parent(the iframe's parent window where plebbit-react-hooks runs)Test plan
yarn buildpassesyarn testpasseswindow.postMessage({type: 'challengeanswer', challengeAnswer: ''}, '*')and verifypublishChallengeAnswersis called