tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

webconsole.js (6478B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 const {
      8  types,
      9  generateActorSpec,
     10  RetVal,
     11  Option,
     12  Arg,
     13 } = require("resource://devtools/shared/protocol.js");
     14 
     15 types.addDictType("console.startlisteners", {
     16  startedListeners: "array:string",
     17 });
     18 
     19 types.addDictType("console.stoplisteners", {
     20  stoppedListeners: "array:string",
     21 });
     22 
     23 types.addDictType("console.autocomplete", {
     24  matches: "array:string",
     25  matchProp: "string",
     26 });
     27 
     28 types.addDictType("console.evaluatejsasync", {
     29  resultID: "string",
     30 });
     31 
     32 types.addDictType("console.cachedmessages", {
     33  // this type is a union of two potential return types:
     34  // { error, message } and { _type, message, timeStamp }
     35  error: "nullable:string",
     36  message: "longstring",
     37  _type: "nullable:string",
     38  timeStamp: "nullable:string",
     39 });
     40 
     41 const webconsoleSpecPrototype = {
     42  typeName: "console",
     43 
     44  events: {
     45    evaluationResult: {
     46      resultID: Option(0, "string"),
     47      awaitResult: Option(0, "nullable:boolean"),
     48      errorMessageName: Option(0, "nullable:string"),
     49      exception: Option(0, "nullable:json"),
     50      exceptionMessage: Option(0, "nullable:string"),
     51      exceptionDocURL: Option(0, "nullable:string"),
     52      exceptionStack: Option(0, "nullable:json"),
     53      hasException: Option(0, "nullable:boolean"),
     54      frame: Option(0, "nullable:json"),
     55      helperResult: Option(0, "nullable:json"),
     56      input: Option(0, "nullable:string"),
     57      notes: Option(0, "nullable:string"),
     58      result: Option(0, "nullable:json"),
     59      startTime: Option(0, "number"),
     60      timestamp: Option(0, "number"),
     61      topLevelAwaitRejected: Option(0, "nullable:boolean"),
     62    },
     63    fileActivity: {
     64      uri: Option(0, "string"),
     65    },
     66    pageError: {
     67      pageError: Option(0, "json"),
     68    },
     69    logMessage: {
     70      message: Option(0, "json"),
     71      timeStamp: Option(0, "string"),
     72    },
     73    consoleAPICall: {
     74      message: Option(0, "json"),
     75      clonedFromContentProcess: Option(0, "nullable:boolean"),
     76    },
     77    reflowActivity: {
     78      interruptible: Option(0, "boolean"),
     79      start: Option(0, "number"),
     80      end: Option(0, "number"),
     81      sourceURL: Option(0, "nullable:string"),
     82      sourceLine: Option(0, "nullable:number"),
     83      functionName: Option(0, "nullable:string"),
     84    },
     85    // This event is modified re-emitted on the client as "networkEvent".
     86    // In order to avoid a naming collision, we rename the server event.
     87    serverNetworkEvent: {
     88      type: "networkEvent",
     89      eventActor: Option(0, "json"),
     90    },
     91    inspectObject: {
     92      objectActor: Option(0, "json"),
     93    },
     94    documentEvent: {
     95      name: Option(0, "string"),
     96      time: Option(0, "string"),
     97      hasNativeConsoleAPI: Option(0, "boolean"),
     98    },
     99  },
    100 
    101  methods: {
    102    /**
    103     * Start the given Web Console listeners.
    104     *
    105     * @see webconsoleFront LISTENERS
    106     * @param {Array} events
    107     *        Array of events you want to start. See this.LISTENERS for
    108     *        known events.
    109     */
    110    startListeners: {
    111      request: {
    112        listeners: Arg(0, "array:string"),
    113      },
    114      response: RetVal("console.startlisteners"),
    115    },
    116    /**
    117     * Stop the given Web Console listeners.
    118     *
    119     * @see webconsoleFront LISTENERS
    120     * @param {Array} events
    121     *        Array of events you want to stop. See this.LISTENERS for
    122     *        known events.
    123     * @param {Function} onResponse
    124     *        Function to invoke when the server response is received.
    125     */
    126    stopListeners: {
    127      request: {
    128        listeners: Arg(0, "nullable:array:string"),
    129      },
    130      response: RetVal("console.stoplisteners"),
    131    },
    132    /**
    133     * Retrieve the cached messages from the server.
    134     *
    135     * @see webconsoleFront CACHED_MESSAGES
    136     * @param {Array} types
    137     *        The array of message types you want from the server. See
    138     *        this.CACHED_MESSAGES for known types.
    139     */
    140    getCachedMessages: {
    141      request: {
    142        messageTypes: Arg(0, "array:string"),
    143      },
    144      // the return value here has a field "string" which can either be a longStringActor
    145      // or a plain string. Since we do not have union types, we cannot fully type this
    146      // response
    147      response: RetVal("console.cachedmessages"),
    148    },
    149    evaluateJSAsync: {
    150      request: {
    151        text: Option(0, "string"),
    152        frameActor: Option(0, "string"),
    153        url: Option(0, "string"),
    154        selectedNodeActor: Option(0, "string"),
    155        selectedObjectActor: Option(0, "string"),
    156        innerWindowID: Option(0, "number"),
    157        mapped: Option(0, "nullable:json"),
    158        eager: Option(0, "nullable:boolean"),
    159        disableBreaks: Option(0, "nullable:boolean"),
    160        preferConsoleCommandsOverLocalSymbols: Option(0, "nullable:boolean"),
    161        evalInTracer: Option(0, "nullable:boolean"),
    162      },
    163      response: RetVal("console.evaluatejsasync"),
    164    },
    165    /**
    166     * Autocomplete a JavaScript expression.
    167     *
    168     * @param {string} string
    169     *      The code you want to autocomplete.
    170     * @param {number} cursor
    171     *      Cursor location inside the string. Index starts from 0.
    172     * @param {string} frameActor
    173     *      The id of the frame actor that made the call.
    174     * @param {string} selectedNodeActor
    175     *      Actor id of the selected node in the inspector.
    176     * @param {Array} authorizedEvaluations
    177     *      Array of the properties access which can be executed by the engine.
    178     *      Example: [["x", "myGetter"], ["x", "myGetter", "y", "anotherGetter"]] to
    179     *      retrieve properties of `x.myGetter.` and `x.myGetter.y.anotherGetter`.
    180     */
    181    autocomplete: {
    182      request: {
    183        text: Arg(0, "string"),
    184        cursor: Arg(1, "nullable:number"),
    185        frameActor: Arg(2, "nullable:string"),
    186        selectedNodeActor: Arg(3, "nullable:string"),
    187        authorizedEvaluations: Arg(4, "nullable:json"),
    188        expressionVars: Arg(5, "nullable:json"),
    189      },
    190      response: RetVal("console.autocomplete"),
    191    },
    192 
    193    /**
    194     * Same as clearMessagesCache, but wait for the server response.
    195     */
    196    clearMessagesCacheAsync: {
    197      request: {},
    198    },
    199  },
    200 };
    201 
    202 const webconsoleSpec = generateActorSpec(webconsoleSpecPrototype);
    203 
    204 exports.webconsoleSpecPrototype = webconsoleSpecPrototype;
    205 exports.webconsoleSpec = webconsoleSpec;