From eabfa5d375ede317517481207a6de40ca46a15a9 Mon Sep 17 00:00:00 2001 From: blagoev Date: Sun, 18 Dec 2016 12:34:26 +0200 Subject: [PATCH 1/3] added vscode-chrome-debug-core as dependency formated androidConnection --- package.json | 1 + .../connection/androidConnection.ts | 83 ++++++++++--------- 2 files changed, 44 insertions(+), 40 deletions(-) diff --git a/package.json b/package.json index bd5d0d4..3ad3bf1 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ ], "license": "SEE LICENSE IN LICENSE.txt", "dependencies": { + "vscode-chrome-debug-core": "3.9.1", "node-ipc": "^8.9.2", "source-map": "^0.5.3", "xmlhttprequest": "https://github.com/telerik/node-XMLHttpRequest/tarball/master", diff --git a/src/debug-adapter/connection/androidConnection.ts b/src/debug-adapter/connection/androidConnection.ts index 760a267..2acb255 100644 --- a/src/debug-adapter/connection/androidConnection.ts +++ b/src/debug-adapter/connection/androidConnection.ts @@ -1,9 +1,11 @@ import * as http from 'http'; -import {EventEmitter} from 'events'; -import {Services} from '../../services/debugAdapterServices'; +import { EventEmitter } from 'events'; +import { Services } from '../../services/debugAdapterServices'; import * as Net from 'net'; import { INSDebugConnection } from './INSDebugConnection'; +import { ChromeConnection } from 'vscode-chrome-debug-core'; + interface IMessageWithId { id: number; @@ -17,7 +19,7 @@ class Callbacks { public wrap(callback: any): number { var callbackId = this.lastId++; - this.callbacks[callbackId] = callback || function() { }; + this.callbacks[callbackId] = callback || function () { }; return callbackId; } @@ -60,7 +62,7 @@ class ResReqNetSocket extends EventEmitter { return new Promise((resolve, reject) => { that.conn = Net.createConnection(port, url), - that.conn.setEncoding('utf8'); + that.conn.setEncoding('utf8'); setTimeout(() => { reject('Connection timed out') @@ -68,7 +70,7 @@ class ResReqNetSocket extends EventEmitter { that.conn.on('error', reject); - that.conn.on('connect', function() { + that.conn.on('connect', function () { // Replace the promise-rejecting handler that.conn.removeListener('error', reject); @@ -89,23 +91,22 @@ class ResReqNetSocket extends EventEmitter { that.emit('error', e); }); - that.conn.on('data', function(data) { + that.conn.on('data', function (data) { that.debugBuffer += data; - that.parse(function() { - that.connected = true; - that.emit('connect'); - resolve(); + that.parse(function () { + that.connected = true; + that.emit('connect'); + resolve(); }); }); - that.conn.on('end', function() { + that.conn.on('end', function () { that.close(); }); - that.conn.on('close', function() { - if (!that.connected) - { + that.conn.on('close', function () { + if (!that.connected) { reject("Can't connect. Check the application is running on the device"); that.emit('close', that.lastError || 'Debugged process exited.'); return; @@ -184,7 +185,7 @@ class ResReqNetSocket extends EventEmitter { Services.logger().log('To target: ' + data); this.conn.write('Content-Length: ' + data.length + '\r\n\r\n' + data); this.hasNewDataMessage = true; - if (!this.isMessageFlushLoopStarted) { + if (!this.isMessageFlushLoopStarted) { this.isMessageFlushLoopStarted = true; setInterval(() => { if (this.hasNewDataMessage) { @@ -209,13 +210,17 @@ class ResReqNetSocket extends EventEmitter { } if (params) { - Object.keys(params).forEach(function(key) { + Object.keys(params).forEach(function (key) { msg[key] = params[key]; }); } this.send(JSON.stringify(msg)); } + public sendMessage(message: any) { + this.send(message); + } + public close() { if (this.conn) { this.conn.end(); @@ -235,7 +240,7 @@ export class AndroidConnection implements INSDebugConnection { let that = this; this._socket = new ResReqNetSocket(); - this._socket.on("afterCompile", function(params) { + this._socket.on("afterCompile", function (params) { let scriptData = { scriptId: String(params.body.script.id), @@ -248,15 +253,15 @@ export class AndroidConnection implements INSDebugConnection { }); - this._socket.on("break", function(params) { + this._socket.on("break", function (params) { that.handleBreakEvent(params); }); - this._socket.on("exception", function(params) { + this._socket.on("exception", function (params) { that.handleBreakEvent(params); }); - this._socket.on("messageAdded", function(params) { + this._socket.on("messageAdded", function (params) { that._socket.emit("Console.messageAdded", params.body); }); } @@ -342,7 +347,7 @@ export class AndroidConnection implements INSDebugConnection { if (name && name.length > 1) { desc = name[1]; if (desc === 'Array' || desc === 'Buffer') { - size = ref.properties.filter(function(p) { return /^\d+$/.test(p.name); }).length; + size = ref.properties.filter(function (p) { return /^\d+$/.test(p.name); }).length; desc += '[' + size + ']'; } } else if (ref.className === 'Date') { @@ -400,8 +405,8 @@ export class AndroidConnection implements INSDebugConnection { }) .then(response => { var debuggerFrames = >response.frames || []; - let frames = debuggerFrames.map(function(frame) { - var scopeChain = frame.scopes.map(function(scope) { + let frames = debuggerFrames.map(function (frame) { + var scopeChain = frame.scopes.map(function (scope) { return { object: { type: 'object', @@ -481,7 +486,7 @@ export class AndroidConnection implements INSDebugConnection { return this.request("clearbreakpoint", { breakpoint: breakpointId - }) + }) .then(response => { return {}; }); @@ -568,9 +573,9 @@ export class AndroidConnection implements INSDebugConnection { let that = this; return this.request("evaluate", requestParams).then(response => { return { - result: { - result : that.v8ResultToInspectorResult(response), - wasThrown : false + result: { + result: that.v8ResultToInspectorResult(response), + wasThrown: false } } }); @@ -615,12 +620,10 @@ export class AndroidConnection implements INSDebugConnection { } let source = undefined; - if (Array.isArray(response)) - { + if (Array.isArray(response)) { source = response[0].source; } - else if (response.result) - { + else if (response.result) { source = response.result[0].source; } else if (response.source) { @@ -653,7 +656,7 @@ export class AndroidConnection implements INSDebugConnection { if (response.refs) { let refsLookup = {}; - response.refs.forEach(function(r) { refsLookup[r.handle] = r; }); + response.refs.forEach(function (r) { refsLookup[r.handle] = r; }); //TODO: response.body may be undefined in that case set it to {} here response.body.refsLookup = refsLookup; @@ -748,7 +751,7 @@ export class AndroidConnection implements INSDebugConnection { props = obj.properties; if (props) { - props = props.map(function(p) { + props = props.map(function (p) { var ref = response.refsLookup[p.ref]; return { name: String(p.name), @@ -776,13 +779,13 @@ export class AndroidConnection implements INSDebugConnection { throw new Error("Not implemented"); } - // private sendMessage(method: any, params?: any): Promise { - // return this._socket.sendMessage({ - // id: this._nextId++, - // method, - // params - // }); - // } + private sendMessage(method: any, params?: any): Promise { + return this._socket.sendMessage({ + id: this._nextId++, + method, + params + }); + } } /** From 98ce64c10708c96e49263f1c2edf715b626daa5a Mon Sep 17 00:00:00 2001 From: blagoev Date: Mon, 19 Dec 2016 14:16:14 +0200 Subject: [PATCH 2/3] pass arguments to getDebugPort to be able to specify --device correctly --- src/project/androidProject.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/project/androidProject.ts b/src/project/androidProject.ts index 7b42e0f..a36ad91 100644 --- a/src/project/androidProject.ts +++ b/src/project/androidProject.ts @@ -43,8 +43,10 @@ export class AndroidProject extends Project { return { tnsProcess: debugProcess, tnsOutputEventEmitter: tnsOutputEventEmitter }; } - public getDebugPortSync(): number { - let output = this.cli.executeSync(["debug", "android", "--get--port"], this.appRoot); + public getDebugPortSync(tnsArgs?: string[]): number { + let args: string[] = []; + args = args.concat(tnsArgs); + let output = this.cli.executeSync(["debug", "android", "--get--port"].concat(args), this.appRoot); let port = parseInt(output.match("(?:debug port: )([\\d]{5})")[1]); return port; } From 579b351b369b668ef6df9e3c94c10b798c6308cc Mon Sep 17 00:00:00 2001 From: blagoev Date: Fri, 23 Dec 2016 17:50:45 +0200 Subject: [PATCH 3/3] initial support for the new v8 inspector debugger for android --- package.json | 3 +- src/debug-adapter/adapter/pathTransformer.ts | 11 +- .../connection/INSDebugConnection.ts | 5 + .../connection/androidConnection.ts | 439 ++++++++++++------ src/debug-adapter/connection/iosConnection.ts | 4 + src/debug-adapter/webKitDebugAdapter.ts | 14 +- 6 files changed, 320 insertions(+), 156 deletions(-) diff --git a/package.json b/package.json index 3ad3bf1..bc96980 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,8 @@ "typescript": "^2.0.6", "vsce": "^1.0.0", "vscode": "^1.0.3", - "vscode-debugadapter-testsupport": "^1.7.0" + "vscode-debugadapter-testsupport": "^1.7.0", + "chrome-remote-debug-protocol": "git://github.com/roblourens/chrome-remote-debug-protocol.git" }, "scripts": { "clean": "git clean -fdx", diff --git a/src/debug-adapter/adapter/pathTransformer.ts b/src/debug-adapter/adapter/pathTransformer.ts index 5470739..1c612f3 100644 --- a/src/debug-adapter/adapter/pathTransformer.ts +++ b/src/debug-adapter/adapter/pathTransformer.ts @@ -96,11 +96,14 @@ export class PathTransformer implements DebugProtocol.IDebugTransformer { if (!this.inferedDeviceRoot && this._platform === "android") { this.inferedDeviceRoot = utils.inferDeviceRoot(this._appRoot, this._platform, webkitUrl); - Services.logger().log("\n\n\n ***Inferred device root: " + this.inferedDeviceRoot + "\n\n\n"); - - if (this.inferedDeviceRoot.indexOf("/data/user/0/") != -1) + if (this.inferedDeviceRoot) { - this.inferedDeviceRoot = this.inferedDeviceRoot.replace("/data/user/0/", "/data/data/"); + Services.logger().log("\n\n\n ***Inferred device root: " + this.inferedDeviceRoot + "\n\n\n"); + + if (this.inferedDeviceRoot.indexOf("/data/user/0/") != -1) + { + this.inferedDeviceRoot = this.inferedDeviceRoot.replace("/data/user/0/", "/data/data/"); + } } } diff --git a/src/debug-adapter/connection/INSDebugConnection.ts b/src/debug-adapter/connection/INSDebugConnection.ts index 082da3a..85d67c4 100644 --- a/src/debug-adapter/connection/INSDebugConnection.ts +++ b/src/debug-adapter/connection/INSDebugConnection.ts @@ -1,4 +1,9 @@ export interface INSDebugConnection { + + attach(target: number | string, url?: string): Promise + + enable() : Promise; + on(eventName: string, handler: (msg: any) => void): void; close(): void; diff --git a/src/debug-adapter/connection/androidConnection.ts b/src/debug-adapter/connection/androidConnection.ts index 2acb255..1d8b05b 100644 --- a/src/debug-adapter/connection/androidConnection.ts +++ b/src/debug-adapter/connection/androidConnection.ts @@ -4,8 +4,8 @@ import { Services } from '../../services/debugAdapterServices'; import * as Net from 'net'; import { INSDebugConnection } from './INSDebugConnection'; -import { ChromeConnection } from 'vscode-chrome-debug-core'; - +import { ChromeConnection, logger } from 'vscode-chrome-debug-core'; +import Crdp from 'vscode-chrome-debug-core/lib/crdp/crdp'; interface IMessageWithId { id: number; @@ -234,12 +234,20 @@ export class AndroidConnection implements INSDebugConnection { //private _socket: ResReqWebSocket; //private _socket: ResReqHttpSocket; private _socket: ResReqNetSocket; + private _chromeConnection: ChromeConnection; constructor() { + + this._chromeConnection = new ChromeConnection(this.createWebSocketAddress); + logger.init(null, null, true); + logger.setMinLogLevel(logger.LogLevel.Verbose); + //this._socket = new ResReqWebSocket(); let that = this; this._socket = new ResReqNetSocket(); + + this._socket.on("afterCompile", function (params) { let scriptData = { @@ -266,6 +274,15 @@ export class AndroidConnection implements INSDebugConnection { }); } + private createWebSocketAddress(address: string, port: number, targetFilter?: any, targetUrl?: string): Promise + { + return Promise.resolve(`ws://${address}:${port}`); + } + + private get chrome(): Crdp.CrdpClient { + return this._chromeConnection.api; + } + private handleBreakEvent(params: any): Promise { let that = this; return this.fetchCallFrames().then(callFrames => { @@ -438,17 +455,54 @@ export class AndroidConnection implements INSDebugConnection { public on(eventName: string, handler: (msg: any) => void): void { - this._socket.on(eventName, handler); + //this._socket.on(eventName, handler); + + let domainMethodPair = eventName.split("."); + if (domainMethodPair.length == 2) + { + let domain = domainMethodPair[0]; + let method = domainMethodPair[1]; + method = "on" + method.charAt(0).toUpperCase() + method.slice(1); + + //this.chrome.Debugger.onPaused(params => handler(params)); + //this.chrome.Debugger.onPaused(params => this.onPaused(params)); + + this.chrome[domain][method](handler); + } + else + { + ((this._chromeConnection))._socket.on(eventName, handler); + } } public attach(port: number, url?: string): Promise { Services.logger().log('Attempting to attach on port ' + port); - return this._attach(port, url); - //.then(() => this.sendMessage('Console.enable')) + return this._attach(port, url).then(() => + { + (this._chromeConnection)._client.setLogging({logEmit: false, logConsole: true}) + + return Promise.resolve(); + }); + } + + public enable(): Promise { + //this.chrome.Console.enable().catch(e => { /* Specifically ignore a fail here since it's only for backcompat */ }), + return this.chrome.Debugger.enable(); + + + // .then(() => { + // Services.logger().log('Runtime enabled'); + // return this.chrome.Debugger.enable(); + // }).then(() => { + // return this._chromeConnection.run(); + // }).then(() => { + // Services.logger().log('debug connection enabled'); + // }); } private _attach(port: number, url?: string): Promise { - return this._socket.attach(port, url); + //return this._socket.attach(port, url); + return this._chromeConnection.attach(url, port); } public close(): void { @@ -456,23 +510,35 @@ export class AndroidConnection implements INSDebugConnection { } public debugger_setBreakpointByUrl(url: string, lineNumber: number, columnNumber: number, condition: string, ignoreCount: number): Promise { - let that = this; - var requestParams = { - type: 'script', - target: that.inspectorUrlToV8Name(url), - line: lineNumber, - column: columnNumber, - condition: condition, - ignoreCount: ignoreCount - }; - - return this.request("setbreakpoint", requestParams) - .then(response => { + // let that = this; + // var requestParams = { + // type: 'script', + // target: that.inspectorUrlToV8Name(url), + // line: lineNumber, + // column: columnNumber, + // condition: condition, + // ignoreCount: ignoreCount + // }; + + // return this.request("setbreakpoint", requestParams) + // .then(response => { + // return + // { + // result: { + // breakpointId: response.breakpoint.toString(), + // locations: response.actual_locations.map(that.v8LocationToInspectorLocation), + // }, + // } + // }); + + return this.chrome.Debugger.setBreakpointByUrl({ urlRegex: url, lineNumber: lineNumber, columnNumber: columnNumber, condition }) + .then(response => + { return { result: { - breakpointId: response.breakpoint.toString(), - locations: response.actual_locations.map(that.v8LocationToInspectorLocation), + breakpointId: response.breakpointId.toString(), + locations: response.locations }, } }); @@ -484,10 +550,15 @@ export class AndroidConnection implements INSDebugConnection { //ok - return this.request("clearbreakpoint", { - breakpoint: breakpointId - }) - .then(response => { + // return this.request("clearbreakpoint", { + // breakpoint: breakpointId + // }) + // .then(response => { + // return {}; + // }); + + + return this.chrome.Debugger.removeBreakpoint({ breakpointId }).then(response => { return {}; }); } @@ -499,18 +570,27 @@ export class AndroidConnection implements INSDebugConnection { //locations: response.actual_locations.map(that.v8LocationToInspectorLocation) - return this.sendContinue('next').then(reponse => { + // return this.sendContinue('next').then(reponse => { + // return {}; + // }); + + return this.chrome.Debugger.stepOver().then(reponse => { return {}; }); + //ok } private sendContinue(stepAction: string): Promise { - let that = this; - let args = stepAction ? { stepaction: stepAction } : undefined; - return this.request("continue", args).then(response => { - that._socket.emit("'Debugger.resumed"); + // let that = this; + // let args = stepAction ? { stepaction: stepAction } : undefined; + // return this.request("continue", args).then(response => { + // that._socket.emit("'Debugger.resumed"); + // return response; + // }) + + return this.chrome.Debugger.resume().then(response => { return response; }) } @@ -521,8 +601,14 @@ export class AndroidConnection implements INSDebugConnection { //throw new Error("Not implemented"); //ok - return this.sendContinue('in').then(reponse => { - return {}; + + + //return this.sendContinue('in').then(reponse => { + // return {}; + //}); + + return this.chrome.Debugger.stepInto().then(reponse => { + return {}; }); } @@ -531,7 +617,13 @@ export class AndroidConnection implements INSDebugConnection { //throw new Error("Not implemented"); //ok - return this.sendContinue('out').then(reponse => { + + + // return this.sendContinue('out').then(reponse => { + // return {}; + // }); + + return this.chrome.Debugger.stepOut().then(reponse => { return {}; }); } @@ -541,7 +633,12 @@ export class AndroidConnection implements INSDebugConnection { //throw new Error("Not implemented"); //ok - return this.sendContinue(null).then(reponse => { + + // return this.sendContinue(null).then(reponse => { + // return {}; + // }); + + return this.chrome.Debugger.resume().then(reponse => { return {}; }); } @@ -551,53 +648,78 @@ export class AndroidConnection implements INSDebugConnection { //throw new Error("Not implemented"); //ok - let that = this; - return this.request("suspend", {}) - .then(reponse => that.handleBreakEvent(null)); - // .then(reponse => { - // return {}; - // }); + // let that = this; + // return this.request("suspend", {}).then(reponse => that.handleBreakEvent(null)); + + return this.chrome.Debugger.pause().then(reponse => { + return {}; + }); } public debugger_evaluateOnCallFrame(callFrameId: string, expression: string, objectGroup = 'dummyObjectGroup', returnByValue?: boolean): Promise { //return this.sendMessage('Debugger.evaluateOnCallFrame', { callFrameId, expression, objectGroup, returnByValue }); //throw new Error("Not implemented"); - var requestParams = { - expression: expression, - frame: callFrameId - }; - + // var requestParams = { + // expression: expression, + // frame: callFrameId + // }; + + + // let messageId = this._nextId++; + // let that = this; + // return this.request("evaluate", requestParams).then(response => { + // return { + // result: { + // result: that.v8ResultToInspectorResult(response), + // wasThrown: false + // } + // } + // }); - let messageId = this._nextId++; - let that = this; - return this.request("evaluate", requestParams).then(response => { - return { + return this.chrome.Debugger.evaluateOnCallFrame({ callFrameId, expression, silent: true, generatePreview: true }).then(response => { + return { result: { - result: that.v8ResultToInspectorResult(response), + result: response.result, wasThrown: false } } }); } - public debugger_setPauseOnExceptions(state: string): Promise { + public debugger_setPauseOnExceptions(args: string): Promise { //return this.sendMessage('Debugger.setPauseOnExceptions', { state }); - var requestParams = { - type: state !== 'none' ? state : "uncaught", - enabled: state !== 'none' - }; + //throw new Error("Not implemented"); - let messageId = this._nextId++; - return this.request("setexceptionbreak", requestParams).then(response => { - return new Promise((resolve, reject) => { - if (response.error) { - reject(response.error); - return; - } - resolve({ id: messageId }); - }); + // var requestParams = { + // type: state !== 'none' ? state : "uncaught", + // enabled: state !== 'none' + // }; + + // let messageId = this._nextId++; + // return this.request("setexceptionbreak", requestParams).then(response => { + // return new Promise((resolve, reject) => { + // if (response.error) { + // reject(response.error); + // return; + // } + // resolve({ id: messageId }); + // }); + // }); + + let state: 'all' | 'uncaught' | 'none'; + if (args.indexOf('all') >= 0) { + state = 'all'; + } else if (args.indexOf('uncaught') >= 0) { + state = 'uncaught'; + } else { + state = 'none'; + } + + return this.chrome.Debugger.setPauseOnExceptions({ state }) + .then(reponse => { + return {} ; }); } @@ -605,42 +727,53 @@ export class AndroidConnection implements INSDebugConnection { //return this.sendMessage('Debugger.getScriptSource', //{ scriptId }); - var requestParams = { - includeSource: true, - types: 4, - ids: [Number(scriptId)] - }; - - let messageId = this._nextId++; - return this.request("scripts", requestParams).then(response => { - return new Promise((resolve, reject) => { - if (response.error) { - reject(response.error); - return; - } - - let source = undefined; - if (Array.isArray(response)) { - source = response[0].source; - } - else if (response.result) { - source = response.result[0].source; - } - else if (response.source) { - source = response.source; - } + // var requestParams = { + // includeSource: true, + // types: 4, + // ids: [Number(scriptId)] + // }; + + // let messageId = this._nextId++; + // return this.request("scripts", requestParams).then(response => { + // return new Promise((resolve, reject) => { + // if (response.error) { + // reject(response.error); + // return; + // } + + // let source = undefined; + // if (Array.isArray(response)) { + // source = response[0].source; + // } + // else if (response.result) { + // source = response.result[0].source; + // } + // else if (response.source) { + // source = response.source; + // } + + + // let result = { + // id: messageId, + // result: { + // scriptSource: source + // } + // } + + // resolve(result); + // }); + // }); - let result = { - id: messageId, - result: { - scriptSource: source + return this.chrome.Debugger.getScriptSource({ scriptId: scriptId }).then(response => + { + return + { + result: { + scriptSource: response.scriptSource + } } - } - - resolve(result); }); - }); } private request(command, args): Promise { @@ -675,39 +808,46 @@ export class AndroidConnection implements INSDebugConnection { //throw new Error("Not implemented"); - return this.isScopeId(objectId).then(response => { - if (response) { - return this.getPropertiesOfScopeId(objectId); - } - else { - if (!ownProperties || accessorPropertiesOnly) { - // Temporary fix for missing getInternalProperties() implementation - // See the comment in RuntimeAgent.js->getProperties and GH issue #213 (node-inspector repo) - return { result: [] }; - } - - return this.getPropertiesOfObjectId(objectId); - } - }).then(response => { - let properties = response.result; - let result = []; - for (var i = 0; properties && i < properties.length; ++i) { - let property = properties[i]; - //convert the result to - result.push({ - name: property.name, - writeable: property.writable, - enumerable: property.enumerable, - value: property.value - }); - } + // return this.isScopeId(objectId).then(response => { + // if (response) { + // return this.getPropertiesOfScopeId(objectId); + // } + // else { + // if (!ownProperties || accessorPropertiesOnly) { + // // Temporary fix for missing getInternalProperties() implementation + // // See the comment in RuntimeAgent.js->getProperties and GH issue #213 (node-inspector repo) + // return { result: [] }; + // } + + // return this.getPropertiesOfObjectId(objectId); + // } + // }).then(response => { + // let properties = response.result; + // let result = []; + // for (var i = 0; properties && i < properties.length; ++i) { + // let property = properties[i]; + // //convert the result to + // result.push({ + // name: property.name, + // writeable: property.writable, + // enumerable: property.enumerable, + // value: property.value + // }); + // } + + // return { + // result: { + // result: result + // } + // }; + // }); + return this.chrome.Runtime.getProperties({objectId, ownProperties, accessorPropertiesOnly, generatePreview: true}).then(response => { return { result: { - result: result + result: response.result } - }; - }); + }}); } private isScopeId(objectId: string): Promise { @@ -776,31 +916,40 @@ export class AndroidConnection implements INSDebugConnection { public runtime_evaluate(expression: string, objectGroup = 'dummyObjectGroup', contextId?: number, returnByValue = false): Promise { //return this.sendMessage('Runtime.evaluate', { expression, objectGroup, contextId, returnByValue }); - throw new Error("Not implemented"); - } + //throw new Error("Not implemented"); - private sendMessage(method: any, params?: any): Promise { - return this._socket.sendMessage({ - id: this._nextId++, - method, - params - }); + return this.chrome.Runtime.evaluate({expression, objectGroup, contextId, returnByValue}).then(response => { + return { + result: { + result: response.result + } + }}); } + + // private sendMessage(method: any, params?: any): Promise { + // return this._socket.sendMessage({ + // id: this._nextId++, + // method, + // params + // }); + // } + + } /** * Helper function to GET the contents of a url */ -function getUrl(url: string): Promise { - return new Promise((resolve, reject) => { - http.get(url, response => { - let jsonResponse = ''; - response.on('data', chunk => jsonResponse += chunk); - response.on('end', () => { - resolve(jsonResponse); - }); - }).on('error', e => { - reject('Cannot connect to the target: ' + e.message); - }); - }); -} +// function getUrl(url: string): Promise { +// return new Promise((resolve, reject) => { +// http.get(url, response => { +// let jsonResponse = ''; +// response.on('data', chunk => jsonResponse += chunk); +// response.on('end', () => { +// resolve(jsonResponse); +// }); +// }).on('error', e => { +// reject('Cannot connect to the target: ' + e.message); +// }); +// }); +// } diff --git a/src/debug-adapter/connection/iosConnection.ts b/src/debug-adapter/connection/iosConnection.ts index a2621ec..777cdd0 100644 --- a/src/debug-adapter/connection/iosConnection.ts +++ b/src/debug-adapter/connection/iosConnection.ts @@ -170,6 +170,10 @@ export class IosConnection implements INSDebugConnection { return this._socket.attach(filePath); } + public enable() : Promise { + return Promise.resolve(); + } + public close(): void { this._socket.close(); } diff --git a/src/debug-adapter/webKitDebugAdapter.ts b/src/debug-adapter/webKitDebugAdapter.ts index e3a3ae5..8d424e9 100644 --- a/src/debug-adapter/webKitDebugAdapter.ts +++ b/src/debug-adapter/webKitDebugAdapter.ts @@ -166,16 +166,19 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter { Services.logger().log('[NSDebugAdapter] Watching the tns CLI output to receive a connection token', Tags.FrontendMessage); // Attach to the running application cliCommand.tnsOutputEventEmitter.on('readyForConnection', (connectionToken: string | number) => { - connectionToken = this._request.isAndroid ? this._request.androidProject.getDebugPortSync() : connectionToken; + connectionToken = this._request.isAndroid ? this._request.androidProject.getDebugPortSync(this._request.args.tnsArgs) : connectionToken; Services.logger().log(`[NSDebugAdapter] Attaching to application on ${connectionToken}`, Tags.FrontendMessage); let connection: INSDebugConnection = this._request.isAndroid ? new AndroidConnection() : new IosConnection(); - this.setConnection(connection); - let attachPromise = this._request.isAndroid ? (connection).attach(connectionToken, 'localhost') : (connection).attach(connectionToken); - attachPromise.then(() => { + + connection.attach(connectionToken, 'localhost').then(() => { + this.setConnection(connection); + return connection.enable(); + }).then(() => { Services.logger().log(`[NSDebugAdapter] Successfully attached to the target application'`, Tags.FrontendMessage); - // Send InitializedEvent this.fireEvent(new InitializedEvent()); promiseResolve(); + }).then(() => { + }); }); @@ -185,7 +188,6 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter { } private setConnection(connection: INSDebugConnection) : INSDebugConnection { - let args = this._request.args; connection.on('Debugger.paused', params => this.onDebuggerPaused(params)); connection.on('Debugger.resumed', () => this.onDebuggerResumed()); connection.on('Debugger.scriptParsed', params => this.onScriptParsed(params));