calculateHtmlDocDimensions property
String
calculateHtmlDocDimensions
getter/setter pair
Implementation
static String calculateHtmlDocDimensions = '''
(function() {
try {
const body = document.body;
const html = document.documentElement;
// Remove scrolling and set proper styles for both platforms
html.style.margin = '0';
html.style.padding = '0';
html.style.overflow = 'hidden';
html.style.height = '100%';
body.style.margin = '0';
body.style.padding = '0';
body.style.overflow = 'hidden';
body.style.height = '100%';
// Ensure all images are loaded
const imgs = document.images;
for (let i = 0; i < imgs.length; i++) {
if (!imgs[i].complete) return -1;
}
// Compute dimensions
let height = Math.max(
body.scrollHeight, body.offsetHeight,
html.clientHeight, html.scrollHeight, html.offsetHeight
);
let width = Math.max(
body.scrollWidth, body.offsetWidth,
html.clientWidth, html.scrollWidth, html.offsetWidth
);
return JSON.stringify({
height: height.toString(),
width: width.toString()
});
} catch (e) {
return JSON.stringify({ height: "400", width: "400" });
}
})();
''';