While as ridiculous as it sounds, there isn't a certain way to know the platform for sure, but I propose at least this better heuristic, using window instead. The likelihood of a Node project to have a window global variable seems to be super low.
Additional ways to detect platforms involve: self and global.
At https://github.com/ethereumjs/ethereumjs-vm/pull/785#issuecomment-670268717, we found that
exports
shouldn't guide the browser/node detection. It is usually present in browser builds made with Browserify, invalidating that clause.While as ridiculous as it sounds, there isn't a certain way to know the platform for sure, but I propose at least this better heuristic, using
window
instead. The likelihood of a Node project to have awindow
global variable seems to be super low.Additional ways to detect platforms involve:
self
andglobal
.More on this: https://v8.dev/features/globalthis.