mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-01 01:38:07 +08:00
devtools:// scheme This change replaces the chrome-devtools:// URL scheme, with a more browser-agnostic equivalent. Naturally, many files had to be touched, but it's mostly a straightforward find/replace. A related change is out against the catapult repo here: https://chromium-review.googlesource.com/c/catapult/+/1606268, which removes a test file containing the old scheme. Once it goes in, the root DEPS file in the chromium repo needs to be updated as well. Note: This is a continuation of patch 1552143, but since Fabio is out on leave and I don't have permissions to upload to his patch, I needed to start a new one. Bug: 960409 Change-Id: I3ede7f8d1dcbca457167eb3641ae60e9685d8d78 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1582881 Commit-Queue: James Lissiak <jalissia@microsoft.com> Reviewed-by: Joel Einbinder <einbinder@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: Scott Violet <sky@chromium.org> Reviewed-by: Charlie Reis <creis@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#659944} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 28b21a67f09a13c465b73776aecd9995d8a07737
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`;
|
|
}
|