BerndGabriel/HtmlViewer

THtmlViewer.LoadHTML hangs when loading an html with css code that includes a media query on color scheme

chrswgnr opened this issue · 2 comments

Hey when I load an html with a color scheme media query the Load function doesn't return resulting an application hang for us.

Here is a small code sample that you can add to a TForm of a VCL APplication to reproduce.

var
  LHtmlViewer: THtmlViewer;
begin
  LHtmlViewer := THtmlViewer.Create(Self);
  LHtmlViewer.Align := alClient;
  LHtmlViewer.LoadFromString('<html><head><style type="text/css">@media (prefers-color-scheme: dark) .ReadMsgBody {width: 100%;}</style></head><body><div>Hallo Welt</div></body></html>');
end;

We are currently using the HtmlViewer in Version 11.8, but a quick test with 11.9 also had the same issue.

Thanks for spotting this issue.

Commit 9be6af1 fixes it in the master branch.

Please notice that the correct syntax of the media query expression requires braces around the style(s):
@media (prefers-color-scheme: dark) { .ReadMsgBody {width: 100%;} }

Thanks for the quick response and fix.

Good point. Unfortunately the incorrect synatx html was some breakdown from some big company newsletter that one of our users wanted to view within the THtmlViewer.