[英]Ionic 5/Capacitor ERR_CLEARTEXT_NOT_PERMITTED in Android
[英]ERR_CLEARTEXT_NOT_PERMITTED on Android 9, with domain cleartext permitted
在 Android 10 設備上,我在 http 服務器上的 webview 中收到 ERR_CLEARTEXT_NOT_PERMITTED 錯誤,但僅限於某些頁面,即使我使用 network_security_config 來允許域。 我只能通過使用 . 我該如何解決這個問題,以便只允許我的域,並且不會收到錯誤,但不使用 ?
日志貓:
07:54:09.004 com.myserver.myapp D/myapp: Webview.onPageStarted called on http://myserver.com/myapp/index.php?view=discrete
07:54:09.232 com.myserver.myapp I/myapp: onPageFinished called.
07:54:15.938 com.myserver.myapp D/myapp: Webview.onPageStarted called on http://myserver.com/myapp/index.php?view=about
07:54:15.958 com.myserver.myapp I/myapp: onReceivedError called.
07:54:15.958 com.myserver.myapp I/myapp: Web Load Error:net::ERR_CLEARTEXT_NOT_PERMITTED
07:54:16.012 com.myserver.myapp I/myapp: onPageFinished called.
網絡安全配置 xml:
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">localhost</domain>
<domain includeSubdomains="true">myserver.com</domain>
</domain-config>
<!-- Want to delete this for better security-->
<base-config cleartextTrafficPermitted="true"/>
</network-security-config>
根本原因是提供第三方廣告內容 (Google Ads) 的 javascript 沒有使用 https。
向 onReceivedError 添加了代碼以記錄導致問題的 URL...
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
Log.i(TAG, "onReceivedError called for URL "+ request.getUrl().toString());
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.