Access Add-on SDK module from the scratchpad

后端 未结 2 1082
刺人心
刺人心 2021-02-06 18:04

I\'d like to test small snippets of my add-on code using the scratchpad. In this case, I\'m trying to access the notifications module like so:

const { notify } =         


        
2条回答
  •  攒了一身酷
    2021-02-06 18:14

    By now there is a relatively simple way to do this. The following code works fine if executed in privileged context (meaning switching Scratchpad's environment to "Browser"):

    let {require} = Cu.import("resource://gre/modules/commonjs/toolkit/require.js", {});
    let {notify} = require("sdk/notifications");
    

    This is supported starting with Firefox 36 but not really documented as of now - meaning that this might stop working in future.

    For reference: pull request #1679 added this functionality (not meant for external use it seems).

提交回复
热议问题