Firefox扩展:从Chrome:/ / URL加载脚本到页面 [英] firefox extension: load script from chrome:// url into page

查看:287
本文介绍了Firefox扩展:从Chrome:/ / URL加载脚本到页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Firefox扩展中,我想添加一个JS文件到页面。

我试图通过在页面中添加一个脚本标记我的脚本:

 < script src =chrome://path/to/my/script/file.jstype =text / javascriptasync =>< / script> 

但是当我将它添加到页面时,没有任何反应。



这个脚本在devtools中是不可见的(debugger> sources)。

当我在地址栏中输入相同的url时, 。

我错过了什么?

解决方案

一个安全错误,请参阅浏览器控制台,它会说铬URL不允许注入。你需要做的是在你要注入文件的路径上设置 contentaccessible = true - 在你的 chrome.manifest 像这样: https://gist.github.com/ Noitidart / 9406437#file-chrome-manifest-L1


In my Firefox extension I want to add a JS file to the page.

I tried to do that by adding to the page a script tag with the url to my script:

<script src="chrome://path/to/my/script/file.js" type="text/javascript" async=""></script>

But nothing happens when I add it to the page.

The script is not visible in the devtools (debugger > sources).

When I enter the same url in the address bar - I do see the file.

What am I missing?

解决方案

You are probably getting a security error, see in browser console it will say chrome url not allowed to be injected. What you have to do is set contentaccessible=true on the path which you have files which you want to inject - in your chrome.manifest like this: https://gist.github.com/Noitidart/9406437#file-chrome-manifest-L1

这篇关于Firefox扩展:从Chrome:/ / URL加载脚本到页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆