playwright-fluent
Version:
Fluent API around playwright
28 lines (27 loc) • 1.13 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getWindowState = void 0;
async function getWindowState(page) {
if (page) {
const windowStateSerialized = await page.evaluate(() => {
const result = {
innerHeight: window.innerHeight,
innerWidth: window.innerWidth,
outerWidth: window.outerWidth,
outerHeight: window.outerHeight,
screen: {
availWidth: window.screen.availWidth,
availHeight: window.screen.availHeight,
},
isMaximized: Math.abs(window.outerWidth - window.screen.availWidth) <
window.screen.availWidth * 0.03 &&
Math.abs(window.outerHeight - window.screen.availHeight) < 100,
};
return JSON.stringify(result);
});
const windowState = JSON.parse(windowStateSerialized);
return windowState;
}
throw new Error('Cannot get window state because no browser has been launched');
}
exports.getWindowState = getWindowState;
;