Improve screenshot.js: close page and release memory before exit