Chrome Developer Tools - Browser Size? - google-chrome

I'm using Chrome Developer Tools and trying to get the browser width in px
Google recently rolled out updates for their Developer Tools, before these updates the screen height & width used to appear in the top right of the website preview when scaling the developer tools, but now there's no way to find out the screen size (example below)?
How can I find out the browser size via Chrome dev tools now?

I came across this trying to figure this out and couldn't find device mode as per Danamorah's answer. So I thought I would help save some time for a newbie and screen shot the icon to click so you can get measurements.
First, open dev tools, and then the top left corner you should see an icon shaped as a small tablet and phone. Click that and you can adjust measurements with the pixel count:

They change the way to show this tool, you can find it pressing in device mode

It's a bug: https://bugs.chromium.org/p/chromium/issues/detail?id=582421
Google Chrome beta branch has this bug fixed already and the fix is expected to be added to the next stable release (version 50).
As a temporary workaround, you can use this bookmarklet:
javascript: (function() {
var v = window,
d = document;
v.onresize = function() {
var w = v.innerWidth ? v.innerWidth : d.documentElement.clientWidth,
h = v.innerHeight ? v.innerHeight : d.documentElement.clientHeight,
s = d.getElementById('WSzPlgIn'),
ss;
if (!s) {
s = d.createElement('div');
s.id = 'WSzPlgIn';
d.body.appendChild(s);
s.onclick = function() {
s.parentNode.removeChild(s)
};
ss = s.style;
ss.position = 'fixed';
ss.top = 0;
ss.right = 0;
ss.backgroundColor = 'black';
ss.opacity = '1';
ss.color = 'white';
ss.fontFamily = 'monospace';
ss.fontSize = '10pt';
ss.padding = '5px';
ss.textAlign = 'right';
ss.zIndex = '999999';
}
s.innerHTML = 'w ' + w + '<br />h ' + h;
};
})();

It's not the same, and not as convenient as it used to be. But you can turn on a ruler under developer tools settings (General tab, Elements section, check "show rulers").
Then when you select an element (body or html) you can get the size of the element with a ruler on the x and y of the browser. This will not be the same as your browser window though if your content is wider than the browser.
It's inconvenient because it doesn't show you the size of the browser as you are resizing like it used to. Hopefully the original feature comes back.
*Also found that if you Toggle Device Mode on, and select Responsive in the drop down, you can resize the browser area and see real-time screen sizes.

Related

How can I make it so Edit2D lines do not resize when viewer is zoomed in and out?

Long story short: I want to set Edit2D polyline tool's line width to 6" based on calibration sizing and have it stay that size in the viewer no matter the camera zoom.
I'm using the edit2d library to allow drawing. I need to be able to set the line width for the polyline tool and have it stay at that width similar to how markups stay a set size when drawn. The default functionality of the edit2d polyline tool is for the line to be resized on camera changes and so it grows and shrinks depending on zoom.
I tried setting edit2DTools.polylineTool.style.isScreenSpace = false; which works, however, trying to set the specific size is difficult as it ends up being a decimal less then 1 and I can't find a correlation from the calibration, page size, etc. to allow me to dynamically set the size the same on different models.
I also found this in the Edit2D Snapper's code, but I can't figure out what's happening here to replicate it on the polyline tool. It seems to be doing what I want to do.
Any help or ideas at all would be greatly appreciated!
This code seems to be working for me:
async function setLineWidth(viewer) {
let mt = await viewer.loadExtension("Autodesk.Measure");
if (!mt.sharedMeasureConfig.calibrationFactor) {
console.log("Has not been calibrated yet");
return;
}
let edit2d = viewer.getExtension('Autodesk.Edit2D');
let pt1 = {x:0, y:0, z:0}, pt2 = {x:6, y:0, z:0};
viewer.model.pageToModel(pt1, pt2, 0 /*viewport id*/, true /*reverse*/);
let style = edit2d.defaultTools.polylineTool.style;
style.lineWidth = (pt2.x - pt1.x) / mt.calibration.scaleFactor;
}
Here is a video showing it in action: https://youtu.be/DIaKugvQdm4
As you can see first the lineWidth of the polylineTool is not what you want, but after setting what 6" should be in the drawing, I can set it to the same width and all is fine.
Here is a zip file with the html including the JavaScript code and the test PDFs I used: https://github.com/adamenagy/Container/blob/master/Edit2dTest.zip

How to keep size of a DIV independent of window resizing AND zooming?

I am trying to keep the physical size of a DIV constant, even when the user zooms in/out, or resizes the browser window.
Here's my latest attempt:
<center>Hello world</center>
<div style="text-align:left;background-color:#474747;
line-height:1.4;color:#a7a7a7;font-size:2vh;width:60vh;height:30vh;
bottom:0px;right:0px;margin:2vh;position:fixed;padding:1vh;">FixedDIV</div>
https://codepen.io/hexatomium/full/MWwNpzB
This almost fills my objective, except when vertically resizing the window.
Thanks for any ideas.
Note: Ideally I would like to make this work in Chrome and IE11.
You can try the Visual Viewport API.
This will take one step further.
const update = (event) => {
document.getElementById("size").style.width = window.visualViewport.width / 10 + 'px';
document.getElementById("size").style.height = window.visualViewport.height / 10 + 'px';
document.getElementById("size").innerHTML = window.visualViewport.width + 'px';
}
visualViewport.addEventListener('scroll', update);
visualViewport.addEventListener('resize', update);
addEventListener('scroll', update);
https://codepen.io/AvremiFriedman/pen/abOejZJ
It dont work good enough on code.
Try it on yor computer. You will get better results.

Use CSS to maintain height of web app = innerHeight

I'm building a responsive web app and want to guarantee that nothing is unintentionally hidden by the address bar or navigation bar in iOS Safari and other mobile browsers.
I'm currently using this code:
window.onresize = function (event) {
toastr.warning("resized");
var h = window.innerHeight;
document.getElementById("applicationHost").style.height = h + 'px';
};
But I was wondering if there's a CSS-only way to solve this problem.
Maybe "vh" units would help in this case, hard to tell without seeing code and doing some testing. Try adding height:100vh; to the element that needs to have the viewport height.

Chrome - Window Width / Height Not Appearing in Developer Mode?

I just noticed that the window height / width are no longer appearing on the top right hand corner of the web page when I enter developer mode.
Not sure if I accidentally turned it off or if an version upgrade removed this functionality.
How do I turn this back on? I am running version 49.0.2623.87.
The width and height at the top right hand corner of the window is gone. To get a similar view, you now have to click on the device icon on the top left hand corner of the developer console (below in red). Then on the screen that pops up, you need to select 'Responsive' on the device drop down tab on the top center of the screen (in blue).
Now you can see the width / height of the window and also resize it.
Looks like after sufficient requests, the developer tools team brought it back. In unstable/canary for now, soon in stable.
I created a plugin to help me when I'm not using the responsive feature in Chrome's dev tools as it does not resize when using the dev tools to the side. Here's the link to the plugin: https://chrome.google.com/webstore/detail/width-and-height-display/hhcddohiohbojnfdmfpbbhiaompeiemo?hl=en-US&gl=US
Alternatively, I took #Joefay and #Micah's (thanks!) answer from above and made a little visual in the upper right hand corner so you don't need to keep your console open after popping the code into the console. You will have to paste it in each time you open a new window or refresh your page however. Hope this helps.
var onresize = function() {
var width = window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth;
var height = window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;
var container = document.getElementById('heightAndWidth');
container.innerHTML = width + ' x ' + height;
};
(function addHAndWElement() {
var cssString = 'position:fixed;right:8px;top:8px;z-index:20000;background:rgba(0,0,0,0.6);color:#FFF;padding:4px;'
var htmlDoc = document.getElementsByTagName('body');
var newDiv = document.createElement('div');
var divIdName = 'heightAndWidth';
newDiv.setAttribute('id',divIdName);
newDiv.style.cssText = cssString;
htmlDoc[0].appendChild(newDiv);
onresize();
})();

How do I find out what's causing a page to temporarily render a horizontal scrollbar?

I'm looking at the following page:-
http://www.gearzap.com/
In Google's Chrome.
During page load, for some reason, a horizontal scrollbar appears for approximately half a second.
This is obviously something that's below the fold that's causing this, but I can't seem to find out what's causing the issue
EDIT:- Video of this happening here:-
http://files.sourceguru.net/scrollbars.ogv
I had a quick look (and man is there a lot of js on that page) and the navigation.js file jumped out at me. I set the debugger and found that after 8 iterations of this loop:
$j('#navigation .submenu').each(function() {
var obj = $j(this);
var cols, w, l, offset;
cols = obj.find('ul').length;
obj.css('width', (cols * 200 + 16) + 'px');
w = obj.outerWidth();
l = obj.offset().left;
offset = w + l;
if(offset > max_w) {
obj.animate({
'margin-left' : '-=' + (offset - max_w) + 'px'
});
}
});
the scrollbar appears.
EDIT: You may be able to just get away with turning that obj.animate into an obj.css. If that doesn't work you might need to do the calculations prior to setting the css at all, rather than setting it, doing the calculations and then changing it again. Not sure why that was ever an animate to begin with.
Actually it doesn't show for me. Not in Chrome nor firefox. Im using Chrome 12.0.742 for windows 7. I have checked over 10 times, but it never shows.
Maybe it has something to do with the version/settings of the browser used?