0

I'm using TChromium to navigate to pages. It has the property Options.ImageLoading , where you can specify if you want to show website's images or not.

Problem is it works only with the option is set in design time. If i change this property in runtime, it has no effect. Here is an example code ; what i wanted to achieve in this example was open test1.com showing images and open test2.com hiding images. Unfortunately both sites are loaded with images, ignoring the option i set.

Any ideas how to fix this ? I want to be able to show images only for certain websites.

procedure tform1.button1click(Sender : TObject);
begin
chromium1.options.ImageLoading = STATE_ENABLED;
chromium1.load('www.test1.com');
end;

procedure tform1.button2click(Sender: TObject);
begin
chromium1.options.ImageLoading = STATE_DISABLED;
chromium1.load('www.test2.com');
end;
delphirules
  • 6,443
  • 17
  • 59
  • 108
  • 1
    CEF's browser settings can't be changed dynamically. Recreating of browser/control should help. – Dmitry Azaraev May 17 '16 at 01:04
  • @fddima That's bad news :( When i used TWebbrowser i could do it dynamically... – delphirules May 17 '16 at 01:05
  • I'm does not know what is TWebBrowser. Because you anyway reload page - recreating browser is most simple way without any cons. Just create controls dynamically, you even can avoid flickering by correct waiting and show/hiding windows. So not a bad news actually. – Dmitry Azaraev May 17 '16 at 01:09
  • @fddima It is because in my old workflow, i could load a page without images, run some script on it and activate the images only after certain point ; this would save a lot of download. In this new sceario i need to show the images since the start. Anyway, thanks for the info. – delphirules May 17 '16 at 01:12
  • 1
    There is absolutely different from yours post. Balance between load/dont load is on you. You always can recreate and restart yours transaction again with images if it is have sense. You actually asking about deferred media loading, what actually, afaik, possible but bit tricky / not guaranteed, but better is have raw access to CEF api (at least you need able provide own CefRequestHandler, also i'm of course speak about latest versions, not sure about delphi bindings). – Dmitry Azaraev May 17 '16 at 01:18

2 Answers2

2

Because @delphirules actually ask about deffered image loading, and next answer is greatest (and applicable to any chromium-based solution) i'm re-post part of this answer here:

You can load a webpage with webkit.webprefs.loads_images_automatically preference set to false then later change it to true and the images will load (you cannot unload images once they're loaded).

Thanks to user amaitland for great findings. :)

Community
  • 1
  • 1
Dmitry Azaraev
  • 1,093
  • 6
  • 9
  • Thank you, this is great news. I just don't know how to set it in the component i'm using, it's a Delphi binding... – delphirules May 19 '16 at 12:21
1

Try this:

  • Create two instances of TChromium, one with options.ImageLoading := STATE_ENABLED and the other with options.ImageLoading := STATE_DISABLED

  • Then, when you want a page to be loaded, make the first one visible and the other one not visible and vice versa.

Obviously, there may be a bit more to do than that, but at least it would avoid having to recreate the browser each time you want to change.

MartynA
  • 30,454
  • 4
  • 32
  • 73