puppeteer-extra-plugin-recaptcha: _isInViewport drops the right-edge bound
Description
In puppeteer-extra-plugin-recaptcha, _isInViewport (packages/puppeteer-extra-plugin-recaptcha/src/content.ts) should check all four viewport bounds, but a misplaced parenthesis nests the right-edge check inside the bottom comparison:
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <=
(window.innerHeight ||
(document.documentElement.clientHeight &&
rect.right <=
(window.innerWidth || document.documentElement.clientWidth)))window.innerHeight is truthy in a real browser, so the || short-circuits to innerHeight and rect.right <= innerWidth is never evaluated. The horizontal bound is dropped, so an element overflowing the right edge is reported as in-viewport.
isInViewport feeds the solveInViewportOnly filter (src/index.ts:105-112), so with that option enabled a checkbox reCAPTCHA positioned past the right edge is solved instead of skipped.
Steps to Reproduce
function buggy(r, w) { return r.top>=0 && r.left>=0 && r.bottom <= (w.innerHeight || (w.clientHeight && r.right <= (w.innerWidth || w.clientWidth))); }
function fixed(r, w) { return r.top>=0 && r.left>=0 && r.bottom <= (w.innerHeight || w.clientHeight) && r.right <= (w.innerWidth || w.clientWidth); }
const vp = { innerHeight:800, innerWidth:1280, clientHeight:800, clientWidth:1280 };
const offRight = { top:10, left:10, bottom:200, right:2000 };
console.log(buggy(offRight, vp), fixed(offRight, vp)); // true falseThe off-right-edge element is reported true by the current code; it should be false.
Expected Behavior
An element extending past the right edge of the viewport is not reported as in-viewport.
Fix
Restore the standard four-bound check (top >= 0, left >= 0, bottom <= innerHeight, right <= innerWidth).
Environment
- package:
puppeteer-extra-plugin-recaptcha - branch:
master
Source: berstend/puppeteer-extra