Hi,
Let's say i navigate to an website that has an image . This image has src = 'https://www.site.com.br/image1.jpg'.
Is there a way to hot changing this image for another one i choose , and this change reflect on the actual browser ?
I'm trying to build a kind of ad-blocker based on specific urls.
Thanks
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.
Change images ?
- salvadordf
- Posts: 4580
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Change images ?
if the ad-blocker decides to block an image based only in the URL then you can use the TChromium.OnBeforeResourceLoad event.
Check request.url and set Result to RV_CANCEL if you want to block that image.
Check request.url and set Result to RV_CANCEL if you want to block that image.
Re: Change images ?
I want to block images based on mime type. I'm playing with the ResponseFilterBrowser demo.
If I use similar code to yours and FStream (the passed on image), is a png with 1x1 dimensions, it works quite well, since that small image goes unnoticed in most cases. However in some cases it is noticable (Using briskbard's website, there is a white dot on the black header).
If I just call
Then a chrome "broken-image" icon is shown.
Is there another solution? (As you say above, calling RV_CANCEL in OnBeforeResourceLoad event works perfectly, however the mime type is not known at that point...)
Thanks
Code: Select all
procedure TResponseFilterBrowserFrm.Chromium1GetResourceResponseFilter( Sender : TObject;
const browser : ICefBrowser;
const frame : ICefFrame;
const request : ICefRequest;
const response : ICefResponse;
out Result : ICefResponseFilter);
begin
if pos('image', response.MimeType) > 0 then
begin
Result := FFilter;
....
end
else
Result := nil;
If I just call
Code: Select all
aResult := RESPONSE_FILTER_DONE;
Is there another solution? (As you say above, calling RV_CANCEL in OnBeforeResourceLoad event works perfectly, however the mime type is not known at that point...)
Thanks
Re: Change images ?
Actually, if I use a transparent png, then it works fine.
Maybe there is another way?
Maybe there is another way?

- salvadordf
- Posts: 4580
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Change images ?
I think using a 1x1 transparent pixel image is the best solution.