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 ?

Post Reply
thefunkyjoint
Posts: 458
Joined: Thu Aug 10, 2017 12:40 pm

Change images ?

Post by thefunkyjoint »

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
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Change images ?

Post by salvadordf »

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.
RaelB
Posts: 16
Joined: Sun Feb 12, 2017 11:22 am

Re: Change images ?

Post by RaelB »

I want to block images based on mime type. I'm playing with the ResponseFilterBrowser demo.

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 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

Code: Select all

    aResult := RESPONSE_FILTER_DONE;
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
RaelB
Posts: 16
Joined: Sun Feb 12, 2017 11:22 am

Re: Change images ?

Post by RaelB »

Actually, if I use a transparent png, then it works fine.
Maybe there is another way? :)
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Change images ?

Post by salvadordf »

I think using a 1x1 transparent pixel image is the best solution.
Post Reply