Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
How to get CSSStyleDeclaration.backgroundImage set descriptor

I'm trying to override the setters of some style properties in javascript.

Here's an example of what I'm doing.

const setDescriptor = Object.getOwnPropertyDescriptor(CSSStyleDeclaration.prototype, 'backgroundImage').set;
Object.defineProperty(CSSStyleDeclaration.prototype, 'backgroundImage', {
    set: function (value) {
        const newValue = // Some sort of mutation to value

        setDescriptor.call(this, newValue);
    },
});

When trying to run this inside my browser I'm getting the following error:

Uncaught TypeError: Cannot read properties of undefined (reading 'set')

I know that the interface does not have any reference to styling properties.
However, when accessing an instance of CSSStyleDeclaration from CSSStyleRule.style the properties do exist.

When is that instance populated? How can I override the setters of the properties for all new and old instances?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!