unbreak server-side/web worker

We're now trying to access document directly at require time. Wrapping in a function prevented that before. But we can simply check what environment we're in first.