Remove event listeners before and restore after injecting code