Re-instrument HTML after document changed

Fix for #3652

Adds a document `change` listener to scanned documents. The cached values are cleared when the document changes.

Adds unit test to verify functionality.