[英]Firefox Addon Scripting Trusted Page Content
So I'm trying to use a chrome:// URI in my add-on and I want to use a page-worker on it using the scripting trusted content method, however it seems to not work when I hard code the URI in, the chrome://<package name>/<part>/<file>
; 因此,我尝试在加载项中使用chrome:// URI,并且希望使用脚本可信内容方法在其上使用分页处理程序,但是当我对URI进行硬编码时,它似乎不起作用,
chrome://<package name>/<part>/<file>
; however, it works when I use the self.data.url('filename'). 但是,当我使用self.data.url('filename')时,它可以工作。 I want to use the chrome:// URI is because I use a GUID instead of the email style as the add-on's ID and also I don't want to use the resource:// URI.
我要使用chrome:// URI是因为我使用GUID而不是电子邮件样式作为加载项的ID,而且我也不想使用resource:// URI。
Content Script 内容脚本
addon.port.emit('hi');
HTML HTML
<html>
<head>
<meta charset="UTF-8">
<title>Gaia Utils Settings</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="chrome://gaiascripts/content/dropdown.min.js"></script>
<script type="text/javascript" src="chrome://gaiascripts/content/settings.dev.js"></script>
<script type="text/javascript" src="chrome://gaiascripts/content/test.dev.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="css/settings.css" rel="stylesheet" type="text/css">
<link href="css/poststyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<nav id="navbar_header" class="navbar navbar-blue navbar-static-top"></nav>
<div id="content_wrapper" class="container">
<div id="content_padding" class="container"></div>
</div>
<footer class="footer"></footer>
</body>
</html>
main.js main.js
var PageWorker = require("sdk/page-worker");
PageWorker.Page({
contentURL: "chrome://gaiautils/content/settings.dev.html",
onMessage: function(message) {
console.log(message);
}
});
I know I can use a page-mod and attach the scripts to it with that, but I'd rather call the scripts from within the file and be able to communicate with the main add-on code. 我知道我可以使用page-mod并以此附加脚本,但是我宁愿从文件中调用脚本并能够与主要附加代码进行通信。 So is there a way so that I can have my cake and eat it too - using the hard coded chrome:// URI in conjunction with calling the scripts from within the HTML file while being able to have those scripts communicate back to the main.js file?
因此,有一种方法可以让我吃蛋糕也能吃到它-使用硬编码的chrome:// URI结合从HTML文件中调用脚本,同时能够使这些脚本传达回主脚本。 js文件?
How can I have it so that I can use the addon.port.emit() in the content scripts that are called directly in the HTML file so that I don't have to use the self.data.url('htmlFile'), because I don't want to use the resource://pageckage-GUID-at-jetpack/path/to/file
如何获得它,以便可以在直接在HTML文件中调用的内容脚本中使用addon.port.emit(),因此不必使用self.data.url('htmlFile') ,因为我不想使用resource:// pageckage-GUID-at-jetpack / path / to / file
The SDK only considers pages "trusted" if the URL you're loading is part of the add-on assets ( data/
). 如果您正在加载的URL是附加资产(
data/
)的一部分,则SDK仅将页面视为“受信任”页面。 chrome://
URIs are not. chrome://
URI不是。 Hence you'll need to use regular content scripts via the contentScriptFile: [...]
option in your PageWorker definition. 因此,您需要通过PageWorker定义中的
contentScriptFile: [...]
选项使用常规内容脚本。
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
Don't ever load remote scripts for security reasons (and performance reasons to a far lesser extent)! 永远不要出于安全原因(和性能方面的影响要小得多)加载远程脚本! Ship a local copy of jQuery if you want to use it.
如果要使用它,请发送jQuery的本地副本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.