BuilderIO / partytown

Relocate resource intensive third-party scripts off of the main thread and into a web worker. 🎉
https://partytown.builder.io
MIT License
12.98k stars 429 forks source link

Uncaught TypeError: Cannot read properties of undefined (reading 'prototype') #38

Closed lizryzhko closed 2 years ago

lizryzhko commented 2 years ago

Hi. I just tried to use this library for the first time, got the error:

Uncaught TypeError: Cannot read properties of undefined (reading 'prototype')
    at partytown-sandbox-sw.js:304
    at Array.map (<anonymous>)
    at readMainPlatform (partytown-sandbox-sw.js:300)
    at accessRsp.$msgId$ (partytown-sandbox-sw.js:373)
    at Worker.worker.onmessage (partytown-sandbox-sw.js:422)
(anonymous) @ partytown-sandbox-sw.js:304
readMainPlatform @ partytown-sandbox-sw.js:300
accessRsp.$msgId$ @ partytown-sandbox-sw.js:373
worker.onmessage @ partytown-sandbox-sw.js:422

here docImpl.createElement("i").constructor.name returns b, and win.b is undefined. 🤷‍♀️

adamdbradley commented 2 years ago

What browser are you receiving this error? Would you be able to create a minimal example to reproduce this? Thanks

davidmerrique commented 2 years ago

@adamdbradley I'm getting a similar error. All browsers, Chrome, FF, Safari

I have it set up like this

<script>
    partytown = {
      lib: "/js/~partytown/",
      debug: true,
      forward: [['dataLayer', 1]],
      logCalls: true,
      logGetters: true,
      logSetters: true,
      logImageRequests: true,
      logMainAccess: true,
      logSendBeaconRequests: true,
      logStackTraces: false,
      logScriptExecution: true,
    };
  </script>
<script src="/js/~partytown/debug/partytown.js"></script>
<script type="text/partytown">
  (function (window, document, i) {
    window['dataLayer'] = window[dataLayer] || [];

    window['dataLayer'].push({ 'gtm.start': new Date().getTime(), 'event': 'gtm.js' });

    var firstScript = document.getElementsByTagName('script')[0];
    var gtmScript = document.createElement('script');
    var dataLayer = 'dataLayer' != 'dataLayer' ? '&l=' + 'dataLayer' : '';

    gtmScript.async = true;

    gtmScript.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dataLayer;

    firstScript.parentNode.insertBefore(gtmScript, firstScript);
  })(window, document, 'GTM-REDACTED');
</script>

And i'm getting this error:

url: https://www.googletagmanager.com/gtm.js?id=GTM-REDACTED TypeError: Cannot read properties of undefined (reading 'createElement')
    at eval (eval at re (partytown-ww-sw.js:1), <anonymous>:36:242)
    at eval (eval at re (partytown-ww-sw.js:1), <anonymous>:36:402)
    at eval (eval at re (partytown-ww-sw.js:1), <anonymous>:37:271)
    at eval (eval at re (partytown-ww-sw.js:1), <anonymous>:48:326)
    at Proxy.eval (eval at re (partytown-ww-sw.js:1), <anonymous>:493:3)
    at re (partytown-ww-sw.js:1)
    at partytown-ww-sw.js:1
edstarck commented 2 years ago

Hey! I'm getting a similar error. Help me please.

const doc = win.document;
const docImpl = doc.implementation.createHTMLDocument();
const elm = docImpl.createElement("i");
elm.constructor.name // returns 'b' but not 'HTMLElement'

elm.constructor  - > ƒ (){return a.Reflect.construct(a.HTMLElement,[],this.constructor)}
but not
elm.constructor  - > ƒ HTMLElement() { [native code] }

Why? I hope for your help. Thanks.

eliseumds commented 2 years ago

It conflicts with gpt.js:

<script src="//securepubads.g.doubleclick.net/tag/js/gpt.js" />
naveedahmed1 commented 2 years ago

Any update on this? I am also receiving this error:

partytown-sandbox-sw.html?1646610283529:2 Uncaught TypeError: Cannot read properties of undefined (reading 'prototype')
    at partytown-sandbox-sw.html?1646610283529:2:5241
    at Array.map (<anonymous>)
    at P (partytown-sandbox-sw.html?1646610283529:2:5191)
    at partytown-sandbox-sw.html?1646610283529:2:6635
    at Worker.W.onmessage (partytown-sandbox-sw.html?1646610283529:2:25463)