Refactor take_screenshot_viewport