Get most recent window **not** of windowType

Doing Services.wm.getMostRecentWindow with the first argument being a windowType, will give you the most recent window of that type.

However I want to get the most recent window NOT of a given windowType alert:alert which is the notification thingy:

Is there anyway to do this?

I saw the Services.wm.getZOrderDOMWindowEnumerator but there is a warning on MDN saying this may not work on all Linux/Mac systems.

I also could not use Services.wm.getEnumerator and check a timestamp each window was focused as there doesn’t seem to be a property or a DOM attribute for this.

Any ideas?

On some systems you wouldn’t even have to worry about this, especially Mac and some Linux desktop environments. But the mix between native and non-native notifications really is a bummer for devs.

1 Like

Ooh thanks for that point. I didn’t realize that on Mac it wouldn’t be an issue. Sweet.

Get therm all, test the windowType attribute.

Thanks litho is there a time attribute though on the window? To detect most recent?

I don’t think you can access the window timestamp from javascript. However “most recent” effectively means first in z-order, and you can get an enumerator in z-order. Iterate through from front to back, until you find a window you like, and that is your most recent.

1 Like

Thanks @Litho this is awesome! I missed that zorder method!