UNPKG

playwright-fluent

Version:
35 lines (34 loc) 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isHandleNotVisibleInViewport = void 0; const utils_1 = require("../../../utils"); const get_intersection_ratio_of_handle_1 = require("../get-intersection-ratio-of-handle"); async function isHandleNotVisibleInViewport(selector, options) { if (selector === undefined || selector === null) { return true; } const visibleRatio = await (0, get_intersection_ratio_of_handle_1.getIntersectionRatioOfHandle)(selector); (0, utils_1.report)(`visible ratio is ${visibleRatio}`, options.verbose); if (visibleRatio <= 0) { (0, utils_1.report)(`selector is not visible in the current viewport`, options.verbose); return true; } try { const isTransparentOrHidden = await selector.evaluate((el) => { const style = window.getComputedStyle(el); if (style && style.opacity && style.opacity === '0') { return true; } if (style && style.visibility === 'hidden') { return true; } return false; }); return isTransparentOrHidden; } catch (error) { // Element has been removed from DOM while or just before selector.evaluate execution return true; } } exports.isHandleNotVisibleInViewport = isHandleNotVisibleInViewport;