I'm using the stripe JS library on my frontend and just setting the token, not actually using the library for anything. Odd thing is that when I load any page stripe will make a bunch of odd requests and lots of them are duplicates. Often it'll look like this:
https://m.stripe.com/4
https://m.stripe.com/4
https://stripensrq.global.ssl.fastly.net/s/e
https://stripensrq.global.ssl.fastly.net/s/o
https://m.stripe.com/4
Then if I change the page state using the History API it makes all these calls again even though this is a single page webapp. Is this normal?
This behavior caught me by surprise, too. If you have import { loadStripe } from '@stripe/stripe-js
anywhere in your SPA, Stripe will begin phoning home on every page load from the moment your app opens.
As of @stripe/stripe-js v1.4.0, you can use the /pure
import path, which defers the load of Stripe's library until the app actually calls loadStripe
:
import { loadStripe } from '@stripe/stripe-js/pure';
Once you call loadStripe
, Stripe will continue sending requests to https://m.stripe.com/4
on every URL change until the browser navigates to a new page through an HTTP request (not through a JavaScript route change) or until the browser reloads.
stripe.js makes requests to https://m.stripe.com/4
as part of its fraud detection mechanisms. As of @stripe/stripe-js v1.5.0, you can disable this behavior by setting {advancedFraudSignals: false}
:
import {loadStripe} from '@stripe/stripe-js/pure';
loadStripe.setLoadParameters({advancedFraudSignals: false})
const stripe = await loadStripe('pk_test_TYooMQauvdEDq54NiTphI7jx');
Note that disabling this feature increases your risk of receiving fraudulent transactions.
I wrote a blog post about this if you're interested in additional details: https://mtlynch.io/stripe-recording-its-customers/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With