Chrome Extension: using document.querySelector in background script

跟風遠走 提交于 2020-03-05 07:36:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!