homerchen19 / github-file-icons

🌈 🗂 A browser extension which gives different filetypes different icons to GitHub, GitLab, gitea and gogs.
https://chrome.google.com/webstore/detail/file-icon-for-github-and/ficfmibkjjnpogdcfhfokmihanoldbfe
MIT License
1.44k stars 69 forks source link

Icons flashing issue #3

Closed aj-4 closed 6 years ago

aj-4 commented 6 years ago

Icons will show briefly and disappear on initial page load. They work as expect on refresh and with cached pages.

It seems they are being loaded then replaced by the default svg graphic. Are others having this issue?

seanhamlin commented 6 years ago

Yeap, seeing the same issue too. Basically makes the extension unusable in it's current state.

homerchen19 commented 6 years ago

So do I, but not everytimes. GitHub somehow rerenders page, and it makes this extension useless at the first time. I will try to find a listener api to detect when the page is reloaded, then call contentscript.js again.

Updated I found that chrome.webNavigation.onHistoryStateUpdated did be triggered when the page rerendered, so it would be called twice if entering a non-cache page. I believe GitHub rerenders the page asynchronously. Therefore, the icons are replaced by this extension replaces the icons immediately when the request is completed, then GitHub rerenders the page.

Timeline would be: render(first time) -> extension replaced the icons -> render(second time) request completed -> extension replaced the icons -> render(second time) finished

homerchen19 commented 6 years ago

I have tried a workaround way is to replace icons after delaying execution for 500 ms. Although final result is correct, this will cause icons to flash twice. I couldn't think of alternative way to solve this problem at this moment 😢

aj-4 commented 6 years ago

would you mind pushing that workaround? if they persist I wouldn't mind a double flash :)

homerchen19 commented 6 years ago

Sure. https://github.com/xxhomey19/github-file-icon/blob/6d1fced4dae432912ebfd5f6d8b1e05679c30d79/src/js/contentscript.js#L6

@aj-4 do you think this would be better then the latest version? I'm unsure about it.

https://github.com/OctoLinker/injection this seems work though.

aj-4 commented 6 years ago

@xxhomey19 imo that'd be a great workaround

homerchen19 commented 6 years ago

@aj-4 Me too, but I'm still trying to find a better solution. I think someone has developed browser extension on GitHub should also get this problem.