When taking screenshot check window.document.body dimensions only if it is
not null. Fixes issue 5130