Check for existence of "document" and "navigator" before referencing them

* Allows requiring the module in an environment without a DOM. Thus permitting to late inject a `document`.