Using rails, and pulling in the recaptcha js through gems, I was unable to use the onloadCallBack "quick fix" option above because those assets are loaded earlier, and reloading them entirely seemed wasteful. I opted for a similar setAttribute, but needed to wait for a few seconds (even when using document.ready) to make sure the textarea was available on which to update the attribute. This seems to do what the question asker needs from a rails perspective, as was in my case, and screen readers will behave as desired/expected:
<script type="text/javascript">
$(document).ready(function(){
setTimeout(() => {
var textarea = document.getElementById("g-recaptcha-response");
textarea.setAttribute("aria-hidden", "true");
textarea.setAttribute("aria-label", "do not use");
textarea.setAttribute("aria-readonly", "true");
}, 2000);
});
</script>
If you're looking for a clean report for a client that reflects actual screen reader results, the wave browser extension for chrome and firefox both report clean (no error), while the wave web-based app still has an error on that field. htmlcodesniffer clears that textarea without error, but actually reports an error on the recaptcha iframe (which is above the textarea) having an empty title, which can't be changed because of the cross-site scripting request to update the iframe (that has different domain origin). Have a lovely day.