I have just cherry-picked https://github.com/hypothesis/h/pull/527/files#r5394067 and https://github.com/hypothesis/h/pull/527/files#r5394067 from the develop branch. Please discuss it there.