为什么使用html导入动态加载资源不需要web_accessible_resources中的条目?

时间:2015-05-06 14:13:44

标签: javascript google-chrome-extension

如果没有我的Chrome扩展程序,我似乎可以将资源加载到web_accessible_resources中未指定的文档头部。

我想澄清一下这是否是一个错误,一旦它被修复就会回来追捕我或者是Chrome扩展中的一个功能。

不用多说,这就是我从content script

加载资源的方式
  function loadRes(res) {
    return new Promise(
      function(resolve, reject) {
        var link = document.createElement('link');
        link.setAttribute('rel', 'import');
        link.setAttribute('href', res);
        link.onload = function() {
          resolve(res);
        };
        document.head.appendChild(link);
      });
  }

  loadRes( "vendor/bower_components/webcomponentsjs/webcomponents-lite.js" )
  .then( loadRes("vendor/bower_components/polymer/polymer.html") )
  .then(function(){
      window.chromeApp = new ChromeApp(options);
  });
}

任何人都可以解释为什么Chrome不会动态加载它们?

更新

这是我的清单文件:

{
  "name": "Web Notes",
  "version": "1.0",
  "manifest_version": 2,
  "description": "C",
  "icons": {"128": "assets/images/ext_icon.png"},
  "browser_action": {
    "default_icon": "assets/images/ext_icon.png",
    "default_title": "C",
    "default_popup": "popup.html"
  },
  "content_scripts": [ {
    "js": [
      "vendor/bower_components/jquery/dist/jquery.min.js",
      "vendor/bower_components/underscore/underscore-min.js",
      "vendor/bower_components/backbone/backbone.js",
      "vendor/bower_components/pouchdb/dist/pouchdb.js",

      "assets/javascripts/collections/asset_collection.js",

      "assets/javascripts/helpers/asset_view_helper.js",
      "assets/javascripts/models/pouch_db_user.js",
      "assets/javascripts/models/node_client.js",
      "assets/javascripts/views/chrome_app.js",

      "content.js"
    ],
    "css": [
      "vendor/bower_components/bootstrap-tagsinput/dist/bootstrap-tagsinput.css",
      "vendor/bower_components/bootstrap/dist/css/bootstrap.min.css",
      "assets/stylesheets/css/chrome_app.css"
    ],
    "matches": ["file://*", "http://localhost/*.*"]
  }],
  "web_accessible_resources": [
    "vendor/bower_components/jquery/dist/jquery.min.map",
    "assets/images/*.*",
    "web_components/component/component.html"
  ]
}

0 个答案:

没有答案