google-pay / google-pay-button

Google Pay button - React, Angular, and custom element
Apache License 2.0
254 stars 61 forks source link

Unhandled Exception Google is not Defined #219

Closed jconleyCB closed 1 year ago

jconleyCB commented 1 year ago

Describe the bug A clear and concise description of what the bug is. The issue im seeing is when the google pay script doesnt load, an unhandled exception is thrown instead of passing the error to the config.onError.

To Reproduce Steps to reproduce the behavior:

  1. Go to this stackblitz
  2. Click on update all dependencies to latest
  3. inspect the page and block https://pay.google.com/gp/p/
  4. See error

Expected behavior A clear and concise description of what you expected to happen. The updateElement function should have a check that google is defined before invoking this.client = new google.payments.api.PaymentsClient(this.createClientOptions(this.config));

Screenshots If applicable, add screenshots to help explain your problem.

Screenshot 2023-04-19 at 10 05 35 AM

Component information:

Environment:

Additional context Add any other context about the problem here.

dmengelt commented 1 year ago

@jconleyCB could you try with 3.0.6? We recently fixed a potentially related issue. We still have to update our own stackblitz examples to use the latest version 😉

jconleyCB commented 1 year ago

Yep its still an issue in 3.0.6. My assumption is that even though the try-catch catches the error for loading the script it continues down to this.updateElement() and that tries to reference google without it being defined

dmengelt commented 1 year ago

@jconleyCB found the issue. will submit a fix.

jconleyCB commented 1 year ago

Thank you @dmengelt!

dmengelt commented 1 year ago

@jconleyCB please use version 3.0.8

jconleyCB commented 1 year ago

@dmengelt So after using version 3.0.8 for a few days I noticed some users still came across the google being undefined error. Im not sure if the script loading guarantees that google is available, should a check for google be added to the updateElement(), before it's used?

dmengelt commented 1 year ago

Hi @jconleyCB very good point. Let me have a look at this.

dmengelt commented 1 year ago

@jconleyCB see #225