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

326
Visualizações
Is it possible to stop javascript from knowing if window/document has focus?

Some websites stop working (for example, playing music) if one moves from one tab to another. Question: Is it possible for the client to stop this behaviour?

There are multiple ways to check if the current browser tab is focused. One can use document.hasFocus() or window.addEventListener('focus', function), for example. The visibilitychange or blur events aren't cancelable, so Event.stopPropagation wouldn't work. But is there any other way to stop their propagation? (For example, could an addon break the way the blur event works and not make it dispatch?)

Or is there a way to simulate a tab having focus via the JS console? For example, by toggling a checkbox in the Web Console or by constantly retriggering a focus event after the tab loses focus? (Or maybe could tampermonkey force set the read-only document.visibilityState always to visible?)


Regarding the question being closed: This question is not the same as Is there a way to detect if a browser window is not currently active?, it's asking from the opposite direction: that question asks how can one detect changes in focus, this one asks how can one avoid that detection

about 4 years ago · Juan Pablo Isaza
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