简体   繁体   中英

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. 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 ?

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.

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.

If you provided more information about what your add-on actually does, people might be able to suggest a better approach to the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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