I am integrating Stripe Elements using vue-stripe-elements-plus on a single page application. I want to completely unload Stripe after the user leaves the credit card module, but it seems more complicated than expected.
Even after unloading it in the component's destroyed
hook and removing the iframes added by Stripe:
destroyed () {
this.$unloadScript('https://js.stripe.com/v3/');
let stripeIframes = [
document.querySelectorAll('[name^=__privateStripeMetricsController]'),
document.querySelectorAll('[name^=__privateStripeController]'),
];
stripeIframes.forEach(iframes => iframes.forEach(iframe => {
iframe.parentNode.removeChild(iframe);
}));
},
The iframes added by Stripe:
https://i.sstatic.net/qrj6J.png
reappear after some time (one of them in particular):
https://i.sstatic.net/LFgSz.png
It appears that this iframe is regenerated by Stripe's listeners attached to the window object during message events. Removing this listener is challenging as the handler function is nested inside an inaccessible iframe within another iframe.
Additionally, this listener triggers unwanted requests to the Stripe server:
XHR finished loading: POST "https://m.stripe.com/4".