Search code examples
google-chrome-devtools

Show viewport width when resizing window in Chrome developer tools?


I use Chrome with developer tools docked to the right hand side of the window. Chrome used to show the viewport dimensions at the top right of the window, when you resize the viewport by dragging the central divider. I've always found it useful for testing responsive sites and media queries.

Since a recent update, this has disappeared. Is there a way to switch it back on?

I'm using the latest version (Version 49.0.2623.87) on Mac.


Solution

  • As mentioned it's a bug. For the time being a cheap workaround I've been using is put this into your console:

    window.addEventListener('resize', function(event){
      console.log(window.innerWidth);
    });
    

    Now just watch the console when you resize. It does the trick for basic width checking.

    Here's a version that imitates the old resizer:

    var b = document.createElement('div');
    var bS = b.style;
    bS.position = 'fixed';
    bS.top = 0;
    bS.right = 0;
    bS.background = '#fff';
    bS.padding = '5px';
    bS.zIndex = 100000;
    bS.display = 'block';
    bS.fontSize = '12px';
    bS.fontFamily = 'sans-serif';
    b.innerText = window.innerWidth + 'x' + window.innerHeight;
    b.addEventListener("click", function(){bS.display = 'none';}, false);
    document.body.appendChild(b);
    window.addEventListener('resize', function(event){
      bS.display = 'block';
      b.innerText = window.innerWidth + 'x' + window.innerHeight;
    });