Keep in mind I am very new to extensions/add ons.
I have the following function in my content.js script:
function getUpc() {
var lotsOfData = document.getElementById("__NEXT_DATA__");
lotsOfData = JSON.parse(lotsOfData.innerHTML);
var upc = lotsOfData.props.pageProps.initialData.data.product.upc;
return upc;
}
console.log("UPC: " + getUpc());
This function grabs the upc data from a walmart product. Now this function works great if I press the refresh button while looking at a product, but wont load when I search said product in walmart. It seems walmart is using AJAX or something to dynamically update the page and updates the URL when using the search feature. So I need some way to detect a URL/URI change and re-run my function.
Ive tried some solutions like a background script that listens for the 'popstate' or a change in the history, however to no avail. I just need some way to detect a dynamic change in the URL and run my function when it does.