Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPF - Browser goes blank if used in combination with TabControl #2779

Closed
dkrainyk opened this issue May 17, 2019 · 73 comments
Closed

WPF - Browser goes blank if used in combination with TabControl #2779

dkrainyk opened this issue May 17, 2019 · 73 comments
Labels
known-issue upstream These issues require fixing in the Chromium Embedded Framework(CEF) or Chromium. wpf
Milestone

Comments

@dkrainyk
Copy link

  • What version of the product are you using?
    Nuget 73.1.130 and 74.1.130-CI3117 (not reproducible on 71.0.2)

  • What architecture x86 or x64?
    x64

  • On what operating system?
    Win10

  • Are you using WinForms, WPF or OffScreen?
    WPF

  • What steps will reproduce the problem?
    Use TabControl (or similar approach) to launch ~10 tabs of ChromiumWebBrowser pointing to google.com
    Switch between tabs and eventually (after 10-20 switches) browser will go blank (according to debug tools browser still works and you can execute JS, change DOM, etc.).

Adapted minimal example: dkrainyk/CefSharp.MinimalExample@8fa4bd5

  • What is the expected output? What do you see instead?
    Browser window goes blank. Page should be visible.

  • Please provide any additional information below.
    debug.log is empty

  • Does this problem also occur in the CEF Sample Application from http://opensource.spotify.com/cefbuilds/index.html?
    N/A

@amaitland amaitland added the upstream These issues require fixing in the Chromium Embedded Framework(CEF) or Chromium. label May 21, 2019
@amaitland
Copy link
Member

Looks like a bug in CEF, will add more details later.

I suspect that testing with with cefclient and minimizing/maximizing the window will probably reproduce the same problem.

For now rollback to version 71.

@hucongquan

This comment has been minimized.

@amaitland amaitland added the wpf label May 21, 2019
@amaitland
Copy link
Member

environment: winform use cefsharp(nuget);

@hucongquan If you are using WinForm then your issue is completely unrelated to this one.

is it too big data for chrome to process?

Probably the render process is crashing with an out of memory exception if you are loading huge amounts of data. Upgrading to a newer version of CEF is likely the only fix (remember that CefSharp is just a wrapper).


Now back to the actual issue at hand. The OnPaint method continues to be called even though it looks like it's not rendering, it's just getting invalid data, the DirtyRect has y = 0, a rough check and the width and height appear to be correct. So CEF is basically passing an incorrect image back. Resizing the browser in most cases causes it to start rendering again, there was a very similar issue with CEF not too long ago.

CEF is about to undergo a major rewrite of the Offscreen Rendering implementation due to a Chromium change, outlined in https://bitbucket.org/chromiumembedded/cef/issues/2575/viz-implementation-for-osr there is a PR which is still reportedly a work in progress at https://bitbucket.org/chromiumembedded/cef/pull-requests/226/wip-viz-osr-implementation/diff

It's probably worth someone creating an issue upstream after a bit more testing, though I don't expect this to be fixed until the new VIZ implementation is done unless someone specifically wants to debug the issue and submit a PR.

Probably next week I'll do some more testing to see if there's a viable workaround.

@amaitland
Copy link
Member

Please only post further comments if you have a viable workaround, other non constructive comments will likely be removed.

@amaitland

This comment has been minimized.

@dkrainyk

This comment has been minimized.

@amaitland

This comment has been minimized.

@nocanstillbb

This comment has been minimized.

@ray007
Copy link

ray007 commented Jul 5, 2019

We had a similar problem, and a resize on show helped as workaround.
Increase height by 1 and set it back to original.

@amaitland
Copy link
Member

Once the cefsharp/75 branch is created I'll look at applying a hack to resize the browser when it becomes visible. Viz support should be available in the 77 release, so hopefully this will be resolved properly.

@mol

This comment has been minimized.

@nocanstillbb

This comment has been minimized.

@ray007

This comment has been minimized.

@mol
Copy link
Contributor

mol commented Jul 24, 2019

Thanks guys - I managed to get it set up and working, but the width/height change is messing up the other resize code/bindings we have, so that's not great.

@amaitland any idea if there's another way to "give it a kick" without setting the width/height? It's pretty easy to reproduce using the latest WPF example in case you haven't seen (assuming it's the same issue):
https://www.screencast.com/t/1UQDCCEk

@nocanstillbb

This comment has been minimized.

@amaitland
Copy link
Member

@mol I'm not aware of another way. How are you resizing? My plan is to use an approach similar to https://github.com/cefsharp/CefSharp/blob/master/CefSharp.Wpf.Example/Controls/ChromiumWebBrowserWithScreenshotSupport.cs

I will implement a workaround hopefully tomorrow if all goes well.

@mol
Copy link
Contributor

mol commented Jul 25, 2019

@nocanstillbb yeah I'm using SetCurrentValue but it's not that it's clearing a binding, it's that we have some JavaScript triggering resizes as well when the content in the browser changes (and it seems to break as a result of the workaround. Probably some kind of timing/race condition issue).

@amaitland that would be amazing. I tried forcing the InteropBitmapRenderHandler to create a new Bitmap but then I saw it was already doing it when the issue occurs, and I can't see what the difference is for when it works (with the resizing hack) and when it doesn't. But I can't say I'm familiar with the code so hopefully you can figure it out :)

@mol
Copy link
Contributor

mol commented Jul 25, 2019

@amaitland you probably already know but I just noticed that the elements on the page shown in the browser are still clickable in the blank browser, they're just not drawn.

amaitland added a commit that referenced this issue Jul 26, 2019
Do this so it's easier to implement a workaround for #2779
amaitland added a commit that referenced this issue Jul 26, 2019
@amaitland
Copy link
Member

Rough hack was added in 0d67b05

Will add more details tomorrow. It's had some testing, needs quite a bit more.

@mol
Copy link
Contributor

mol commented Jul 26, 2019

Thanks a lot Alex, I really appreciate it. Looks interesting. When you think it's ready we'll release it as an alpha for testing.

amaitland added a commit that referenced this issue Jul 27, 2019
Do this so it's easier to implement a workaround for #2779
@amaitland
Copy link
Member

So the hack basically works like this

  • When the browser is hidden/minimised we set a bool to ignore subsequent OnPaint calls.
  • Waits 50ms then resizes the browser, reduces it's height/width by 1px
  • Waits 50ms then resizes browser to it's original dimensions
  • Waits 50ms then calls Invalidate to generate a new frame (was seeing a few instances of flicker where an empty frame was rendered). It's possible we can do without this, leaving it for now as I've tested with it being there.
  • Set bool to continue OnPaint calls

Attempting to resize the browser when the hack is running shouldn't cause any problems though I've only tested whilst my automated test was running, so it's not a definitive test. The new value should be stored and restored as it's original dimensions. The hack will take ~150ms to run, it might be possible to reduce this, reducing the 50ms wait before Invalidate would be the first step if absolutely required.

Further changes

  • Add option to disable hack in c912277
  • Only call WasHidden and enable hack when WindowState was previously Minimised 22a9149

I've had the CefSharp.Wpf.Example switching between two tabs every second for 1000 iterations and both tabs were functional.

@mol Should be ready for a wider audience to test, I've only tried against version 75 though, should work on an older branch if you backport the changes starting at 1423a97 and finishing at 22a9149

@amaitland
Copy link
Member

as you explained this might be the reason.right??

@Shankp It's likely though I cannot say for sure without an actual example.

1*1 size will not reflect your hack.

For version 79.1.x that is correct. For version 81.3.x the hack will add one to the size instead of subtracting, see 8b40e9b

The 81.3.20-pre release is on Nuget.org for testing purposes.

@deonberlin
Copy link
Contributor

@amaitland Would be great if we could expose the the method ResizeHackFor2779() to derived classes. If one sets WasHidden() on other occasions, the method could be reused and has not to be implemented again.

@amaitland
Copy link
Member

@deonberlin Is there something stopping you from using reflection?

In this case I'm not keen on making this part of the public API.

@deonberlin
Copy link
Contributor

@amaitland I thought of this, because the properties for configuring this hack are also public and for some use-cases it's a requirement to apply this hack, until the issue is resolved.

But I understand your concerns and will go with reflection.

amaitland added a commit that referenced this issue Oct 4, 2020
…2779)

- Add 1 to the width/height rather than subtracts like the hack in the previous
versions
- Delay between resizes is now configurable via ResizeHackForIssue2279DelayInMs
amaitland added a commit that referenced this issue Jan 9, 2021
…2779)

- Add 1 to the width/height rather than subtracts like the hack in the previous
versions
- Delay between resizes is now configurable via ResizeHackForIssue2279DelayInMs
@dkrainyk
Copy link
Author

@amaitland I see that 88.1.0-CI3869 doesn't resize on tab change and this issue is not reproducible there.
Was it finally fixed on upstream?

@amaitland
Copy link
Member

I see that 88.1.0-CI3869 doesn't resize on tab change and this issue is not reproducible there.
Was it finally fixed on upstream?

@dkrainyk Before a final release I do some testing to see if the problem reproduces, if it does then I manually cherry pick the required commit into the release branch. As yet I haven't done in testing for M88. It would be fantastic if it's fixed. To my knowledge the upstream issue is still open. It's possible that Chromium has changed and we're the beneficiaries, it may also be that it's just harder to reproduce.

amaitland added a commit that referenced this issue Feb 9, 2021
@amaitland
Copy link
Member

I can reproduce the problem in version 88, so the hack will stay enabled by default.

amaitland added a commit that referenced this issue Mar 4, 2021
…ible (#2779)

Problem still reproduces, so readding hack to 88 release branch

This reverts commit 47a3fe1.
@zhuchaoyanzi
Copy link

@amaitland Most device is ok, but a new Sureface with the latest version also didn't work. blank ui, but resize will show.

@amaitland
Copy link
Member

WPF the browser stops redrawing when running on Intel Iris Xe Integrated GPU(11th Gen). The issue has been reported to the WPF team see dotnet/wpf#3817

As per https://github.com/cefsharp/CefSharp/releases/tag/v89.0.170

@zhuchaoyanzi
Copy link

zhuchaoyanzi commented May 8, 2021 via email

@dkrainyk
Copy link
Author

@kkwpsv I see in your commit you disabled resize hack and commented WasHidden usages, did it help?

@kkwpsv
Copy link
Contributor

kkwpsv commented Aug 10, 2021

@kkwpsv I see in your commit you disabled resize hack and commented WasHidden usages, did it help?

Yes. It'll not go blank. But it may has performance issuess. When browser is hidden. it will continue to render.
In my application, I chose this method

amaitland added a commit that referenced this issue Sep 5, 2021
…ible (#2779)

Problem still reproduces, so readding hack to release branch
@rothariger
Copy link

version 93 and still happening... any news about this?

@amaitland
Copy link
Member

@rothariger As I've stated before, it's an upstream bug, the best we can do is attempt a workaround. Upstream issue https://bitbucket.org/chromiumembedded/cef/issues/2483/osr-invalidate-does-not-generate-frame

The workaround is included in the 93-pre release see commit 9140c08 if you have a use case for which this doesn't work you are welcome to debug and submit an PR with improvements.

The workaround isn't included in the master branch deliberately so it's easier to test with new versions.

@rothariger
Copy link

i just stop getting the issue by changing this...
scale

@amaitland amaitland added this to the 94.2.x milestone Sep 22, 2021
@amaitland
Copy link
Member

An upstream fix has just been committed and will be available in version 94.

https://bitbucket.org/chromiumembedded/cef/commits/b156d790e35e1fea7e92097339a03a0185548f1d

@amaitland amaitland changed the title Browser goes blank if used in combination with WPF TabControl WPF - Browser goes blank if used in combination with TabControl Sep 22, 2021
@amaitland
Copy link
Member

For those using Intel Iris Xe Integrated GPU(11th Gen) there is an issue that maybe mistake for this one where the browser stops redrawing. There is a bug in the driver for which Intel have released an update, see https://www.intel.com/content/www/us/en/support/articles/000058136/graphics/graphics-for-11th-generation-intel-processors.html

See dotnet/wpf#3817 for workaround if you are unable to install the updated driver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
known-issue upstream These issues require fixing in the Chromium Embedded Framework(CEF) or Chromium. wpf
Projects
None yet
Development

No branches or pull requests