PAYONE-GmbH / magento-2

PAYONE Payment Extension for Magento 2
28 stars 56 forks source link

JS Issues with Amazon Pay #448

Closed gfemorris closed 2 years ago

gfemorris commented 2 years ago

When calling / redirecting to the "Amazon Pay" onepage checkout in Magento 2 (2.4.2-p2), a Javascript error occurs sporadically:

Uncaught TypeError: formAction.indexOf is not a function

File: web/vendor/magento/magento2-base/lib/web/mage/common.js:30

After one or more reloads of the page, however, this error no longer occurs, possibly a race condition? The cause seems to be the following fields in the Amazon Pay forms, as Magento 2 incorrectly picks up these fields instead of the actual form action, which leads to the above error.

Formular: form#OffAmazonPaymentsWidgets0Form

Problematisches Input Feld: <input type="hidden" name="action" value="spaAddressWidget">

und

Formular: form#OffAmazonPaymentsWidgets1IFrame Problematisches Input Feld: <input type="hidden" name="action" value="spaWalletWidget">

Is this error known with the Payone Extension (payone-gmbh/magento-2: 3.4.1) in combination with Magento 2 (2.4.2-p2)?

janteuber commented 2 years ago

Hello @gfemorris ,

Thanks for your request.

I have forwarded the issue and will get back to you as soon as there is news.

FatchipRobert commented 2 years ago

I can confirm this error, happens in my testing environments too.

Still looking for a way to prevent this. Not so easy, since the two scripts clashing are not part of the Payone module.

FatchipRobert commented 2 years ago

Tricky one - there was a race condition indeed.

I think I fixed it, but technically there is still a race condition.

The problem is that this line of the common.js https://github.com/magento/magento2/blob/2.4-develop/lib/web/mage/common.js#L28 tries to read the action attribute of the form, expecting the URL the form wants to send to. But the form.prop('action') call returns the hidden input with the name "action" you mentioned.

Disabling the common.js didnt help, there was another Magento javascript doing a similar thing and stumbling over the action hidden input and there was also no way to hinder the AmazonPay javascript to add those action hidden inputs.

I added a javascript mechanism that is looking for those action hidden inputs and removes these from the document before the problematic Mage2 javascripts are triggered, this way it worked for me all the time.