Just check `if (typeof alert !== 'undefined') {` ?