- In each browser, I get a JSON-stringified array of every property name on
window
except itself. I place these names into files like name.chrome.json
or name.firefox.json
.
<!doctype html>
<body>
<script>
(function () {
const windowNames = Object.getOwnPropertyNames(window).filter(name => name !== 'window');
const textarea = document.createElement('textarea');
textarea.value = JSON.stringify(windowNames);
document.body.appendChild(textarea);
textarea.focus();
textarea.select();
})();
</script>
- In Node, I import and combine all of these names, only removing those names which also appear in Node’s
global
.
const nodeNames = Object.getOwnPropertyNames(global);
const names = [
...new Set(
[].concat(
require('./names.chrome'),
require('./names.firefox'),
require('./names.safari')
)
)
].filter(
name => !nodeNames.includes(name)
).sort();
- In Node, I write these combined names as a default export to
browserGlobals.js
.
require('fs').writeFileSync(
'browserGlobals.js',
`export default ${JSON.stringify(names, null, '\t').replace(/"/g, `'`)};\n`
);