I'm not an engineer, but it sounds like inspectors are windows, too.
You probably want to do something along the lines of
"first window whose document is true"
to make this work.
You probably want to do something along the lines of
"first window whose document is true"
to make this work.