I'm trying to create a chrome extension (for personal use) that will run every time I open a gmail message, however I can't seem to get the function to run in gmail pages. When I try it on other pages it runs successfully, but not on gmail. I have tried different kind of listeners and added a couple of alerts as an indication for what's running, but on gmail nothing runs at all.
Manifest:
{
"name": "***",
"version": "0.99",
"manifest_version": 2,
"content_scripts" : [
{
"matches": ["<all_urls>"],
"js": ["agent.js"],
"css": ["style.css"],
"all_frames": true
}
],
"icons": {
"16": "icon16.png",
"48": "icon16.png",
"128": "icon16.png"
},
"browser_action": {
"default_popup": "popup.html"
}
}
agent.js:
function replaceText() {
if ((document.body.innerHTML.search("****")) >= 0) {
alert("Found")
var prev = document.getElementsByTagName("table")...
prev = prev.replace(...)
prev = prev.replace(...)
document.getElementsByTagName("table")... = prev
}
}
window.addEventListener('load', function () {
alert("Started")
replaceText()
})
new MutationObserver(() => {
alert("Started")
replaceText()
}).observe(document, {subtree: true, childList: true});
chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
if (changeInfo.status == 'complete') {
alert("Started")
replaceText()
}
})