问题
I'm trying to set a variable equal to the favicon url of the current page. Are you not able to do this in the background script? How else could I get the current page's favicon url that the user is on?
background.js
var currentFaviconURL = document.querySelector("link[rel*='shortcut icon']").href;
console.log(currentFaviconURL);
console
Error in response to tabs.query: TypeError: Cannot read property 'href' of null
回答1:
For reading and manipulating DOM, you must use Content Scripts. https://developer.chrome.com/extensions/content_scripts
来源:https://stackoverflow.com/questions/51885877/chrome-extension-using-document-queryselector-in-background-script