- Code: Select all
@Override
public boolean onBeforeResourceLoad(CefBrowser cefBrowser, CefFrame cefFrame, CefRequest cefRequest) {
if (cefRequest.getResourceType().equals(RT_IMAGE)) {
cefRequest.setMethod("HEAD");
}
return false;
}
The problem with this is that the request is still being made to the server which is slower than simply blocking the request. The other technique I can think of is to set the URL to some value that is not "active". This way, the request fails right away making this solution a bit faster than the previous one.
- Code: Select all
@Override
public boolean onBeforeResourceLoad(CefBrowser cefBrowser, CefFrame cefFrame, CefRequest cefRequest) {
if (cefRequest.getResourceType().equals(CefRequest.ResourceType.RT_IMAGE)) {
cefRequest.setURL("https://tyghjjknm.ertyu");
System.out.println("LOL!");
}
return false;
}
In my opinion, the above tricks must be avoided if there's a better solution, like canceling/blocking the request by simply calling a method. I don't know if such a method exists. Can you give a more robust solution for doing what's mentioned. Also, I should point out that both tricks fail to prevent loading images loaded using the data uri scheme (e.g. <img src="data:image/jpeg...." />)