android-webviewandroid-developer-apiandroid-websettingscross-origin-read-blockingandroid-chrome

Dynamic images won't load, shows up as text/html MIME type, fix for webview?


For example, a link for one of the images goes to a url https://storage.notmywebsite.com/some/path/on/website/image:Static,Small/ImageFileName?params=123456.

When degbugging webview via chrome://inspect, the kind of error that shows up is ...

Cross-Origin Read Blocking (CORB) blocked cross-origin response https://login.notmywebsite.com/login.srf?moreparams=123456&wreply=https:%2F%2Fstorage.notmywebsite.com%2Fstorageservice%2Fpassport%2Fauth.aspx%3Fsru%3Dhttps:%252f%252fstorage.notmywebsite.com%252fsome%252fpath%252fon%252fwebsite%252fimage:Static%252cSmall%252fImageFileName&otherparams=123456 with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.

However, loading the same website in the Chrome web browser, those images show up... so what is going wrong? Is there any way to fix this?


Solution

  • I finally figured out what was wrong.

    For the webview, it needs one more setting turned on in order for the cookies of the website to be used in order to access credential protected images.

    So, if you want to fix it for your application, just use the following code.

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
    else
        CookieManager.getInstance().setAcceptCookie(true);