Home > Blockchain >  webview and blocking xmlhttp request and fetch
webview and blocking xmlhttp request and fetch

Time:07-13

As read on the google documentation, the latest released versions of the WebView API block calls to XMLHttpRequest and Fetch but does not explain how to get around this block. Can anyone explain to me how to go about this problem?

CodePudding user response:

You need to set your scheme and hostname to turn on CORS.

<preference name="scheme" value="https" />
<preference name="hostname" value="myapp" />

CodePudding user response:

Hello and thanks for the reply I did this in the config.xml file:

<platform name="android">
        <preference name="scheme" value="https" />
        <preference name="hostname" value="radiomatese.it" />
        <icon src="res/android/icon.png" />
        <allow-intent href="market:*" />
        <resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
</platform>

And the script is this:

const url = "https://www.radiomatese.it/script/app/details.php";
        const response = await fetch(url);
        alert(response.status);
        if(response.ok) { return response.json(); } else { alert(response.error); }

But nothing, if I emulate with the browser everything works perfectly but if I emulate with an android device it does not run the fetch in fact it does not even give me alert(response.status)

  • Related