Turns out this doesn't work in services , which was my requirement. My decision did it "the old way":
@Injectable() export class WindowService { constructor(){ window.addEventListener('focus', event => { console.log(event); }); window.addEventListener('blur', event => { console.log(event); }); } }
Not sure if I did this in the “right” way, but it works on Chrome. What I'm not sure of is whether I should destroy the event listener or not, and whether it works in other browsers. Let me know if I accidentally shoot myself in the foot here. Updates the answer, if so, or removes it, if necessary.
source share