|
| 1 | +--- |
| 2 | +"@wdio/image-comparison-core": patch |
| 3 | +"@wdio/visual-service": patch |
| 4 | +--- |
| 5 | + |
| 6 | +## #1146 Fix BiDi element screenshots missing composited layers (scrollbars, fixed/sticky overlays) |
| 7 | + |
| 8 | +### Root cause |
| 9 | + |
| 10 | +When `checkElement` / `saveElement` is used with the WebDriver BiDi protocol, the screenshot was taken with `browsingContext.captureScreenshot` using `origin: 'document'`. This renders the document layout independently of the browser's compositor, which means **composited layers are never included** — element-level scrollbars, `position: fixed` / `position: sticky` overlays, and elements with a `will-change` CSS property all render as invisible or without their correct visual state. |
| 11 | + |
| 12 | +The switch to `origin: 'document'` was introduced in an earlier fix (commit `227f10a`) to avoid a `zero dimensions` error that occurred when `origin: 'viewport'` was used for elements that were outside the visible viewport. That fix was correct for out-of-viewport elements, but it also silently broke composited-layer capture for all elements. |
| 13 | + |
| 14 | +### Fix: new `biDiOrigin` method option |
| 15 | + |
| 16 | +A new **method-level** option `biDiOrigin` has been added to `saveElement` / `checkElement`. It is BiDi-only and ignored for the legacy WebDriver screenshot path. |
| 17 | + |
| 18 | +| Value | Behaviour | |
| 19 | +|---|---| |
| 20 | +| `'document'` *(default)* | Previous behaviour — works for any element position but composited layers (scrollbars, overlays, `will-change`) are not captured | |
| 21 | +| `'viewport'` | Captures the composited frame as the browser painted it — scrollbars, fixed/sticky overlays and `will-change` layers are included. The element must be visible in the viewport; descriptive errors are thrown when it is not | |
| 22 | + |
| 23 | +#### Usage |
| 24 | + |
| 25 | +```ts |
| 26 | +// Capture an element with its scrollbar / overlay visible: |
| 27 | +await browser.checkElement(element, 'myTag', { biDiOrigin: 'viewport' }) |
| 28 | +await browser.saveElement(element, 'myTag', { biDiOrigin: 'viewport' }) |
| 29 | +``` |
| 30 | + |
| 31 | +#### Error messages when `biDiOrigin: 'viewport'` cannot produce a valid screenshot |
| 32 | + |
| 33 | +**Element larger than the viewport** — must fall back to `'document'`: |
| 34 | +``` |
| 35 | +[BiDi viewport screenshot] The element dimensions (1400x800px) exceed the viewport (1280x720px). |
| 36 | +You must use the default `biDiOrigin: 'document'` for this element. |
| 37 | +Note: with `'document'` origin, composited layers such as scrollbars, fixed/sticky overlays, |
| 38 | +and elements using `will-change` may not appear in the screenshot. |
| 39 | +``` |
| 40 | + |
| 41 | +**Element not in the viewport at all** — needs scrolling: |
| 42 | +``` |
| 43 | +[BiDi viewport screenshot] The element is not in the viewport |
| 44 | +(element: x=0, y=900, 300x200px; viewport: 1280x720px). |
| 45 | +Call `element.scrollIntoView()` before taking the screenshot, or set `autoElementScroll: true`. |
| 46 | +``` |
| 47 | + |
| 48 | +**Element partially outside the viewport but fits** — needs to be scrolled fully into view: |
| 49 | +``` |
| 50 | +[BiDi viewport screenshot] The element is not fully visible in the viewport |
| 51 | +(element: x=-20, y=100, 300x200px; viewport: 1280x720px). |
| 52 | +The element fits within the viewport — scroll it fully into view by calling |
| 53 | +`element.scrollIntoView()` or setting `autoElementScroll: true`. |
| 54 | +``` |
| 55 | + |
| 56 | +### Committers: 1 |
| 57 | + |
| 58 | +- Wim Selles ([@wswebcreation](https://github.com/wswebcreation)) |
0 commit comments