OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <title>Headless remote debugging</title> | 3 <title>Headless remote debugging</title> |
4 <style> | 4 <style> |
5 </style> | 5 </style> |
6 | 6 |
7 <script> | 7 <script> |
8 function onLoad() { | 8 const fetchjson = (url) => fetch(url).then(r => r.json()); |
9 var tabs_list_request = new XMLHttpRequest(); | 9 |
10 tabs_list_request.open("GET", "/json/list?t=" + new Date().getTime(), true); | 10 function loadData() { |
11 tabs_list_request.onreadystatechange = onReady; | 11 const getList = fetchjson("/json/list"); |
12 tabs_list_request.send(); | 12 const getVersion = fetchjson('/json/version'); |
| 13 Promise.all([getList, getVersion]).then(parseResults); |
13 } | 14 } |
14 | 15 |
15 function onReady() { | 16 function parseResults([listData, versionData]){ |
16 if(this.readyState == 4 && this.status == 200) { | 17 const version = versionData['WebKit-Version']; |
17 if(this.response != null) | 18 const hash = version.match(/\s\(@(\b[0-9a-f]{5,40}\b)/)[1]; |
18 var responseJSON = JSON.parse(this.response); | 19 listData.forEach(item => appendItem(item, hash)); |
19 for (var i = 0; i < responseJSON.length; ++i) | |
20 appendItem(responseJSON[i]); | |
21 } | |
22 } | 20 } |
23 | 21 |
24 function appendItem(item_object) { | 22 function appendItem(item, hash) { |
25 var frontend_ref; | 23 let link; |
26 if (item_object.devtoolsFrontendUrl) { | 24 if (item.devtoolsFrontendUrl) { |
27 frontend_ref = document.createElement("a"); | 25 link = document.createElement("a"); |
28 frontend_ref.href = item_object.devtoolsFrontendUrl; | 26 var devtoolsFrontendUrl = item.devtoolsFrontendUrl.replace(/^\/devtools\//,'
'); |
29 frontend_ref.title = item_object.title; | 27 link.href = `https://chrome-devtools-frontend.appspot.com/serve_file/@${hash
}/${devtoolsFrontendUrl}&remoteFrontend=true`; |
| 28 link.title = item.title; |
30 } else { | 29 } else { |
31 frontend_ref = document.createElement("div"); | 30 link = document.createElement("div"); |
32 frontend_ref.title = "The tab already has active debugging session"; | 31 link.title = "The tab already has active debugging session"; |
33 } | 32 } |
34 | 33 |
35 var text = document.createElement("div"); | 34 var text = document.createElement("div"); |
36 if (item_object.title) | 35 if (item.title) |
37 text.innerText = item_object.title; | 36 text.textContent = item.title; |
38 else | 37 else |
39 text.innerText = "(untitled tab)"; | 38 text.textContent = "(untitled tab)"; |
40 text.style.cssText = "background-image:url(" + item_object.faviconUrl + ")"; | 39 if (item.faviconUrl) |
41 frontend_ref.appendChild(text); | 40 text.style.cssText = "background-image:url(" + item.faviconUrl + ")"; |
| 41 link.appendChild(text); |
42 | 42 |
43 var item = document.createElement("p"); | 43 var p = document.createElement("p"); |
44 item.appendChild(frontend_ref); | 44 p.appendChild(link); |
45 | 45 |
46 document.getElementById("items").appendChild(item); | 46 document.getElementById("items").appendChild(p); |
47 } | 47 } |
48 </script> | 48 </script> |
49 </head> | 49 </head> |
50 <body onload='onLoad()'> | 50 <body onload='loadData()'> |
51 <div id='caption'>Inspectable WebContents</div> | 51 <div id='caption'>Inspectable WebContents</div> |
52 <div id='items'></div> | 52 <div id='items'></div> |
53 </body> | 53 </body> |
54 </html> | 54 </html> |
OLD | NEW |