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) {
let oldHost = sessionHost;
try {
sessionId = sendRequest('create_session', null, host);
sessionHost = host;
sessionId = sendRequest('create_session');
} catch (e) {
sessionHost = oldHost;
throw e;
}
return sessionId;
}
@ -165,8 +158,8 @@ function deserializeDict(realmId, info) {
return object;
}
function sendRequest(command, data) {
if (!sessionHost) {
function sendRequest(command, data, host = sessionHost) {
if (!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 request = new XMLHttpRequest();
let url = 'http://' + sessionHost + '/' + command;
let url = 'http://' + host + '/' + command;
request.open('POST', url, false);
request.send(body);