UNPKG

playwright-fluent

Version:
27 lines (26 loc) 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getIntersectionRatioOfHandle = void 0; async function getIntersectionRatioOfHandle(selector) { if (!selector) { return -1; } // this code was taken from Playwright visibleRatio() // that has been been removed from src/dom.ts:482 (version 0.11.1) const result = await selector.evaluate(async (el) => { const visibleRatio = await new Promise((resolve) => { const observer = new IntersectionObserver((entries) => { resolve(entries[0].intersectionRatio); observer.disconnect(); }); observer.observe(el); // Firefox doesn't call IntersectionObserver callback unless // there are rafs. // eslint-disable-next-line @typescript-eslint/no-empty-function requestAnimationFrame(() => { }); }); return visibleRatio; }); return result; } exports.getIntersectionRatioOfHandle = getIntersectionRatioOfHandle;