Search Issue Tracker
By Design
By Design in 2023.1.X
Votes
0
Found in
2020.3.42f1
2021.3.14f1
2022.1.23f1
2022.2.0b16
2023.1.0a20
Issue ID
UUM-19938
Regression
No
[WebGL] The canvas element gets constantly resized when width and height are defined in attributes but not styles
Reproduction steps:
1. Open the attached “IN-22017_unity-bug-webgl-canvas-rescale-to-infinity.7z“ project
2. Open “SampleScene” scene
3. Switch platform to WebGL
4. In Player settings, choose the WebGL template called 'WorkingStyles', Build and Run the project
5. Inspect the local server window. Canvas is visible and scales according to the window size
6. In Player settings, choose the WebGL template called 'BuggedAttributes', Build and Run the project
7. Inspect the local server window. Canvas is black and keeps constantly scaling
8. Inspect window console log errors
Expected result: Canvas scales according to screen size
Actual result: Canvas keeps constantly scaling and the screen goes black
Reproducible with: 2020.3.42f1, 2021.3.14f1, 2022.1.23f1, 2022.2.0b16, 2023.1.0a20
Reproduced on: macOS Monterey 12.6 (Intel)
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Out-of-bounds memory access with multiple CanvasRenderers under a Canvas when using Mesh API
- Inspector tries to access file after it was deleted when the file was locked in Inspector window
- Changing Transform values in Search window Inspector loses focus while dragging and stopping mouse without releasing dragging action
- Saving changes on the dirty VFX Graph during the Play mode throws "The referenced script (Unknown) on this Behaviour is missing!" warnings
- VFX Graph Debug Info overlaps the "Initialize" block debug info by default
Resolution Note:
By default, Unity will resize the canvas resolution to match the style resolution, along with the devicePixelRatio to scale the resolution for HDPI screens. This is because the canvas attributes control the WebGL resolution in the browser, and Unity matches the resolution to how it's displayed. For example if you switch to full screen, the resolution will be automatically adjusted to that new size. You can turn off this behavior with `config.matchWebGLToCanvasSize = false;` in the template html, which will give you independent control of the style and canvas resolution.
Resolution Note (2023.1.X):
By default, Unity will resize the canvas resolution to match the style resolution, along with the devicePixelRatio to scale the resolution for HDPI screens. This is because the canvas attributes control the WebGL resolution in the browser, and Unity matches the resolution to how it's displayed. For example if you switch to full screen, the resolution will be automatically adjusted to that new size. You can turn off this behavior with `config.matchWebGLToCanvasSize = false;` in the template html, which will give you independent control of the style and canvas resolution.