react-native-web-community/react-native-web-webview

Implement recaptcha in expo web

Davete0302 opened this issue · 0 comments

I'm trying to implement recaptcha but keep getting errors cannot read properties of undefined (reading 'postMessage')

import WebView from 'react-native-webview';

 const getWebviewContent = () => {
        var originalForm = '<!DOCTYPE html><html><head><script src="https://www.google.com/recaptcha/api.js"></script></head><body><form action="[POST_URL]" method="post"><input type="hidden" value="[TITLE]"><input type="hidden" value="[DESCRIPTION]"><input type="hidden" value="[URL]"><div class="g-recaptcha" data-sitekey="<site-key>"></div><input type="submit" value="Send"/></form></body></html>'
        var tmp = originalForm
            .replace("[POST_URL]", "http://localhost:19006/Contact")
            .replace("[TITLE]", 'title')
            .replace("[DESCRIPTION]", 'description')
            .replace("[URL]", 'http://localhost:19006/Contact');

        return tmp;

    }

 <WebView
     javaScriptEnabled={true}
     mixedContentMode={'always'}
     style={{ height: 500, width: 500 }}
     source={{
     html: getWebviewContent(),
     baseUrl: '<domain>' // <-- SET YOUR DOMAIN HERE
   }} />