ext-devtools-inspectedWindow.js (1867B)
1 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ 2 /* vim: set sts=2 sw=2 et tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 "use strict"; 8 9 var { SpreadArgs } = ExtensionCommon; 10 11 this.devtools_inspectedWindow = class extends ExtensionAPI { 12 getAPI(context) { 13 // TODO - Bug 1448878: retrieve a more detailed callerInfo object, 14 // like the filename and lineNumber of the actual extension called 15 // in the child process. 16 const callerInfo = { 17 addonId: context.extension.id, 18 url: context.extension.baseURI.spec, 19 }; 20 21 return { 22 devtools: { 23 inspectedWindow: { 24 async eval(expression, options) { 25 const toolboxEvalOptions = await getToolboxEvalOptions(context); 26 const evalOptions = Object.assign({}, options, toolboxEvalOptions); 27 28 const commands = await context.getDevToolsCommands(); 29 const evalResult = await commands.inspectedWindowCommand.eval( 30 callerInfo, 31 expression, 32 evalOptions 33 ); 34 35 // TODO(rpl): check for additional undocumented behaviors on chrome 36 // (e.g. if we should also print error to the console or set lastError?). 37 return new SpreadArgs([evalResult.value, evalResult.exceptionInfo]); 38 }, 39 async reload(options) { 40 const { ignoreCache, userAgent, injectedScript } = options || {}; 41 42 const commands = await context.getDevToolsCommands(); 43 commands.inspectedWindowCommand.reload(callerInfo, { 44 ignoreCache, 45 userAgent, 46 injectedScript, 47 }); 48 }, 49 }, 50 }, 51 }; 52 } 53 };