I using WebViewClient's shouldInterceptRequest function to filter photos in my android webView.
The problem
I'm trying to block google's base64 URL photos (like:data:image/jpeg;base64,+) using this regex data:image/(jpg|png|jpeg);base64, but without success.
I done my research and found that:
these base64 background images are injected with JS.
but I don't know to continue.
my code:
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
String url = request.getUrl().toString();
if (imgCheck(url,res))
{
return new WebResourceResponse(
BrowserUnit.MIME_TYPE_TEXT_PLAIN,
BrowserUnit.URL_ENCODING,
new ByteArrayInputStream("".getBytes())
);
}
return super.shouldInterceptRequest(view, request);
}
private static boolean isImage(String url, Resources res) {
BufferedReader imageUrlRegex = openRawFile(res, R.raw.image_regex);
try {
String line = imageUrlRegex.readLine();
while (line != null) {
Pattern pattern = Pattern.compile(line);
if (pattern.matcher(url).find())
return true;
line = imageUrlRegex.readLine();
}
} catch (IOException e) {
e.printStackTrace();
return true;
}
return false;
}
data:image/(jpg|png|jpeg|svg|ico|webp|tif|tiff|bmp|eps|apng|avif|jfif|pjpeg|pjp|cur);base64,
**note : I tried block like this return url.contains("data:image"); still nothing