avoid stack overflow error when taking screenshot throws exception