3

I use TChromium. I assign AWebPageAsString which is a static HTML page with a gray background color.

FBrowser := TChromium.Create(pnlHolder);
FBrowser.Visible := false;
FBrowser.Parent := TWinControl(pnlHolder);
FBrowser.Align := alClient;
FBrowser.OnBeforeBrowse := BrowserBeforeBrowse;
FBrowser.HandleNeeded;
FBrowser.FontOptions.RemoteFontsDisabled := true;
FBrowser.Browser.MainFrame.LoadString(AWebPageAsString, 'navigate:webpage');

When I start the application it is displayed first with white background and empty content and then my page gets displayed with gray background and actual content.

Is there a way to avoid this ? Maybe have a default background color ?

TLama
  • 71,521
  • 15
  • 192
  • 348
Gad D Lord
  • 6,130
  • 10
  • 50
  • 98
  • Why don't you load the page with the browser hidden and only show it when load is complete? – David Heffernan Dec 27 '11 at 14:48
  • Possibly because that is what the Chrome engine does. When I have had the Chrome browser minimized for some time, then restore it and navigate to a different tab, it displays with an entirely white background and no content before showing the page as it was before. – Marjan Venema Dec 27 '11 at 15:10
  • "Why don't you load the page with the browser hidden and only show it when load is complete?" - tried that way with Visibility property and OnLoadEnd but still the same behavior. – Gad D Lord Dec 27 '11 at 15:34
  • Tried 1. make the browser invisible by default 2. Handled OnLoadStart and make FBrowser.Visible := true; Unfortunately the OnLoadStart does not even get fired. – Gad D Lord Dec 28 '11 at 15:12

1 Answers1

2

Quite a late answer, I know, but it's at least an interesting topic. To change default browser's background color you can use a custom stylesheet. It sounds good, but it has one big weakness - when you navigate to a page that has e.g. no stylesheet defined, your custom one will be applied. But if you know that you'll browse e.g. only your pages in a certain style, it might be even advantage, since then you can leave the style definitions defined in that default custom style.

So to create a browser with a black background (using the style described below) you can use this code:

procedure TForm1.FormCreate(Sender: TObject);
const
  CSSHeader = 'data:text/css;charset=utf-8;base64,';
  CSSBase64 = 'Ym9keSB7YmFja2dyb3VuZC1jb2xvcjpibGFjazt9';
begin
  Chromium1.UserStyleSheetLocation := CSSHeader + CSSBase64;
  Chromium1.Options.UserStyleSheetEnabled := True;
  Chromium1.ReCreateBrowser('about:blank');
end;

The CSSBase64 constant used in the above code is the following stylesheet encoded to Base64:

body {background-color:black;}
TLama
  • 71,521
  • 15
  • 192
  • 348