What's the best way to detect a user playing on PC or Mobile?

There’s a lot of conflicting answers but one that I’m more drawn to is the canvas / device size. Any suggestions?

Cross-browser @media (width) and @media (height) values

var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);

There are really a lot of opinions but this seems quite accurate across different browsers and platforms. See hot discussion in details - Get the browser viewport dimensions with JavaScript - Stack Overflow