chromiumembedded / cef

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
https://bitbucket.org/chromiumembedded/cef/
Other
3.26k stars 456 forks source link

OnAutoResize calls fall into an infinite loop on some webpages #3360

Closed magreenblatt closed 2 years ago

magreenblatt commented 2 years ago

Original report by Ilia Korjoukov (Bitbucket: Ilia Korjoukov).


On some webpages, if the auto-resize is enabled via CefBrowserHost::SetAutoResizeEnabled, CefDisplayHandler.OnAutoResize starts being called infinitely with incrementally growing height in the new_size parameter. The height grows up to hundred thousands pixels, which completely exceeds the real webpage height.

The examples of such webpages:

https://www.bbc.com/culture

https://www.bbc.com/future

magreenblatt commented 2 years ago

Original comment by Alex Maitland (Bitbucket: a-maitland).


When posting a BUG REPORT please answer the following questions in your issue description:

  1. What steps will reproduce the problem?
  2. What is the expected output? What do you see instead?
  3. What version of the product are you using? On what operating system?
  4. Does the problem reproduce with the cefclient or cefsimple sample application at the same version? How about with a newer or older version?

magreenblatt commented 2 years ago

Original comment by Ilia Korjoukov (Bitbucket: Ilia Korjoukov).


Hi,

Sorry for missing details, here they are.

I am using CefSharp wrapper libraries in a WPF application (.NET 4.6.1) complied in Windows 11.

The versions of the used nuget packages are:

CEFSharp: 103.0.90

cef.redist.x64 : 103.0.9

When a new page is loaded, I expect a one or few calls of the OnAutoResize callback with the new_size parameter returning the full size of the loaded webpage. It works for the most pages, but not for all. Some pages, like https://www.bbc.com/culture, cause a infinite sequence of OnAutoResize calls with incrementally growing height in the new_size parameter. The calls continues until the height hits the limit set by the max_size parameter in the SetAutoResizeEnabled().

I enclose here a download link to a VS 2022 project that reproduces that issue. The project is a WPF app that contains a browser and box showing calls of the OnAutoResize.

magreenblatt commented 2 years ago

Original comment by Alex Maitland (Bitbucket: a-maitland).


The calls continues until the height hits the limit set by the max_size parameter in the SetAutoResizeEnabled().

How is that infinite exactly?

It’s not uncommon for web pages to virtualize content.

Is the website rendering content to fill the space? If yes then Sounds like everything is working as expected.

magreenblatt commented 2 years ago

Agreed, sounds like it's working as expected.

magreenblatt commented 2 years ago

Original comment by Ilia Korjoukov (Bitbucket: Ilia Korjoukov).


Although you can expect multiple onAutoResize call on virtualized pages, I don't think that it’s a reason. For 'good' pages, like www.bbc.co.uk . I record 11 OnAutoResize calls during page loading. The calls return the following sizes:

{700 x 716), {700 x 1047), {700 x 9684), {700 x 9716), {700 x 9764), {4679 x 7233), {1280 x 8541), {1280 x 8541), {1280 x 8574), {1280 x 8525), {1280 x 8617)

Note that the last call (1280 x 8617) matches the real full page size.

For ‘bad’ pages, the calls are infinite, unless the returned height hits the max height limit set in SetAutoSizeEnabled, up to Int32.Max. For example, these are calls for https://www.bbc.com/culture

{700 x 700), {700 x 7735), {700 x 9411), {700 x 11087), {700 x 25487), {700 x 26387), {700 x 27287), {700 x 29087), {700 x 33587), {700 x 34487), {700 x 35387), {700 x 39887), {700 x 40787), {700 x 44387), {700 x 48887), {700 x 49787), {700 x 50687), {700 x 51587), {700 x 56087), {700 x 56987), {700 x 57887), {700 x 64187), {700 x 65087), {700 x 65987), {700 x 68687), {700 x 74087), {700 x 74987), {700 x 75887), {700 x 82187), {700 x 83087), {700 x 83987), {700 x 90287), {700 x 91187), {700 x 92087), {700 x 99287), {700 x 100187 (bb)), {700 x 101087 (bb)), {700 x 101987 (bb)), {700 x 110087 (bb)), {700 x 110987 (bb)), {700 x 111887 (bb)), {700 x 116387 (bb)), {700 x 117287 (bb)), {700 x 118187 (bb)), {700 x 122687 (bb)), {700 x 125387 (bb)), {700 x 129887 (bb)), {700 x 135599 (bb)), {700 x 136499 (bb)), {700 x 137399 (bb)), {700 x 141899 (bb)), {700 x 142799 (bb)), {700 x 143699 (bb)), {700 x 148199 (bb)), {700 x 149099 (bb)), {700 x 149999 (bb)), {700 x 154499 (bb)), {700 x 155399 (bb)), {700 x 156299 (bb)), {700 x 163499 (bb)), {700 x 164399 (bb)), {700 x 166199 (bb)), {700 x 170699 (bb)), {700 x 172499 (bb)), {700 x 173399 (bb)), {700 x 175199 (bb)), {700 x 179699 (bb)), {700 x 180599 (bb)), {700 x 185099 (bb)), {700 x 185999 (bb)), {700 x 186899 (bb)), {700 x 187799 (bb)), {700 x 192299 (bb)), {700 x 193199 (bb)), {700 x 194099 (bb)), {700 x 198599 (bb)), {700 x 199499 (bb)), {700 x 200000 (bb))

Note that the last height, 200 000, is the limit that I set in SetAutoSizeEnabled. If the limit is larger, more calls are made until it is hit. The real page height is about 10 000 pixels. Moreover, if I take a screenshot of the ‘bad’ page with devtools, the screenshot shows the page divided in 2 parts, top and bottom, with an empty space between parts. See the attached screenshot below (the max limit in SetAutoSizeEnabled was set to 20 000 x 20 0000)

My guess is that certain HTML tags or JS causes incorrect measures in the auto resizing.

magreenblatt commented 2 years ago

Any use of “auto resize” should be in partnership with the page author/designer. The functionality is not intended to work (perfectly or at all) with random websites that were not tested/designed for it.

magreenblatt commented 2 years ago

Original comment by Ilia Korjoukov (Bitbucket: Ilia Korjoukov).


Ok, what are requirements for this “auto-size functionality” you mentioned? Are they documented? How exactly the bbc culture page breaks it?

In my opinion, this is clearly a bug in auto-sizing code, given that OnAutoSizes callbacks go to the infinite loop and therefore hang/slow the browser app. Imagine a CEF user “randomly” browses to such page (these pathetic BBC culture lovers!) and crushes his browser. Is it BBC website to blame?

magreenblatt commented 2 years ago

Original comment by Alex Maitland (Bitbucket: a-maitland).


Based on the screenshot I'd say it is a bug in the BBC website. Likely they’ve never tested the size you are testing with as it falls outside the scope of regular usage.

CEF to my understanding doesn’t perform any actual changes to the web page which is What it sounds like you are implying. See how the web page displays in Chrome when you emulate a giant screen size in DevTools (assuming you still can).

You will likely need to impose some realistic limits within your code.

magreenblatt commented 2 years ago

Original comment by Dmitry Azaraev (Bitbucket: Dmitry Azaraev).


In fact given page has fixed size with fluid markup, so it looks like bug in engine. However CEF do nothing with it, so even if it bug - then it in Chromium.

magreenblatt commented 2 years ago