mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-11 06:04:55 +08:00
This reverts commit e4d2472814.
Reason for revert: Further discussions are needed to ensure
consistency between DevTools and Lighthouse on how to calculate
kb/MB.
Original change's description:
> Use 1000 not 1024 for kB and MB calculations
>
> This removes the usage of the number 1024 for the calculation of kB and
> MB values. Instead the correct value of 1000 is used.
> The changes mostly affect the file/transfer size values seen in the
> network tab (screenshot: https://imgur.com/a/cDqxScS).
>
> Bug: chromium:1035309
> Change-Id: Ic3fe4fc6536326d44fc9f838189db9b0c19d0955
> Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2062606
> Commit-Queue: Wolfgang Beyer <wolfi@chromium.org>
> Reviewed-by: Mathias Bynens <mathias@chromium.org>
TBR=mathias@chromium.org,wolfi@chromium.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: chromium:1035309
Change-Id: I60dd9be51a097166889db9d7206ad251be6d2235
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2071878
Commit-Queue: Wolfgang Beyer <wolfi@chromium.org>
Reviewed-by: Wolfgang Beyer <wolfi@chromium.org>
70 lines
2.7 KiB
JavaScript
70 lines
2.7 KiB
JavaScript
const path = require('path');
|
|
const fs = require('fs');
|
|
const puppeteer = require('puppeteer');
|
|
const childProcess = require('child_process');
|
|
const CHROMIUM_DEFAULT_PATH = path.resolve(__dirname, '..', '..', '..', '..', '..', '..', 'out', 'Release', 'chrome');
|
|
|
|
(async function() {
|
|
const targetRevision = process.argv[2];
|
|
if (!targetRevision || String(parseInt(targetRevision, 10)) !== targetRevision) {
|
|
console.log('The first argument should be a Chromium revision number, like 338865');
|
|
return;
|
|
}
|
|
const info = await downloadChrome(targetRevision);
|
|
childProcess.exec(`${info.executablePath} --remote-debugging-port=9227 --user-data-dir=user-data-dir about:blank`);
|
|
const browser = await puppeteer.launch({
|
|
executablePath: process.env.CHROMIUM_PATH || CHROMIUM_DEFAULT_PATH,
|
|
dumpio: true,
|
|
defaultViewport: null,
|
|
ignoreDefaultArgs: true,
|
|
args: puppeteer.defaultArgs({
|
|
headless: false,
|
|
args: ['--no-default-browser-check', `--custom-devtools-frontend=http://localhost:9227/devtools/`],
|
|
userDataDir: 'debugging-user-data-dir'
|
|
}).filter(x => !x.startsWith('--enable-automation'))
|
|
});
|
|
const page = (await browser.pages())[0];
|
|
await page.goto('http://localhost:9227');
|
|
const chromeVersion = await page.evaluate(async () => {
|
|
const data = await fetch('json/version');
|
|
const json = await data.json();
|
|
const userAgent = json['User-Agent'];
|
|
const start = userAgent.indexOf('Chrome/') + 'Chrome/'.length;
|
|
return userAgent.substring(start, userAgent.indexOf(' ', start));
|
|
});
|
|
console.log(`Launched Chromium ${chromeVersion}`);
|
|
await page.bringToFront();
|
|
await page.waitForSelector('a');
|
|
const realURL = await page.evaluate(() => document.querySelector('a').href);
|
|
|
|
const path = realURL.substring('http://localhost:9227/devtools/'.length);
|
|
const url = `devtools://devtools/custom/${path}&remoteVersion=${chromeVersion}`;
|
|
|
|
await page.goto(url);
|
|
})();
|
|
|
|
async function downloadChrome(revision) {
|
|
const fetcher = puppeteer.createBrowserFetcher();
|
|
let progressBar = null;
|
|
let lastDownloadedBytes = 0;
|
|
return await fetcher.download(revision, (downloadedBytes, totalBytes) => {
|
|
if (!progressBar) {
|
|
const ProgressBar = require('progress');
|
|
progressBar = new ProgressBar(`Downloading Chromium r${revision} - ${toMegabytes(totalBytes)} [:bar] :percent :etas `, {
|
|
complete: '=',
|
|
incomplete: ' ',
|
|
width: 20,
|
|
total: totalBytes,
|
|
});
|
|
}
|
|
const delta = downloadedBytes - lastDownloadedBytes;
|
|
lastDownloadedBytes = downloadedBytes;
|
|
progressBar.tick(delta);
|
|
});
|
|
}
|
|
|
|
function toMegabytes(bytes) {
|
|
const mb = bytes / 1024 / 1024;
|
|
return `${Math.round(mb * 10) / 10} Mb`;
|
|
}
|