Add better node/window/document detection, addEventListener