Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: third_party/WebKit/Source/devtools/scripts/chrome_debug_launcher/launch_chrome.js

Issue 2493573003: DevTools: improve launch chrome (add --reset-profile option) (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var childProcess = require("child_process"); 5 var childProcess = require("child_process");
6 var fs = require("fs"); 6 var fs = require("fs");
7 var path = require("path"); 7 var path = require("path");
8 var shell = childProcess.execSync; 8 var shell = childProcess.execSync;
9 9
10 var remoteDebuggingPort = parseInt(process.env.REMOTE_DEBUGGING_PORT, 10) || 922 2; 10 var utils = require("../utils");
11 var serverPort = parseInt(process.env.PORT, 10) || 8090; 11
12 var REMOTE_DEBUGGING_PORT = parseInt(process.env.REMOTE_DEBUGGING_PORT, 10) || 9 222;
13 var SERVER_PORT = parseInt(process.env.PORT, 10) || 8090;
14 var CHROMIUM_DEFAULT_PATH = path.resolve(__dirname, "..", "..", "..", "..", ".." , "..", "out", "Release", "chrome");
15 var CHROME_PROFILE_PATH = path.resolve(__dirname, "..", "..", ".dev_profile");
16
17 var Flags = {
18 RESET_PROFILE: "--reset-profile",
19 };
20
21 if (utils.includes(process.argv, Flags.RESET_PROFILE)) {
22 console.log(`Removing your dev profile for Chrome Canary / Chromium at:`);
23 console.log(CHROME_PROFILE_PATH, "\n");
24 utils.removeRecursive(CHROME_PROFILE_PATH);
25 }
12 26
13 var chromeArgs = [ 27 var chromeArgs = [
14 `--remote-debugging-port=${remoteDebuggingPort}`, 28 `--remote-debugging-port=${REMOTE_DEBUGGING_PORT}`,
15 `--custom-devtools-frontend=http://localhost:${serverPort}/front_end/`, 29 `--custom-devtools-frontend=http://localhost:${SERVER_PORT}/front_end/`,
16 `--no-first-run`, 30 `--no-first-run`,
17 `http://localhost:${remoteDebuggingPort}#custom=true&experiments=true`, 31 '--enable-devtools-experiments',
18 `https://devtools.chrome.com` 32 `http://localhost:${REMOTE_DEBUGGING_PORT}#custom=true&experiments=true`,
33 `https://devtools.chrome.com`,
34 `--user-data-dir=${CHROME_PROFILE_PATH}`
19 ].concat(process.argv.slice(2)); 35 ].concat(process.argv.slice(2));
20 36
21 if (process.platform === "win32") { 37 if (process.platform === "win32") {
22 launchChromeWindows(); 38 launchChromeWindows();
23 return; 39 return;
24 } 40 }
25 if (process.platform === "darwin") { 41 if (process.platform === "darwin") {
26 launchChromeMac(); 42 launchChromeMac();
27 return; 43 return;
28 } 44 }
(...skipping 19 matching lines...) Expand all
48 } 64 }
49 } 65 }
50 launchChrome(chromeCanaryPath, chromeArgs); 66 launchChrome(chromeCanaryPath, chromeArgs);
51 } 67 }
52 68
53 function launchChromeMac() 69 function launchChromeMac()
54 { 70 {
55 var lsregister = "/System/Library/Frameworks/CoreServices.framework/Versions /A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister"; 71 var lsregister = "/System/Library/Frameworks/CoreServices.framework/Versions /A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister";
56 var chromeCanaryPath = shellOutput(`${lsregister} -dump | grep -i 'applicati ons/google chrome canary.app$' | awk '{$1=""; print $0}' | head -n 1`); 72 var chromeCanaryPath = shellOutput(`${lsregister} -dump | grep -i 'applicati ons/google chrome canary.app$' | awk '{$1=""; print $0}' | head -n 1`);
57 var chromeCanaryExecPath = `${chromeCanaryPath}/Contents/MacOS/Google Chrome Canary`; 73 var chromeCanaryExecPath = `${chromeCanaryPath}/Contents/MacOS/Google Chrome Canary`;
58 var tmpProfileDir = shellOutput("mktemp -d -t devtools"); 74 launchChrome(chromeCanaryExecPath, chromeArgs);
59 chromeArgs.push(`--user-data-dir=${tmpProfileDir}`);
60 launchChrome(chromeCanaryExecPath, chromeArgs, () => shell(`rm -r ${tmpProfi leDir}`));
61 } 75 }
62 76
63 function launchChromeLinux() 77 function launchChromeLinux()
64 { 78 {
65 var tmpProfileDir = shellOutput("mktemp -d -t devtools.XXXXXXXXXX"); 79 var chromiumPath;
66 chromeArgs.push(`--user-data-dir=${tmpProfileDir}`); 80 if (utils.isFile(process.env.CHROMIUM_PATH))
67 launchChrome(process.env.CHROMIUM_PATH, chromeArgs, () => shell(`rm -r ${tmp ProfileDir}`)); 81 chromiumPath = process.env.CHROMIUM_PATH;
82 else if (utils.isFile(CHROMIUM_DEFAULT_PATH)) {
83 chromiumPath = CHROMIUM_DEFAULT_PATH;
84 } else {
85 onLaunchChromeError();
86 return;
87 }
88 launchChrome(chromiumPath, chromeArgs);
68 } 89 }
69 90
70 function launchChrome(filePath, chromeArgs, cleanup) 91 function launchChrome(filePath, chromeArgs)
71 { 92 {
72 console.log(`Launching Chrome from ${filePath}`); 93 console.log(`Launching Chrome from ${filePath}`);
73 console.log("Chrome args:", chromeArgs.join(" "), "\n"); 94 console.log("Chrome args:", chromeArgs.join(" "), "\n");
74 var child; 95 var child;
75 try { 96 try {
76 child = childProcess.spawn(filePath, chromeArgs, { 97 child = childProcess.spawn(filePath, chromeArgs, {
77 stdio: "ignore", 98 stdio: "ignore",
78 }); 99 });
79 } catch (error) { 100 } catch (error) {
80 onLaunchChromeError(); 101 onLaunchChromeError();
81 if (cleanup)
82 cleanup();
83 return; 102 return;
84 } 103 }
85 child.on("error", onLaunchChromeError); 104 child.on("error", onLaunchChromeError);
86 child.on("exit", onExit); 105 child.on("exit", onExit);
87 function onExit(code) 106 function onExit(code)
88 { 107 {
89 if (cleanup)
90 cleanup();
91 console.log("Exited Chrome with code", code); 108 console.log("Exited Chrome with code", code);
92 } 109 }
93 } 110 }
94 111
95 function onLaunchChromeError() 112 function onLaunchChromeError()
96 { 113 {
97 if (process.platform !== "linux") { 114 if (process.platform !== "linux") {
98 console.log("Cannot find Chrome Canary on your computer"); 115 console.log("ERROR: Cannot find Chrome Canary on your computer");
99 console.log("Install Chome Canary at:"); 116 console.log("Install Chome Canary at:");
100 console.log("https://www.google.com/chrome/browser/canary.html\n"); 117 console.log("https://www.google.com/chrome/browser/canary.html\n");
101 } else { 118 } else {
119 console.log("ERROR: Could not launch Chromium");
102 console.log("The environment variable CHROMIUM_PATH must be set to execu table of a build of Chromium"); 120 console.log("The environment variable CHROMIUM_PATH must be set to execu table of a build of Chromium");
103 console.log("If you do not have a recent build of chromium, you can get one from:"); 121 console.log("If you do not have a recent build of chromium, you can get one from:");
104 console.log("https://download-chromium.appspot.com/\n"); 122 console.log("https://download-chromium.appspot.com/\n");
105 } 123 }
106 } 124 }
107 125
108 function print(buffer) 126 function print(buffer)
109 { 127 {
110 var string = buffer.toString(); 128 var string = buffer.toString();
111 console.log(string); 129 console.log(string);
112 return string; 130 return string;
113 } 131 }
114 132
115 function shellOutput(command) 133 function shellOutput(command)
116 { 134 {
117 return shell(command).toString().trim(); 135 return shell(command).toString().trim();
118 } 136 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698