Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

100
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda