I am coding a chrome extension to detect changes in the DOM after a certain button is clicked on this website. Specifically, once one clicks the add-to-cart button, a popup appears displaying more information, and when this occurs the DOM changes. I've coded an event listener to see when the add-to-cart button is clicked. However, if I click say one of the buttons to specify my size, a notification in the console appears stating Overriding "availability.update"!. And after this, when I click the add-to-cart button, I get no response from my code. Does anyone know how to fix this?
JavaScript (content.js)
document.getElementById("add-to-cart").addEventListener("click", domChange); //event listener for add-to-cart button
function domChange(){ //checks for changes in the DOM
var myElement = $('<div class="modal-content js-modal-content></div>')[0];
var observer = new MutationObserver(function(mutations) {
if (document.contains(myElement)) {
console.log("It's in the DOM!");
observer.disconnect();
}else{
console.log('did not work');
}
});
observer.observe(document, {attributes: false, childList: true, characterData: false, subtree:true});
}
Manifest.json
{
"manifest_version": 2,
"name": "Chrome Extension Test",
"description": "chrome extension trial build",
"version": "1.0.0",
"browser_action": {
"default_popup": "popup.html"
},
"content_scripts": [{
"js": ["content.js"],
"matches": ["http://*/*", "https://*/*"]
}],
"content_security_policy": "script-src 'self' 'unsafe-eval' https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js; object-src 'self'",
"permissions": [
"http://localhost/",
"tabs",
"<all_urls>"
]
}
HTML (popup.html)
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="content.js"></script>
</head>
<body>
</body>
</html>