2015-03-19 19:10:41 +00:00
<!doctype html>
2015-03-23 18:48:02 +00:00
<!--
Copyright (c) 2015-present, Facebook, Inc.
All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree. An additional grant
of patent rights can be found in the PATENTS file in the same directory.
-->
2015-03-19 19:10:41 +00:00
< html >
< head >
< meta charset = utf-8 >
<!-- Fake favicon, to avoid extra request to server -->
< link rel = "icon" href = "data:;base64,iVBORw0KGgo=" >
< title > React Native Debugger< / title >
2015-08-21 17:15:04 +00:00
< script >
2015-03-19 19:10:41 +00:00
(function() {
function setStatus(status) {
document.getElementById('status').innerHTML = status;
}
2016-09-14 09:55:14 +00:00
var isMacLike = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform);
var refresh_shortcut = isMacLike ? '⌘R' : 'Ctrl R';
window.onload = function() {
if (!isMacLike) {
document.getElementById('dev_tools_shortcut').innerHTML = 'Ctrl⇧J';
}
}
var INITIAL_MESSAGE = 'Waiting, press < span class = "shortcut" > ' + refresh_shortcut + '< / span > in simulator to reload and connect.';
2015-09-24 03:02:22 +00:00
2016-02-05 23:16:16 +00:00
function connectToDebuggerProxy() {
var worker;
var ws = new WebSocket('ws://' + window.location.host + '/debugger-proxy?role=debugger&name=Chrome');
function createJSRuntime() {
// This worker will run the application javascript code,
// making sure that it's run in an environment without a global
// document, to make it consistent with the JSC executor environment.
worker = new Worker('debuggerWorker.js');
worker.onmessage = function(message) {
ws.send(JSON.stringify(message.data));
};
window.onbeforeunload = function() {
return 'If you reload this page, it is going to break the debugging session. ' +
2016-09-14 09:55:14 +00:00
'You should press' + refresh_shortcut + 'in simulator to reload.';
2016-02-05 23:16:16 +00:00
};
2015-03-19 19:10:41 +00:00
}
2016-02-05 23:16:16 +00:00
function shutdownJSRuntime() {
if (worker) {
worker.terminate();
worker = null;
window.onbeforeunload = null;
}
}
2015-03-19 19:10:41 +00:00
2015-07-16 21:16:50 +00:00
ws.onopen = function() {
2016-02-05 23:16:16 +00:00
setStatus(INITIAL_MESSAGE);
2015-07-16 21:16:50 +00:00
};
2015-03-19 19:10:41 +00:00
2015-07-16 21:16:50 +00:00
ws.onmessage = function(message) {
2016-02-05 23:16:16 +00:00
if (!message.data) {
return;
}
2015-07-16 21:16:50 +00:00
var object = JSON.parse(message.data);
2016-02-05 23:16:16 +00:00
if (object.$event === 'client-disconnected') {
shutdownJSRuntime();
2016-09-14 09:55:14 +00:00
setStatus('Waiting, press < span class = "shortcut" > ' + refresh_shortcut + '< / span > in simulator to reload and connect.');
2016-02-05 23:16:16 +00:00
return;
}
2015-08-31 18:18:23 +00:00
if (!object.method) {
return;
}
2016-02-05 23:16:16 +00:00
// Special message that asks for a new JS runtime
if (object.method === 'prepareJSRuntime') {
shutdownJSRuntime();
2016-06-09 02:00:12 +00:00
console.clear();
2016-02-05 23:16:16 +00:00
createJSRuntime();
ws.send(JSON.stringify({replyID: object.id}));
setStatus('Debugger session #' + object.id + ' active.');
} else if (object.method === '$disconnected') {
shutdownJSRuntime();
setStatus(INITIAL_MESSAGE);
2015-07-16 21:16:50 +00:00
} else {
2015-12-08 23:57:34 +00:00
// Otherwise, pass through to the worker.
worker.postMessage(object);
2015-07-16 21:16:50 +00:00
}
};
2016-02-05 23:16:16 +00:00
ws.onclose = function(e) {
shutdownJSRuntime();
2015-07-16 21:16:50 +00:00
setStatus('Disconnected from proxy. Attempting reconnection. Is node server running?');
2016-02-05 23:16:16 +00:00
if (e.reason) {
setStatus(e.reason);
console.warn(e.reason);
}
setTimeout(connectToDebuggerProxy, 500);
2015-07-16 21:16:50 +00:00
};
2015-03-19 19:10:41 +00:00
}
2015-07-16 21:16:50 +00:00
connectToDebuggerProxy();
2015-03-19 19:10:41 +00:00
})();
< / script >
< style type = "text/css" >
2015-08-07 22:01:40 +00:00
body {
font-size: large;
2015-08-21 17:15:04 +00:00
margin: 0;
2015-08-07 22:01:40 +00:00
padding: 0;
2015-08-21 17:15:04 +00:00
font-family: Helvetica, Verdana, sans-serif;
2015-08-07 22:01:40 +00:00
font-weight: 200;
}
2015-03-19 19:10:41 +00:00
.shortcut {
2015-08-19 22:42:27 +00:00
font-family: "Monaco", monospace;
font-size: medium;
2015-03-19 19:10:41 +00:00
color: #eee;
background-color: #333;
padding: 4px;
border-radius: 4px;
letter-spacing: 3px;
}
2015-08-07 22:01:40 +00:00
.content {
padding: 10px;
2015-03-19 19:10:41 +00:00
}
< / style >
< / head >
< body >
2015-08-07 22:01:40 +00:00
< div class = "content" >
< p >
2015-08-19 22:42:27 +00:00
React Native JS code runs inside this Chrome tab.
2015-08-07 22:01:40 +00:00
< / p >
2016-09-14 09:55:14 +00:00
< p > Press < kbd id = 'dev_tools_shortcut' class = "shortcut" > ⌘⌥J< / kbd > to open Developer Tools. Enable < a href = "https://stackoverflow.com/a/17324511/232122" target = "_blank" > Pause On Caught Exceptions< / a > for a better debugging experience.< / p >
2015-08-21 17:15:04 +00:00
< p > Status: < span id = "status" > Loading...< / span > < / p >
2015-08-07 22:01:40 +00:00
< / div >
2015-03-19 19:10:41 +00:00
< / body >
< / html >