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

99
Views
Custom window object property with reference to original

I am trying to develop an extension in Chrome that will allow me to intercept access to the window object. Lets say I want to return double window.innerHeight, I tried setting it as follows:

Object.defineProperty(window, 'innerHeight', {
  get : () => window.innerHeight * 2,
});

But this obviously leads into infinite recursion. How can I redefine a window property while maintaining a reference to the original property? Doing something like let windowOld = Object.assign({}, window); will just capture the window properties at that static moment, and not actually maintain a reference to the original properties.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Usually, in this situation, you'd just save the existing property in a variable first - but a complication is that window.innerHeight is a getter/setter, not a standard property. So, save the existing getter/setter, then define the property again (as a getter/setter, again, to maintain consistency).

const { get, set } = Object.getOwnPropertyDescriptor(window, 'innerHeight');
Object.defineProperty(
  window,
  'innerHeight',
  {
    get: () => get.call(window) * 2,
    set: (newVal) => set.call(window, newVal),
  }
);
about 4 years ago · Juan Pablo Isaza Report
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!