首页 > android > 被阻止:Android webView中的csp

被阻止:Android webView中的csp (Getting blocked:csp in Android webView)

问题

我有一个用ReactJS编写的Web应用程序和使用NextJS呈现的服务器。它适用于所有浏览器,但是当我在Android webView中打开它时,我的所有请求都被阻止,原因是“csp:blocked”,如下面的屏幕截图所示。

我没有指定我自己的任何CSP政策。

这是我的next.config

/**
 * Disable public routes from "pages" folder.
 */
useFileSystemPublicRoutes: false,
/**
 * Change "__next" directory path.
 */
assetPrefix: '/store/__js',
webpack: (config) => {
    config.output.publicPath = `/store/__js${config.output.publicPath}` // eslint-disable-line no-param-reassign
    return config
},

csp:在用于在NextJS中编写的Web应用程序的Android webView中被阻止

解决方法

面对完全相同的问题,您需要在Android端的WebView设置中进行一些更改。

WebSettings webSettings = yourWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
yourWebView.loadUrl("yourWebUrl");

问题

I have a web app that is written in ReactJS and server rendered using NextJS. It works fine on all browsers but when I open it in Android webView, all my requests are blocked citing the reason "csp:blocked" as shown in the screenshot below.

I haven't specified any CSP policy of my own.

Here's my next.config

/**
 * Disable public routes from "pages" folder.
 */
useFileSystemPublicRoutes: false,
/**
 * Change "__next" directory path.
 */
assetPrefix: '/store/__js',
webpack: (config) => {
    config.output.publicPath = `/store/__js${config.output.publicPath}` // eslint-disable-line no-param-reassign
    return config
},

csp:blocked in Android webView for web app written in NextJS

解决方法

Faced exactly the same issue, you need to do some changes in WebView settings on Android side.

WebSettings webSettings = yourWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
yourWebView.loadUrl("yourWebUrl");
相似信息