Speaking of flogging a dead thread, a friend of mine and I ran into some interesting issues concerning the Iframe size issue.
Seems that there are multiple ways of scaling content on a browser, not just Chrome’s “hold Ctrl and scroll” to zoom. There’s also a dedicated scaling option in Windows 10, which you can find via pressing “Windows + I”, then navigate to system and display. Under display, you’ve got “Scale and layout”. The recommended default is 100%, i.e. no scaling, but the very next option is 125%. There are also advanced scaling settings there, etc.
Anyway, I built and setup develephant’s HTML5 demo project to https://xedur.com/demos/windowSizeDemo/. On my friend’s screen, the size dimensions were 1200x800, but the app itself said 960x640 as they should have been. So, I also set the scaling to 125% in Windows’ display settings and the results were identical.
So, the reason why @mr.badim also had the 1200x800 was because he somewhere has/had 125% scaling set up, either in his browser or the OS. If you load the demo project that I linked and it still appears to have a width of 1200 pixels on the screen, but it reads innerWidth: 960, then that’s due to browser or OS scaling.
Now, I checked out a few Unity HTML5 games, like https://smilodon.itch.io/angrymountaingods, to see if Unity handles things differently and the answer is no. When you apply browser or OS level scaling, then the games will get blurry.
To make things more chaotic, it seems that there’s no easy way to address this issue. There are projects like https://github.com/tombigel/detect-zoom, but its readme file and stack overflow answers on the subject suggest that identifying browser zoom is very difficult if not downright impossible for all browsers, Chrome seems to be particularly tough one. Now add OS scaling on top of that and I’m not sure if there’s any way to even remotely get that information for an HTML5 app.
So, what you can do is to:
-
use Iframe to constrain the app’s dimensions to what you have set up in config.lua. This will make your HTML5 app look good as long as no zoom/scaling is applied, and
-
let your user know that if they zoom in using the browser or if they are using scaling in their OS, that the game will appear blurry, and that if they want to experience the game like you’ve intended, then they should undo the zoom/scaling and reload the page.