0

I'm not sure if this is allowed, but here goes. I have a free account on chess.com, so whenever I want more puzzles, I have to watch ads. The ads pause every time I switch to a different window. The real question I'm asking is how can I make it so it doesn't pause when I switch? I thought it would be simple.

I went into the console and did window.onblur = function(){} and document.body.onblur = function(){} but nothing changed.

Sorry, and thanks in advance.

  • 1
    if they use `addEventListener` to handle the blur event, assigning to `window.onblur` has no impact. – Barmar Feb 02 '23 at 22:31
  • 1
    Why do you care what the ads are doing when you're not using that window? – Barmar Feb 02 '23 at 22:31
  • Because when he switched away the site detects it and pauses, effectively forcing him to watch them in full. – adsy Feb 03 '23 at 00:23

1 Answers1

0

You would probably only be able to do this in a scenario where the nullifying code runs before the site code. In other words, the code would probably need to be running inside a browser extension, and not in the browser console.

Probably it uses addEventListener. In a browser extension scenario you could run this to nullify the event listener. Crucially, extensions allow code to execute before the main site code, which would be needed here because you need to nerf addEventListener before the site attempts to execute it:

let oldAddEventListener = window.addEventListener
window.addEventListener = (...args) => {
    if (args[0] === 'blur') return
    oldAddEventListener(...args)
}

If it uses addEventListener (it probably does), then it might seem obvious to attempt to call removeEventListener as theoretically you could then do it in a normal browser console after it was registered. But that's difficult because you need the handler to remove it, and you won't have it in scope. So that prevents you from doing it after the fact it was registered.

Is there a way around this? Possibly. You could probably use window.fetch to get the page contents, modify it with the code, and pull it back into the DOM all over again. But that's extraordinarily involved and smells of "wrong tool for the job".

To be honest you could probably use cheap OS-level tricks to keep the window in top and in focus as you go about your business elsewhere.

I briefly also considered registering a new blur event on the window with capture set to true, but apparently this doesn't work on window events :(.

You probably don't want the burden of building your whole own extension but in chrome you could use TamperMonkey with a script. See this.

adsy
  • 8,531
  • 2
  • 20
  • 31