chrome-tab-modifier
chrome-tab-modifier copied to clipboard
Why use WebKitMutationObserver?
Hello @sylouuu
why do you use window.WebKitMutationObserver
to observe favicon and title changes, when you could use chrome.tabs.onUpdated
listener instead? This is so much simpler and resource efficient.
Hey,
I'm not sure, it was a long time ago. Maybe for performance purpose. I don't remember if chrome.tabs.onUpdated
was available. Anyway thanks for this!
I tried it and it works: removed both observers and use only onUpdate instead. Can't see any behavior change, but many advantages like less code, better performance, cleaner processing flow and potentially less interference with other extensions. Will try for ~two weeks and then do a pull-request, although you implicated in your announcement that you won't accept them anymore. But since I started the work before that, and deem this change and the retry feature worth it, I would be happy if you looked into it nevertheless.
If SPAs are websites such as Gmail, Keep and Trello, then it works. Or do you have any any specific pages in mind where I should test it?
IMO more important than that are the resource requirements. E.g. the resource heavy MutationObservers fired on every DOM change after you've visited a page with rules. At some point I realized this was the reason why google Keep became so unresponsive. Another change I did just now is to inject the content script only on pages for which you have configured rules, and not preventively on any page.
So, I will have to try it out a bit longer, to see if it's stable. Until then, thank you :-)
Yes SPA for websites that change the URL dynamically.
How can you inject the content script depending on your rules? Since the injection is defined in https://github.com/sylouuu/chrome-tab-modifier/blob/master/dist/manifest.json#L29
In background.js
checking if the page got a rule
getRule(tab.url, function(rule) { if (rule !== null) { triggerContentScript(tabId, rule); } });
and triggering/injecting the it like this
chrome.tabs.executeScript(tabId, {file: 'js/content.js'});
Hello @sylouuu what do you say about merging this Pull Request?
All pending PRs will be reviewed lately.
Best