Chrome扩展程序 - 通过content_scripts

时间:2015-09-04 15:44:40

标签: javascript google-chrome google-chrome-extension handlebars.js content-script

我正在尝试使用Chrome扩展程序中的content_scripts在页面中注入一个把手模板,使用来自content_scripts的页面中的以下代码:

var xhr = new XMLHttpRequest();
xhr.open('GET', chrome.extension.getURL('app/templates/tpl.handlebars'), true);
xhr.onreadystatechange = function() {
    if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
        var tplScript = document.createElement('script');
        tplScript.text = xhr.responseText;
        tplScript.id = "mytpl";
        tplScript.type = "text/x-handlebars-template";
        (document.head || document.documentElement).appendChild(toolbarScript);
    }
};
xhr.send();

但是在控制台中我看到了:

Denying load of chrome-extension://hnblpfiofigbkdcdfohdaeifopkjkngj/app/templates/tpl.handlebars. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.

我在清单的相关部分有它:

"web_accessible_resources": [
    "lib/jquery/jquery-2.1.4.min.js",
    "lib/handlebars/handlebars-v3.0.3.js",
    "main.js",
    "app/templates/tpl.handlebars"
  ]

其他脚本运行没有任何问题。我错过了什么吗?

[编辑]修复了web_accessible_resources中的拼写错误,抱歉

谢谢!

0 个答案:

没有答案
相关问题