Simplify setting up Chrome debugging sessionHost

This commit is contained in:
Scott Kyle 2016-03-16 09:28:18 -07:00
parent 00b19d95b8
commit 8d73a8e985
1 changed files with 5 additions and 12 deletions

View File

@ -45,15 +45,8 @@ export function registerTypeConverter(type, handler) {
} }
export function createSession(host) { export function createSession(host) {
let oldHost = sessionHost; sessionId = sendRequest('create_session', null, host);
try {
sessionHost = host; sessionHost = host;
sessionId = sendRequest('create_session');
} catch (e) {
sessionHost = oldHost;
throw e;
}
return sessionId; return sessionId;
} }
@ -165,8 +158,8 @@ function deserializeDict(realmId, info) {
return object; return object;
} }
function sendRequest(command, data) { function sendRequest(command, data, host = sessionHost) {
if (!sessionHost) { if (!host) {
throw new Error('Must first create RPC session with a valid host'); throw new Error('Must first create RPC session with a valid host');
} }
@ -174,7 +167,7 @@ function sendRequest(command, data) {
let body = JSON.stringify(data); let body = JSON.stringify(data);
let request = new XMLHttpRequest(); let request = new XMLHttpRequest();
let url = 'http://' + sessionHost + '/' + command; let url = 'http://' + host + '/' + command;
request.open('POST', url, false); request.open('POST', url, false);
request.send(body); request.send(body);