Detect window focus on desktop effect in javascript

Hi, I’m working on a desktop effect. I want to execute some code when windows gain or lose focus.

I found this code on the internet, but in the kwin logs I am told that connect cannot be applied on undefined.

effects.onWindowFocusChanged.connect(function(window, hasFocus) {
      if (hasFocus) {
        console.log("Window", window, "has gained focus");
      } else {
        console.log("Window", window, "has lost focus");

I have found another signal like windowClosed and windowAdded into the other effect but nothing about the focus.

I usually do it in qml but since the one I duplicated was written in js I did the same thing, and I have the impression that there is no documentation for it (

Since I don’t find the documentation about the effects object, it is possible to have a link for it or a hint about a possible solution ?

Thanks !