So with LWC, as with aura, you cannot include scripts directly in the component. When viewing the google JS is specifically states to not copy and paste...so one should not put it in a static resource.
This led me to the iFrame implementation described HERE and adapted as needed.
The problem, as implemented, requires the iFrame to take up a lot of space on the chance that the reCaptcha challenge tiles are presented as shown below:
This is less than desired. What I would like to see is the recaptcha take up less space then if the challenge is presented either show it in a pop-up over the parent or something else that would be more in the flow. If I set the iFrame width and not height this is what happens:
LWC Div
<div>
<iframe src={navigateTo} name="captchaFrame" onload={captchaLoaded} width="310px" style="border-style: none;"></iframe>
</div>
iFrame SRC
<html>
<head>
<title>reCAPTCHA demo: Simple page</title>
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer></script>
</head>
<body>
<form action="?" method="POST">
<div id="html_element"></div>
<br/>
<input type="submit" value="Submit" style="display: none">
</form>
<script type="text/javascript">
var verifyCallback = function(response) {
parent.postMessage("Unlock", "https://xxxx.force.com");
};
var onloadCallback = function() {
grecaptcha.render('html_element', {
'sitekey' : 'redacted',
'size' : 'normal',
'callback' : verifyCallback
});
};
</script>
</body>
</html>
So the question again:
- How to get the reCaptcha to take up the appropriate space on load and when/if the challenge is presented.
- Bonus if there was a way to get the challenge to show in a pop-up over the parent of the framed window.
Right no, I am thinking that LWC is simply out of the question for this use case and a straight VF page is best given the limitations. Seems an implementation of reCaptcha should be part of both aura and LWC IMHO