开发者

Accessing local resources from a content script

开发者 https://www.devze.com 2023-03-20 22:55 出处:网络
Is there a way i can access local resources inside a script? I need to access data.url(\'layout.html\'), data.url(\'icon.png\') and data.url(\'style.css\') inside the contentScript handler.

Is there a way i can access local resources inside a script? I need to access data.url('layout.html'), data.url('icon.png') and data.url('style.css') inside the contentScript handler.

exports.main = function() {
  require("widget").Widget({
    onClick: function() {
      tabs.activeTab.attach({
        contentScriptFile: [ data.url('jquery.js')],
        contentScript:
          "setTimeout(function(){ alert('asd');}, 100);",
        });
    } 
 开发者_如何学运维 });
}


I've ended up using cssUrl = data.url('alert.css'). In main.js i set this up, and in the script running client-side add a script having href=cssUrl.


Use contentScriptOptions to pass it to the content script, like this:

//main.js
contentScriptFile: [ data.url('jquery.js')],
contentScriptOptions: {
   cssUrl: data.url('alert.css')
}

// jquery.js
console.log(self.options.cssUrl)
0

精彩评论

暂无评论...
验证码 换一张
取 消