Cómo acelerar en red en iframe como lo tenemos en una herramienta de desarrollo, digamos que quiero abrir mi propio sitio web dentro de iframe, y quiero acelerar con un modo 3g lento, ¿cómo podemos lograrlo?
Si quiero hacer esto usando la extensión de Chrome, ¿hay alguna API para hacer esto?
He agregado el siguiente código para habilitar el depurador de Chrome, pero esto es para la página o pestaña, no para el iframe en particular.
await chrome.tabs.query( { currentWindow: true, active: true }, function (tabs) { console.log("tabs--->", tabs); console.log(tabs[0].id); chrome.debugger.attach({ tabId: "8C206DBB36086B4E52EB465197CE01ED" }, "1.3", () => { if (chrome.runtime.lastError) { console.log("runtime.lastError", chrome.runtime.lastError.message); return; } console.log("Debugger attached"); }); chrome.debugger.sendCommand( { tabId: tabs[0].id }, "Network.enable", () => { if (chrome.runtime.lastError) { console.log( "runtime.lastError", chrome.runtime.lastError.message ); return; } console.log("Debugger attached"); } ); const newtworkThrottleValues = { offline: { downloadThroughput: 0, uploadThroughput: 0, latency: 0, offline: true, }, slow3G: { downloadThroughput: ((500 * 1024) / 8) * 0.8, uploadThroughput: ((500 * 1024) / 8) * 0.8, latency: 400 * 5, offline: false, }, fast3G: { downloadThroughput: ((1.6 * 1024 * 1024) / 8) * 0.9, uploadThroughput: ((750 * 1024) / 8) * 0.9, latency: 150 * 3.75, offline: false, }, online: { downloadThroughput: -1, uploadThroughput: -1, latency: 0, offline: false, }, }; chrome.debugger.getTargets((result) => { console.log("result", result); }); chrome.tabs.query( { currentWindow: true, active: true }, function (tabs) { settabid(tabs[0].id); console.log(tabs[0]); } ); chrome.debugger.sendCommand( { tabId: tabs[0].id }, "Network.emulateNetworkConditions", newtworkThrottleValues["offline"], () => { if (chrome.runtime.lastError) { console.log( "runtime.lastError", chrome.runtime.lastError.message ); return; } console.log("Debugger attached 3"); } ); } );Para acelerar la red para la página, tenemos que usar tabId y para iframes tenemos que pasar targetId en lugar de tabId
chrome.tabs.query( { currentWindow: true, active: true }, function async(tabs) { await chrome.debugger.getTargets(async (result) => { const d = result.filter((value) => value.url.includes("url")); await chrome.debugger.attach( { tabId: tabs[0].id,}, "1.3", () => { if (chrome.runtime.lastError) { console.log( "runtime.lastError", chrome.runtime.lastError.message ); return; } console.log("Debugger attached"); } ); await chrome.debugger.sendCommand( { tabId: tabs[0].id }, "Network.enable", () => { if (chrome.runtime.lastError) { console.log( "runtime.lastError", chrome.runtime.lastError.message ); return; } console.log("Debugger attached"); } ); const newtworkThrottleValues = { offline: { downloadThroughput: 0, uploadThroughput: 0, latency: 0, offline: true, }, slow3G: { downloadThroughput: ((500 * 1024) / 8) * 0.8, uploadThroughput: ((500 * 1024) / 8) * 0.8, latency: 400 * 5, offline: false, }, fast3G: { downloadThroughput: ((1.6 * 1024 * 1024) / 8) * 0.9, uploadThroughput: ((750 * 1024) / 8) * 0.9, latency: 150 * 3.75, offline: false, }, online: { downloadThroughput: -1, uploadThroughput: -1, latency: 0, offline: false, }, }; await chrome.debugger.sendCommand( { tabId: tabs[0].id }, "Network.emulateNetworkConditions", newtworkThrottleValues["offline"], () => { if (chrome.runtime.lastError) { console.log( "runtime.lastError", chrome.runtime.lastError.message ); return; } console.log("Debugger attached 3"); } ); }); } ); };```