How to access localStorage of a firefox browser via Python?
Question: following case. I have a python script that opens a firefox browser on windows
which has a firefox addon installed that writes logs into the local storage.

Before I close the browser via python I would like to read out the log
information out of the local storage of the firefox.

So how can I access the localStorage in the firefox?

Help very appreciated.


Answer: You will have to use [PyXPCOM](https://developer.mozilla.org/en-
US/docs/Mozilla/Tech/XPCOM/Language_bindings/PyXPCOM) and the
[nsIDOMStorageManager](https://developer.mozilla.org/en-
US/docs/Mozilla/Tech/XPCOM/Reference/Interface/NsIDOMStorageManager)
interface.

Have a look at this [tutorial](http://www.ibm.com/developerworks/library/co-
pyxp2/) to see how to use PyXPCOM.

You may start from this code (untested):

    
    
    from xpcom import components
    
    principal = (components.classes['@mozilla.org/scriptsecuritymanager;1']
        .getService(components.interfaces.nsIScriptSecurityManager)
        .getNoAppCodebasePrincipal(YOUR_URL))
    dom_storage_manager = (components.classes['@mozilla.org/dom/localStorage-manager;1']
        .getService(components.interfaces.nsIDOMStorageManager))
    local_storage = dom_storage_manager.getLocalStorageForPrincipal(principal, YOUR_URL)
    

