Why won't the SVG load in chrome extension?

懵懂的女人 提交于 2019-12-10 11:14:55

问题


I am injecting some HTML into websites using a chrome extension. In that code I am including an SVG. But when I load websites I get

Failed to load resource: the server responded with a status of 404 (Not Found) http://stackoverflow.com/questions/SVG/home-outline.svg

All of my svg files are in a folder called SVG. I am loading the SVG files with "web_accessible_resources": ["SVG/*.svg"] as I have loaded my other files. Why won't my image load?

<span class="menu_T">
    <button class="large_menu_button_T">
        <img src="SVG/home-outline.svg">
    </button>
</span>

I get the same result when I try to add the svg through css background.


回答1:


In the injected code, relative paths like "SVG/home-outline.svg" point to the site you're injecting to.

You need a full path to the resource in your extension. It's easy to get it: chrome.runtime.getURL("SVG/home-outline.svg") does the job.



来源:https://stackoverflow.com/questions/23592101/why-wont-the-svg-load-in-chrome-extension

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