Controlling a Firefox Extension via Javascript

前端 未结 2 915
失恋的感觉
失恋的感觉 2020-12-01 19:46

Is it possible, using javascript, to control an overlay firefox extension? I\'ve extracted the contents of the extension and have identified what functions/methods I need to

2条回答
  •  执笔经年
    2020-12-01 20:30

    Update for Firefox 47 and up

    Things changed drastically in Firefox 47. This is the new way to access it.

    var XPIScope = Cu.import('resource://gre/modules/addons/XPIProvider.jsm');
    var addonid = 'Profilist@jetpack';
    var scope = XPIScope.XPIProvider.activeAddons.get(addonid).bootstrapScope
    

    Old way for < Firefox 47

    Update for methods of today

    Typically you will do so like this:

    If i wanted to get into AdBlocks scope, I check AdBlock id, it is {d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d} so I would go:

    var XPIScope = Cu.import('resource://gre/modules/addons/XPIProvider.jsm');
    var adblockScope = XPIScope.XPIProvider.bootstrapScopes['{d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}'];
    

    You can now tap into anything there.

    Another example, I have an addon installed with id NativeShot@jetpack

    I would tap into it like this:

    var XPIScope = Cu.import('resource://gre/modules/addons/XPIProvider.jsm');
    var nativeshotScope = XPIScope.XPIProvider.bootstrapScopes['NativeShot@jetpack'];
    

    if you do console.log(nativeshotScope) you will see all that is inside.

提交回复
热议问题