Fix ReferenceError issue when window is not defined