xhr-breakpoints.js (1092B)
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 STATES: THREAD_STATES, 9 } = require("resource://devtools/server/actors/thread.js"); 10 11 module.exports = { 12 async addOrSetSessionDataEntry( 13 targetActor, 14 entries, 15 isDocumentCreation, 16 updateType 17 ) { 18 const { threadActor } = targetActor; 19 if (updateType == "set") { 20 threadActor.removeAllXHRBreakpoints(); 21 } 22 23 // The thread actor has to be initialized in order to correctly 24 // retrieve the stack trace when hitting an XHR 25 if (threadActor.state == THREAD_STATES.DETACHED) { 26 await threadActor.attach(); 27 } 28 29 await Promise.all( 30 entries.map(({ path, method }) => 31 threadActor.setXHRBreakpoint(path, method) 32 ) 33 ); 34 }, 35 36 removeSessionDataEntry(targetActor, entries) { 37 for (const { path, method } of entries) { 38 targetActor.threadActor.removeXHRBreakpoint(path, method); 39 } 40 }, 41 };