Detect window safely