I'm building a Chrome extension that hides notifications around your browser. I want document title '(1) Facebook' to go to simply 'Facebook', always. In my Chrome extension content script, I have:
if (document.title.includes("Facebook")) {
document.title = "Facebook";
}
This doesn't work because document.title
is being dynamically set by the page:
- when document title first loads (which is also when my content script runs), it shows 'Facebook'
- Facebook page continues to load and document title is set to '(1) Facebook'
- at point that new notification is received (e.g. you're on the page and receive a message) document title is again set - to '(X) Facebook' where X is the new total number of notifications
How can I use my content script to override dynamic updating of the document title in the most efficient way, and set my document title to just 'Facebook' without it ever changing? I could do a setInterval
with the above function but it seems a bit heavy. I'm hoping to figure out a method that works for other sites as well (Gmail, Twitter, etc.).