I am trying to get the cart items in phtml file (product detail page) using jquery script. Here is the script:
require([ 'jquery', 'jquery/ui'], function($,item){
item = require('Magento_Customer/js/customer-data').get('cart')().items;
console.log(item.length);
});
It not load customer data all the time.I need this to get the item count when product added or deleted from the mini cart dynamically using ajax cart. On firefox its works but fails in chrome browser.I dont know how to initialize the require('Magento_Customer/js/customer-data') early, so that it works well for all cases. Please help or provide other solution to get the cart item dynamically using jquery