UNPKG

playwright-fluent

Version:
37 lines (36 loc) 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isHandleVisibleInViewport = void 0; const utils_1 = require("../../../utils"); const get_intersection_ratio_of_handle_1 = require("../get-intersection-ratio-of-handle"); async function isHandleVisibleInViewport(selector, options) { if (selector === undefined || selector === null) { return false; } 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 false; } try { const result = await selector.evaluate((el) => { function hasVisibleBoundingBox(element) { const rect = element.getBoundingClientRect(); return !!(rect.top || rect.bottom || rect.width || rect.height); } const style = window.getComputedStyle(el); if (style && style.opacity && style.opacity === '0') { return false; } const isVisible = style && style.visibility !== 'hidden' && hasVisibleBoundingBox(el); return isVisible; }); return result; } catch (error) { // Element has been removed from DOM while or just before selector.evaluate execution return false; } } exports.isHandleVisibleInViewport = isHandleVisibleInViewport;