Search Issue Tracker
By Design
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
- Shader Graph Asset icon is not shown on creation unless you confirm the name
- APV Sky occlusion doesn't consider the terrain
- [iOS] "EXC_BAD_ACCESS" Player crash when Script Debugging is enabled
- Cursor skips input fields when tabbing between two sets of input fields
- "Shader error redefinition of 'Varyings'" error appears when selecting the shader
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.