I came across the need to do this when trying to intercept the native fetch
api.
In addition to @ChrisHamilton's answer, since for me window had to be at a global scope, I ended up putting this check as well:
if (typeof window !== 'undefined') {
const { fetch } = window;
originalFetch = fetch;
}