network-overrides.js (1555B)
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 DevToolsUtils = require("resource://devtools/shared/DevToolsUtils.js"); 8 9 exports.setNetworkOverride = setNetworkOverride; 10 function setNetworkOverride(commands, url, data, win) { 11 return async function ({ dispatch }) { 12 const filename = url.split("/").at(-1); 13 if (typeof data == "string") { 14 data = new TextEncoder().encode(data); 15 } 16 17 const path = await DevToolsUtils.saveAs(win, data, filename); 18 if (path) { 19 const hasWatcherSupport = 20 commands.targetCommand.hasTargetWatcherSupport(); 21 if (hasWatcherSupport) { 22 const networkFront = 23 await commands.targetCommand.watcherFront.getNetworkParentActor(); 24 await networkFront.override(url, path); 25 dispatch({ 26 type: "SET_NETWORK_OVERRIDE", 27 url, 28 path, 29 }); 30 } 31 } 32 }; 33 } 34 35 exports.removeNetworkOverride = removeNetworkOverride; 36 function removeNetworkOverride(commands, url) { 37 return async function ({ dispatch }) { 38 const hasWatcherSupport = commands.targetCommand.hasTargetWatcherSupport(); 39 if (hasWatcherSupport) { 40 const networkFront = 41 await commands.targetCommand.watcherFront.getNetworkParentActor(); 42 await networkFront.removeOverride(url); 43 dispatch({ 44 type: "REMOVE_NETWORK_OVERRIDE", 45 url, 46 }); 47 } 48 }; 49 }