If you’ve ever built a slide-out cart drawer, a dynamic free-shipping bar, or custom analytics tracking for a Shopify store, you've run straight into this brick wall: Shopify themes do not emit consistent, trustworthy cart events.
You write a perfect event listener, only to find out a third-party product-bundle app uses old-school XMLHttpRequest (XHR) instead of fetch to add items to the cart. Your listener misses it completely, the cart drawer stays shut, and your user thinks the button is broken.
Most developers end up copying and pasting messy, brittle window.fetch overrides into their projects.
Frustrated by solving this over and over again, I built Shopify Cart Broadcaster—a zero-dependency, 2 KB utility that intercepts both Fetch and XHR requests seamlessly to provide universal DOM events.
👉 Check out the source on GitHub: Rabin-p/shopify-cart-broadcast (If this saves you an afternoon of debugging, drop a ⭐!)
The Nightmare of the /cart/add Response
Even if you successfully listen to Shopify's /cart/add.js request, Shopify throws another curveball at you.
When you add an item to the cart, the server responds with only the item(s) that were just added—not the updated state of the entire cart. If your slide-out cart drawer needs the new total price to see if a discount threshold is met, you are out of luck.
You're forced to manually chain another fetch('/cart.js') request to get the true state.
My utility handles this annoying race-condition out of the box. It detects the mutation type, intercepts it, pushes the true cart events to the window and displays it beautifully.
window.addEventListener('shopify:cart-updated', (e) => {
// Always gives you the accurate, updated cart object!
console.log('New Cart Total:', e.detail.cart.total_price);
});
Top comments (0)