Skip to content

Fix white flash when takePlayerScreenShot is used with CEF browsers#5004

Open
QueryOfficial wants to merge 2 commits into
multitheftauto:masterfrom
QueryOfficial:fix/cef-screenshot-white-flash
Open

Fix white flash when takePlayerScreenShot is used with CEF browsers#5004
QueryOfficial wants to merge 2 commits into
multitheftauto:masterfrom
QueryOfficial:fix/cef-screenshot-white-flash

Conversation

@QueryOfficial

Copy link
Copy Markdown
Contributor

Summary

Remove the pre/post screenshot hooks that cleared live CEF render targets before takePlayerScreenShot capture. The back buffer is now grabbed as-is after DrawPreGUIQueue, eliminating the visible white flash when a CEF browser is on screen.

Also removes the now-unused OnPreScreenshot, OnPostScreenshot, ClearTextures, and ClearTexture code paths.

Motivation

When the server calls takePlayerScreenShot while a client has a CEF browser displayed via createBrowser + dxDrawImage, the player's screen briefly flashes white on every capture.

The old flow cleared live CEF textures to white (0xFF) before reading the back buffer, then triggered an async Invalidate to repaint them. That touched the same textures used for on-screen rendering in the same frame, so the flash was visible to the player.

This change captures the back buffer without modifying live CEF textures. Screenshot upload continues to work; only the visible flash is removed.

Fixes #4955

Test plan

Create a CEF browser on the client and draw it with dxDrawImage. Call takePlayerScreenShot from the server repeatedly and confirm no white flash appears on the client.

Confirm the server still receives the screenshot with correct game content.

Test downscaled capture with takePlayerScreenShot(player, 320, 240, ...).

Regression: F12 local screenshot still works.

Regression: alt-tab / minimized client still returns MINIMIZED / DISABLED responses as before.

Checklist

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

…e clearing methods

This commit removes the OnPreScreenshot, OnPostScreenshot, and ClearTextures methods from CWebCore and CWebView classes. The changes streamline the code by eliminating unused functionality related to screenshot processing and texture management, improving overall maintainability.
@AlexTMjugador

Copy link
Copy Markdown
Member

It may have been intended by the commit which originally introduced these hooks to intentionally exclude CEF webview contents from screenshots captured by this function, as they can reasonably be considered part of the GUI and may contain more sensitive information than the game scene (usernames or passwords being typed, etc.).

From your PR description alone, it's not clear to me whether you've considered that potentially intentional behavior, or whether your change causes takePlayerScreenShot to start capturing CEF webview contents as well (i.e., the removal of the visible flashing is the only side effect).

Could you elaborate on those considerations?

@QueryOfficial

QueryOfficial commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

Good point. I did consider whether the old behaviour was intentional.

To clarify my planned approach: with withCef = true, the screenshot includes the browser as it appears on screen. With withCef = false, the capture is taken as if the browser were not there, and the player never sees a flash. That follow-up is ready locally but not committed yet — I wanted to align on the intended behaviour first.

Does MTA want browser content to never appear in screenshots at all? If so, I can adjust accordingly in a follow-up commit.

@ffsPLASMA

Copy link
Copy Markdown
Contributor

It may have been intended by the commit which originally introduced these hooks to intentionally exclude CEF webview contents from screenshots captured by this function, as they can reasonably be considered part of the GUI and may contain more sensitive information than the game scene (usernames or passwords being typed, etc.).

From your PR description alone, it's not clear to me whether you've considered that potentially intentional behavior, or whether your change causes takePlayerScreenShot to start capturing CEF webview contents as well (i.e., the removal of the visible flashing is the only side effect).

Could you elaborate on those considerations?

While the idea of censoring certain parts on the clients screen before taking a screenshot is noble, its outdated nowadays. Especially with the tools given in lua to capture all elements (including mta guis) on screen with other means, this "security" approach is kinda outdated.

And given certain servers render CEF on whole screen to draw HUD elements, I dont see any other solution than removing that censoring if this is the root cause.

@QueryOfficial

Copy link
Copy Markdown
Contributor Author

Same here — I agree the censorship should go, which is why this PR removes it. I kept the follow-up uncommitted because I still think it's worth discussing.

If preferred, I can add a withCef parameter:

  • withCef = true — screenshot includes the browser as shown on screen (default behaviour after removing the old hooks)
  • withCef = false — screenshot captures the game scene only, excluding browser content, without any visible flash to the player

Happy to proceed either way based on consensus here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

takePlayerScreenShot causes white flash when a CEF browser is rendered

3 participants