localStorage in a Firefox extension

前端 未结 3 2062
清歌不尽
清歌不尽 2021-02-14 11:59

I am trying to access the localStorage of a page from a Firefox extension. My understanding is that content gives a reference to the window of the cur

相关标签:
3条回答
  • 2021-02-14 12:25

    From a Firefox extension, you can access the localStorage object with window.content.localStorage, for example:

    var ls = window.content.localStorage;
    ls.setItem("myvariable", "myvalue");
    var item = ls.getItem("myvariable");
    

    Anything else will give you a "Component not available" error.

    As an aside, globalStorage doesn't work this way. You can't use it at all with an extension because the object is only available if it's run from a server.

    0 讨论(0)
  • 2021-02-14 12:26

    use content.localStorage.wrappedJSObject.myVariable

    0 讨论(0)
  • 2021-02-14 12:32

    Using NsIDOMStorageManager xpcom interface you can get your local storage information.

    https://developer.mozilla.org/en/XPCOM_Interface_Reference/NsIDOMStorageManager

    0 讨论(0)
提交回复
热议问题