getFavicon.js 755 B

1234567891011121314151617181920212223242526272829
  1. /**
  2. Gets the favicon url
  3. @module getFavicon
  4. */
  5. const { ipcRenderer } = require('electron');
  6. (function() {
  7. document.addEventListener('DOMContentLoaded', DOMContentLoaded, false);
  8. function DOMContentLoaded(event) {
  9. const icon =
  10. document.querySelector('link[rel="apple-touch-icon"]') ||
  11. document.querySelector('link[type="image/x-icon"]') ||
  12. document.querySelector('link[rel="shortcut"]') ||
  13. document.querySelector('link[rel="shortcut icon"]') ||
  14. document.querySelector('link[rel="icon"]');
  15. if (icon) {
  16. ipcRenderer.sendToHost('favicon', icon.href);
  17. } else {
  18. ipcRenderer.sendToHost('favicon', null);
  19. }
  20. document.removeEventListener('DOMContentLoaded', DOMContentLoaded, false);
  21. }
  22. })();