localStorage in a Firefox extension

前端 未结 3 2052
清歌不尽
清歌不尽 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.

提交回复
热议问题