diff --git a/packages/dom/src/index.js b/packages/dom/src/index.js index f034a9832..c1bd918e7 100644 --- a/packages/dom/src/index.js +++ b/packages/dom/src/index.js @@ -1,14 +1,9 @@ import serialize from './serialize-dom'; /* istanbul ignore next */ -// works around instances where the context has an incorrect global scope -// https://github.com/mozilla/geckodriver/issues/1798 -try { - if (globalThis !== window) { - window.PercyDOM = { serialize }; - } -} catch (error) { - // `globalThis` is probably not defined +// works around instances where the context has an incorrect scope +if (typeof window !== 'undefined') { + window.PercyDOM = exports; } export { serialize }; diff --git a/rollup.config.js b/rollup.config.js index d0ffe75c1..a26e72942 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -45,8 +45,7 @@ const base = { ...pkg.rollup.output, intro: [ // provide the bundle with a fake process.env if needed - 'let process = {};', - 'try { process = globalThis.process || {}; } catch (e) {}', + 'const process = (typeof globalThis !== "undefined" && globalThis.process) || {};', 'process.env = process.env || {};', // signals that the package is running in a browserified bundle 'process.env.__PERCY_BROWSERIFIED__ = true;'