Page 1 of 1

Change images ?

Posted: Thu Jan 14, 2021 4:28 pm
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

Re: Change images ?

Posted: Thu Jan 14, 2021 6:14 pm
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.

Re: Change images ?

Posted: Sun Jun 19, 2022 4:09 pm
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

Re: Change images ?

Posted: Sun Jun 19, 2022 10:38 pm
by RaelB
Actually, if I use a transparent png, then it works fine.
Maybe there is another way? :)

Re: Change images ?

Posted: Mon Jun 20, 2022 9:04 am
by salvadordf
I think using a 1x1 transparent pixel image is the best solution.