Get rid of --user-data-dir, search for url when attaching, add logs and test
This commit is contained in:
Родитель
8232921e18
Коммит
aee6dd2f23
|
@ -236,6 +236,10 @@ suite('Utilities', () => {
|
|||
const url = 'http://site.com/My/Cool/Site/script.js?stuff';
|
||||
testCanUrl(url, url);
|
||||
});
|
||||
|
||||
test('strips trailing slash', () => {
|
||||
testCanUrl('http://site.com/', 'http://site.com');
|
||||
});
|
||||
});
|
||||
|
||||
suite('remoteObjectToValue()', () => {
|
||||
|
|
|
@ -233,11 +233,13 @@ export function webkitUrlToClientUrl(cwd: string, url: string): string {
|
|||
* file:///Users/me/project/code.js => /Users/me/project/code.js
|
||||
* c:\scripts\code.js => c:/scripts/code.js
|
||||
* http://site.com/scripts/code.js => (no change)
|
||||
* http://site.com/ => http://site.com
|
||||
*/
|
||||
export function canonicalizeUrl(url: string): string {
|
||||
url = url
|
||||
.replace('file:///', '')
|
||||
.replace(/\\/g, '/'); // \ to /
|
||||
.replace(/\\/g, '/') // \ to /
|
||||
.replace(/\/$/, ''); // strip trailing slash
|
||||
|
||||
// Ensure osx path starts with /, it can be removed when file:/// was stripped.
|
||||
// Don't add if the url still has a protocol
|
||||
|
|
|
@ -120,35 +120,48 @@ export class WebKitConnection {
|
|||
/**
|
||||
* Attach the websocket to the first available tab in the chrome instance with the given remote debugging port number.
|
||||
*/
|
||||
public attach(port: number): Promise<void> {
|
||||
public attach(port: number, url?: string): Promise<void> {
|
||||
Logger.log('Attempting to attach on port ' + port);
|
||||
return utils.retryAsync(() => this._attach(port), 6000)
|
||||
return utils.retryAsync(() => this._attach(port, url), 6000)
|
||||
.then(() => this.sendMessage('Debugger.enable'))
|
||||
.then(() => this.sendMessage('Console.enable'))
|
||||
.then(() => { });
|
||||
}
|
||||
|
||||
public _attach(port: number): Promise<void> {
|
||||
return getUrl(`http://127.0.0.1:${port}/json`)
|
||||
.then(jsonResponse => {
|
||||
// Validate every step of processing the response
|
||||
try {
|
||||
const responseArray = JSON.parse(jsonResponse);
|
||||
if (Array.isArray(responseArray)) {
|
||||
const pages = responseArray.filter(target => target && target.type === 'page');
|
||||
if (pages.length) {
|
||||
const wsUrl = pages[0].webSocketDebuggerUrl;
|
||||
if (wsUrl) {
|
||||
return this._socket.attach(wsUrl);
|
||||
}
|
||||
public _attach(port: number, url?: string): Promise<void> {
|
||||
return getUrl(`http://127.0.0.1:${port}/json`).then(jsonResponse => {
|
||||
// Validate every step of processing the response
|
||||
try {
|
||||
const responseArray = JSON.parse(jsonResponse);
|
||||
if (Array.isArray(responseArray)) {
|
||||
let pages = responseArray.filter(target => target && target.type === 'page');
|
||||
if (url) {
|
||||
const urlPages = pages.filter(page => utils.canonicalizeUrl(page.url) === utils.canonicalizeUrl(url));
|
||||
if (!urlPages.length) {
|
||||
Logger.log(`Can't find a page with url: ` + url);
|
||||
} else {
|
||||
pages = urlPages;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// JSON.parse can throw
|
||||
}
|
||||
|
||||
return utils.errP('Got response, but no valid target pages found');
|
||||
});
|
||||
if (pages.length) {
|
||||
if (pages.length > 1) {
|
||||
Logger.log('Warning! Found more than one valid target page. Attaching to the first one.');
|
||||
Logger.log('pages: ' + JSON.stringify(pages.map(page => page.url)));
|
||||
}
|
||||
|
||||
const wsUrl = pages[0].webSocketDebuggerUrl;
|
||||
if (wsUrl) {
|
||||
return this._socket.attach(wsUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// JSON.parse can throw
|
||||
}
|
||||
|
||||
return utils.errP('Got response, but no valid target pages found');
|
||||
});
|
||||
}
|
||||
|
||||
public close(): void {
|
||||
|
|
|
@ -12,7 +12,6 @@ import {formatConsoleMessage} from './consoleHelper';
|
|||
|
||||
import {spawn, ChildProcess} from 'child_process';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
|
||||
export class WebKitDebugAdapter implements IDebugAdapter {
|
||||
private static THREAD_ID = 1;
|
||||
|
@ -82,20 +81,22 @@ export class WebKitDebugAdapter implements IDebugAdapter {
|
|||
const port = args.port || 9222;
|
||||
const chromeArgs: string[] = ['--remote-debugging-port=' + port];
|
||||
|
||||
// Also start with extra stuff disabled, and user-data-dir in tmp directory
|
||||
chromeArgs.push(...['--no-first-run', '--no-default-browser-check', `--user-data-dir=${os.tmpdir() }/webkitdebugadapter${Date.now() }`]);
|
||||
// Also start with extra stuff disabled
|
||||
chromeArgs.push(...['--no-first-run', '--no-default-browser-check']);
|
||||
if (args.runtimeArguments) {
|
||||
chromeArgs.push(...args.runtimeArguments);
|
||||
}
|
||||
|
||||
let launchUrl: string;
|
||||
if (args.file) {
|
||||
chromeArgs.push(path.resolve(args.cwd, args.file));
|
||||
launchUrl = path.resolve(args.cwd, args.file);
|
||||
} else if (args.url) {
|
||||
chromeArgs.push(args.url);
|
||||
launchUrl = args.url;
|
||||
} else {
|
||||
return utils.errP('The launch config must specify either the "file" or "url" field.');
|
||||
}
|
||||
|
||||
chromeArgs.push(launchUrl);
|
||||
Logger.log(`spawn('${chromePath}', ${JSON.stringify(chromeArgs) })`);
|
||||
this._chromeProc = spawn(chromePath, chromeArgs);
|
||||
this._chromeProc.on('error', (err) => {
|
||||
|
@ -103,7 +104,7 @@ export class WebKitDebugAdapter implements IDebugAdapter {
|
|||
this.terminateSession();
|
||||
});
|
||||
|
||||
return this._attach(port);
|
||||
return this._attach(port, launchUrl);
|
||||
}
|
||||
|
||||
public attach(args: IAttachRequestArgs): Promise<void> {
|
||||
|
@ -122,7 +123,7 @@ export class WebKitDebugAdapter implements IDebugAdapter {
|
|||
return this._attach(args.port);
|
||||
}
|
||||
|
||||
private _attach(port: number): Promise<void> {
|
||||
private _attach(port: number, url?: string): Promise<void> {
|
||||
// ODP client is attaching - if not attached to the webkit target, create a connection and attach
|
||||
this._clientAttached = true;
|
||||
if (!this._webKitConnection) {
|
||||
|
@ -139,7 +140,7 @@ export class WebKitDebugAdapter implements IDebugAdapter {
|
|||
this._webKitConnection.on('close', () => this.terminateSession());
|
||||
this._webKitConnection.on('error', () => this.terminateSession());
|
||||
|
||||
return this._webKitConnection.attach(port)
|
||||
return this._webKitConnection.attach(port, url)
|
||||
.then(
|
||||
() => this.fireEvent(new InitializedEvent()),
|
||||
e => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче