Firefox extension - Share common state between two or more windows

人盡茶涼 提交于 2019-12-11 14:49:14

问题


I am developing firefox extension. Problem is that when i open second window (Ctrl + N) my extension has new state for new opened window. If I reacts or changes on second window it never affect on first window or vice versa.

Ex Installed extension on Firefox first window opened. My extension proper functioning, change state, login, view data etc then opened second. My extension goes new state I cant get previous states (first window states).

How can maintain same state between first and second or other firefox opened windows.?


回答1:


Am I correct to assume you're developing a XUL overlay add-on, and not an SDK add-on?

One way to share state between windows is to use Javascript code modules. A code module will only be loaded once (unless explicitly unloaded) and therefore will expose the same data to multiple windows. Be sure to read the "Sharing objects using code modules"., However, please note that therefore when closing a window, any state associated with it and stored within the code module must be cleaned up, or would leak otherwise.

If you're using the SDK instead, your main.js module is already the equivalent of a code module. Content scripts may use message passing to store and retrieve state from your module.



来源:https://stackoverflow.com/questions/18358207/firefox-extension-share-common-state-between-two-or-more-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!