Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getElementRect = async (selector: string) => {
const rects = (await this.browser.execute(getBoundingRect, selector)) as
| DOMRect
| DOMRect[]
| null;
if (!rects) {
throw new ElementNotFoundError(selector);
}
if (Array.isArray(rects)) {
return rects.map(rect => {
if (
rect.x === 0 &&
rect.y === 0 &&
rect.width === 0 &&
rect.height === 0
) {
throw new ElementNotVisibleError(selector);
}
return {
x: rect.x,
y: rect.y,
getElementRect = async (selector: string) => {
const elements = await this.page.$$(selector);
if (!elements.length) {
throw new ElementNotFoundError(selector);
}
const rects = await Promise.all(
elements.map(async element => {
const rect = await element.boundingBox();
if (!rect) {
throw new ElementNotVisibleError(selector);
}
return rect;
})
);
return rects.length === 1 ? rects[0] : rects;
};