Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

206
Visualizações
How to network throttle in iframe like we have a devtool

How to network throttle in iframe like we have in a devtool, let say want to open my own website inside iframe, and i want to throttle with a slow 3g mode how can we acheive this .

If i want to do this using chrome extension, is there any api to do this.

I have added the below code to enable the chrome debugger, but this is for the page or tab not for the particular iframe.

   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");
          }
        );
      }
    );
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

To throttle network for page we have to use tabId and for iframes we have to pass targetId in place of 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");
            }
          );
        });
      }
    );
  };```
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda