MarketSquare / MarketSquare/robotframework-browser

Add `style=` argument to `Take Screenshot` to apply CSS during capture

Open
#5,114 0 comments 0 reactions 1 assignee View on GitHub

@Snooz82 is already working on this.

Since Aug 6, 2026.

enhancement
Dominant language
Python
Stars
655
Forks
147
Avg merge
5h 27m
Merged PRs (30d)
59

Description

## Use case

Screenshots of real pages are polluted by volatile content: blinking carets, animated spinners, ads, timestamps, avatars. `Take Screenshot` already offers `mask=` for rectangular pink overlays and `disableAnimations=`, but many stabilization needs are not rectangular masking: hiding an element entirely (so layout ignores it), forcing a fixed font, neutralizing box-shadows, or making a dynamic region transparent. Today the only workaround is injecting a style tag before the screenshot and removing it afterwards — extra keywords, and it mutates the page under test.

Playwright's screenshot `style` option applies a stylesheet only *while the screenshot is taken*: the page is untouched before and after. This is the standard tool for producing stable images, especially as groundwork for the planned visual-regression keyword.

## Proposed keyword / arguments

New named-only argument on the existing keyword:

```
Take Screenshot ... style=None
```

- `style` — CSS text applied while making the screenshot. Elements matching `visibility: hidden` collapse from view; `display: none` removes them from layout. Works for both page and element (`selector=`) screenshots.

```robotframework
Take Screenshot baseline selector=id=dashboard
... style=.ad-banner, .live-ticker { visibility: hidden !important; }

# Combine with existing stabilizers
Take Screenshot fullPage=True disableAnimations=True
... style=* { caret-color: transparent !important; }
```

## Playwright API

- [page.screenshot `style` option](https://playwright.dev/docs/api/class-page#page-screenshot-option-style) (also on [locator.screenshot](https://playwright.dev/docs/api/class-locator#locator-screenshot-option-style)), available since Playwright 1.41.

## Implementation notes

- `protobuf/playwright.proto`: one new optional string field on the existing screenshot options message.
- `node/playwright-wrapper`: pass `style` through to the `page.screenshot`/`locator.screenshot` call in the existing screenshot handler.
- Python: new named-only parameter in `take_screenshot` (`Browser/keywords/browser_control.py`), forwarded via `_create_screenshot_options`; docs table entry; stub regen; atest asserting a styled element is absent from the captured image.

## Backwards compatibility

Additive named-only argument with default `None` (no stylesheet applied), preserving current behavior exactly.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.