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

325
Views
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
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!