简体   繁体   English

firefox插件中面板内容脚本和页面内容脚本之间的全局变量

[英]global variable between panel content script and page content script in firefox addon

It is possible to make a global variable same for panel script and page script ? 面板脚本和页面脚本可以使全局变量相同吗?

maybe some hacks like using pointers or maybe some storage locations which can be easily access by panel script and page script. 也许有些黑客比如使用指针或者某些存储位置,可以通过面板脚本和页面脚本轻松访问。 I do not want to send variable with posting messages using port comunnication because I will use this variable in a timer functions which refresh in interval of mileseconds, and web browser will be overloaded if it will post so many messages with system ports. 我不希望使用端口通信发送带有发布消息的变量,因为我将在一个计时器函数中使用此变量,该函数以英里秒的间隔刷新,如果它将使用系统端口发布这么多消息,则Web浏览器将被重载。 I think it will be better if I can read the variable from a location, which can be easily accessed by panel script and page script. 我认为如果我能从一个位置读取变量会更好,这可以通过面板脚本和页面脚本轻松访问。 I'm new to firefox add-on builder, how can I achieve this for my addon ? 我是firefox附加构建器的新手,我怎么能为我的插件实现这个呢?

here I'm attaching panel script, which will read the value saved with page script. 这里我附加了面板脚本,它将读取用页面脚本保存的值。

var panel = require("panel").Panel({
          width: 100,
          height: 100,
          contentScriptFile: data.url("panel_script.js")
    });

here I'm attaching page script which will save a value from page content and panel script will read it. 这里我附加了页面脚本,它将从页面内容中保存一个值,面板脚本将读取它。

var pageMod = require("page-mod");
pageMod.PageMod({
    include: "*",
    contentScriptFile: self.data.url("page_script.js"),
    contentScriptWhen: 'ready'
  });

UPDATE: 更新:

I want to read the player position which is playing on the page, and I need it to be very accurate as mileseconds and I want to use a timer in my addon panel script to get player position value. 我想要读取页面上正在播放的播放器位置,我需要它非常准确,只需几秒钟,我想在我的插件面板脚本中使用计时器来获取玩家位置值。 If I use port requests then web browser is overloaded with so many requests which take more resources than if I would be able just to save the value in a location which can be readed from panel script easily. 如果我使用端口请求,那么Web浏览器会因为如此多的请求而过载,这比我只能将值保存在可以从面板脚本轻松获取的位置中获取更多资源。

You can't, and this is on purpose mainly for security and performance reasons. 你不能,这主要是出于安全和性能原因。 Content scripts are necessarily separate from the main add-on code in main.js so as to prevent web content from being able to inject and run code in main.js with access potentially to all o the Firefox apis, things like writing files to the file system, listening on tcp sockets and modifying other web pages. 内容脚本必须与main.js中的主要附加代码分开,以防止Web内容能够在main.js中注入和运行代码,并且可能访问所有Firefox apis,例如将文件写入文件系统,侦听tcp套接字和修改其他网页。

If you provided more information about what your add-on actually does, people might be able to suggest a better approach to the problem. 如果您提供了有关附加组件实际功能的更多信息,那么人们可能会建议更好地解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM