Hello,
I recently ran into a problem where I wanted to block some ads in my app's browser, usually by blocking the URL with a regex or deleting certain elements with js. However, there is a special case where the URL doesn't have a special gif extension or anything like that, and there is no attribute labeled image, but it gets a stream of GIF content and causes the browser to display them.
I've tried many ways, and found that the loading process is only triggered in BeforeResourceLoad and GetResourceHandler events. I was thinking of doing it in GetResourceResponseFilter but it doesn't get triggered.
I have 2 questions.
1. In this case, in which event can I read out the response stream data first, and then replace it with my own if it's a GIF? CustomResponseFilter.OnFilter?
2. Right now the only way I can do this is to match URLs in BeforeResourceLoad, which is not a good way that needs the user to blacklist it for each random URL. Is there a better way to do this?
Thanks for your attention and help!
Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
Try to block GIF content(not URL) but don't know how.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Try to block GIF content(not URL) but don't know how.
Hi,
Try using TChromiumCore.OnResourceResponse and compare the response.MimeType value to "image/gif". Read the code comments for that event to know if CEF still allows you to stop/redirect that request.
The hardest way to block a GIF would be using a filter. The ResponseFilterBrowser demo shows how to replace an image in the TResponseFilterBrowserFrm.ReplaceLogo procedure. You can inspect the buffer to detect the GIF file header :
https://en.wikipedia.org/wiki/List_of_file_signatures
Try using TChromiumCore.OnResourceResponse and compare the response.MimeType value to "image/gif". Read the code comments for that event to know if CEF still allows you to stop/redirect that request.
The hardest way to block a GIF would be using a filter. The ResponseFilterBrowser demo shows how to replace an image in the TResponseFilterBrowserFrm.ReplaceLogo procedure. You can inspect the buffer to detect the GIF file header :
https://en.wikipedia.org/wiki/List_of_file_signatures
Re: Try to block GIF content(not URL) but don't know how.
Thanks for the reply, you are always so friendly.
I just tested it again in detail and found that it was triggering at OnResourceResponse() instead of not triggering as I said before, but the URL had changed and I didn't notice it.
So it's something that can be handled in OnResourceResponse() as you said.
Thanks!
I just tested it again in detail and found that it was triggering at OnResourceResponse() instead of not triggering as I said before, but the URL had changed and I didn't notice it.
So it's something that can be handled in OnResourceResponse() as you said.
Thanks!