refactored the visibility API function and the new XMLHttpRequest method