从内容脚本访问本地资源

发布于 2024-11-25 01:25:43 字数 500 浏览 3 评论 0原文

有没有办法可以访问脚本中的本地资源? 我需要访问 data.url('layout.html')data.url('icon.png')data.url('style. css') 在 contentScript 处理程序中。

exports.main = function() {
  require("widget").Widget({
    onClick: function() {
      tabs.activeTab.attach({
        contentScriptFile: [ data.url('jquery.js')],
        contentScript:
          "setTimeout(function(){ alert('asd');}, 100);",
        });
    } 
  });
}

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);",
        });
    } 
  });
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白芷 2024-12-02 01:25:43

我最终使用了 cssUrl = data.url('alert.css')。在 main.js 中我进行了设置,并在运行客户端的脚本中添加一个具有 href=cssUrl 的脚本。

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.

九厘米的零° 2024-12-02 01:25:43

使用 contentScriptOptions 将其传递给内容脚本,如下所示:

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

// jquery.js
console.log(self.options.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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文