amzn / amazon-payments-magento-2-plugin

Extension to enable Amazon Pay on Magento 2
https://amzn.github.io/amazon-payments-magento-2-plugin/
Apache License 2.0
109 stars 77 forks source link

Cannot read property 'Login' of undefined #973

Closed HenKun closed 3 years ago

HenKun commented 4 years ago

What I expected

No JS errors

What happened instead

Sometimes (but often), one can see JS error in console:

Uncaught TypeError: Cannot read property 'Login' of undefined
    at HTMLImageElement.B (Widgets.js?nomin:2)
B | @ | Widgets.js?nomin:2
-- | -- | --
  | load (async) |   |  
  | bindEvent | @ | Widgets.js?nomin:2
  | C.Button | @ | Widgets.js?nomin:2
  | _renderAmazonButton | @ | shared.js:212
  | $.each.$.isFunction.a.<computed> | @ | shared.js:17
  | _create | @ | shared.js:212
  | $.each.$.isFunction.a.<computed> | @ | shared.js:17
  | _createWidget | @ | shared.js:17
  | $.<computed>.<computed> | @ | shared.js:17
  | $.<computed>.<computed> | @ | shared.js:17

Pretty printed the error occurs on line 9727 in Widget.js:

void 0 !== l().Login.Metrics)

l() refers to line 6286 in Widget.js

t.exports = function() {
            return window.amazon
        }

window.amazon is null in this case. window.amazon is set by login.js, so I guess there is a timing problem somewhere.

If I break before the line and try to debug slowly, the error does not occur, probably because login.js was executed meanwhile.

Steps to reproduce the issue

Happens sometimes (often) on any page, where an Amazon button is rendered. (doesn't matter if logged in or out of Amazon)

Note: I don't see any obvious failures that result from this JS error.

Your setup

zichicc commented 4 years ago

Hi @HenKun , for this issue and https://github.com/amzn/amazon-payments-magento-2-plugin/issues/974, we would need more details from you in order to proceed with the investigation. Can you contact us at payments-cp-devel@amazon.com and provide a staging URL where these 2 issues occur?

Thanks Best Christian

zichicc commented 3 years ago

Hi @HenKun , this error should be solved with the PR we just merged: https://github.com/amzn/amazon-payments-magento-2-plugin/pull/990 please let us know if you still see the error

Thanks Best Christian