Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 7 Turbo using this gem (stripe-rails) produces Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://js.stripe.com') does not match the recipient window's origin #223

Open
jasonfb opened this issue Jan 4, 2023 · 1 comment

Comments

@jasonfb
Copy link

jasonfb commented Jan 4, 2023

Rails 7 with Turbo enabled interactions

if this gem is install and the Stripe JS is loaded at all, then all page navigations produce this JS error in the console:

(index):1 Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://js.stripe.com') does not match the recipient window's origin

(the error doesn't actually block anything)

also reported here
stripe/react-stripe-js#188

@jasonfb
Copy link
Author

jasonfb commented Jan 4, 2023

a fix has been documented here:

hotwired/turbo#270 (comment)

// persist initial stripe iFrame DOM Object across turbo AJAX page requests
let stripeIFrameQuery = 'iframe[src^="https://js.stripe.com"]';
document.addEventListener('turbo:before-render', function (event) {
  const stripeIFrame = document.querySelector(stripeIFrameQuery);
  const newStripeIFrame = event.detail.newBody.querySelector(stripeIFrameQuery);
  if (stripeIFrame && !newStripeIFrame){
    event.detail.newBody.appendChild(stripeIFrame)
  }
});

I'd recommend either this fix be added directly to this gem or that there be some kind of 3rd gem that glues Turbo and stripe-rails together using the code above.

@jasonfb jasonfb changed the title Rails 7 Turbo using this gem produces Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://js.stripe.com') does not match the recipient window's origin Rails 7 Turbo using this gem (stripe-rails) produces Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://js.stripe.com') does not match the recipient window's origin Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant