英文:
How to disable Content Security Policy in Android WebView?
问题
我正在尝试在 WebView 中加载 TikTok 网站。但是我无法加载成功。在 logcat 中我得到了这个错误:
"[仅报告] 拒绝加载脚本 'https://sf16-scmcdn-va.ibytedtos.com/goofy/slardar/fe/sdk/plugins/monitors.3.5.4.maliva.js',因为它违反了以下内容安全策略指令:'script-src 'self' blob: data: 'unsafe-inline' 'unsafe-eval' polyfill.io *.kakao.com *.cdn-apple.com *.tiktokcdn.com *.byteoversea.com *.tiktok.com'。",
来源:https://www.tiktok.com/ (0)
似乎 Chromium 阻止了一些 JavaScript 文件,这就是我得到白屏的原因。我应该如何禁用它,或者是否有任何解决方案?
我的 WebView 代码:
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewWebClient());
webView.getSettings().setSaveFormData(false);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setUserAgentString(System.getProperty("http.agent"));
webView.loadUrl("https://www.tiktok.com/");
英文:
I'm trying to load TikTok website in WebView. But I can't. In logcat I got this error:
"[Report Only] Refused to load the script 'https://sf16-scmcdn-va.ibytedtos.com/goofy/slardar/fe/sdk/plugins/monitors.3.5.4.maliva.js' because it violates the following Content Security Policy directive: "script-src 'self' blob: data: 'unsafe-inline' 'unsafe-eval' polyfill.io *.kakao.com *.cdn-apple.com *.tiktokcdn.com *.byteoversea.com *.tiktok.com".
", source: https://www.tiktok.com/ (0)
Seems Chromium blocking some javascript files that's why I got white screen. How can I disable or any solutions for it?
My Webview:
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewWebClient());
webView.getSettings().setSaveFormData(false);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setUserAgentString(System.getProperty("http.agent"));
webView.loadUrl("https://www.tiktok.com/");
答案1
得分: 1
webView.getSettings().setDomStorageEnabled(true);
已修复。感谢所有人。
英文:
webView.getSettings().setDomStorageEnabled(true);
Fixed it. Thanks all.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论