chrome-tab-modifier icon indicating copy to clipboard operation
chrome-tab-modifier copied to clipboard

Why use WebKitMutationObserver?

Open MartinLichtblau opened this issue 5 years ago • 7 comments

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.

MartinLichtblau avatar Apr 28 '19 18:04 MartinLichtblau

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!

sylouuu avatar Apr 28 '19 19:04 sylouuu

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.

MartinLichtblau avatar Apr 29 '19 16:04 MartinLichtblau

Thanks for your feedback.

Does it work on SPA?

It would be very nice!

sylouuu avatar May 03 '19 20:05 sylouuu

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 :-)

MartinLichtblau avatar May 04 '19 14:05 MartinLichtblau

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

sylouuu avatar May 04 '19 14:05 sylouuu

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'});

MartinLichtblau avatar May 04 '19 15:05 MartinLichtblau

Hello @sylouuu what do you say about merging this Pull Request?

MartinLichtblau avatar Aug 03 '19 07:08 MartinLichtblau

All pending PRs will be reviewed lately.

Best

sylouuu avatar Mar 28 '24 14:03 sylouuu