darkreader / darkreader/darkreader

[Bug] Broken background-image when URL is set via CSS variable

Open
#12,790 1 comment 1 reaction 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
22.4k
Forks
2.7k
Avg merge
21h 11m
Merged PRs (30d)
78

Description

### Prerequisites

- [X] I [searched for any existing report](https://github.com/darkreader/darkreader/issues?q=is%3Aissue) about this bug to avoid opening a duplicate.
- [X] I can reproduce this bug in a new, unmodified web browser profile with Dark Reader installed as the only extension.
- [X] I understand I need to use the [Broken Website Report template](https://github.com/darkreader/darkreader/issues/new?assignees=&labels=Broken+Website&template=broken-website-report.yml&title=%5BBroken+Website%5D+Replace+with+title) if this bug I am reporting occurs on a single website.

### Bug Description

When the URL for a background image is stored in a CSS variable, the name of the CSS variable is mangled (`--varname` -> `--darkreader-bgimg--varname`) when Dark Reader is active, removing the background image.

It looks like when the CSS variable is set in the same CSS file, it is mangled in the same way, resulting in functional output. When the variable is not set in the same CSS file*, the source is not mangled, resulting in a broken (non-rendering) image.

* Tested setting the var via `style` attr, and by setting it in JS.

### Website Address

https://jsfiddle.net/t0r2yh7e/

### Steps To Reproduce

```html


Darkreader img var test

.image {
height: 200px;
width: 200px;
background-image: var(--image-url);
}






document.querySelector(".image.js").style.setProperty("--image-url", "url(https://picsum.photos/200)");

```

### Expected Behavior

The background-image should display the image from the corresponding CSS variable.

### Actual Behavior

Dark Reader modifies the image's CSS to request a different, non-existent CSS variable, which breaks the image.

### Screenshots

_No response_

### Operating System

Linux

### Web Browser name and version

Firefox 125.0.2

### Dark Reader version

Version 5 Preview (4.9.85)

### Additional Context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.