Add a regression test to ensure capture completes the document.

- Fix a bug in the `restore` method.
- Make the `scriptsCorrectOrder` test behave nicely with other listeners