1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| var shotWidth = 4320; var shotHeight = 7680; var scale = 25; var panX = -4500; var panY = -2000;
function downloadFile(fileName, content) { var base64ToBlob = function(code) { let raw = window.atob(code); let rawLength = raw.length; let uInt8Array = new Uint8Array(rawLength); for(let i = 0; i < rawLength; ++i) { uInt8Array[i] = raw.charCodeAt(i); } return new Blob([uInt8Array], { type: "image/png" }); }; let aLink = document.createElement('a'); let blob = base64ToBlob(content); let evt = document.createEvent("HTMLEvents"); evt.initEvent("click", true, true); aLink.download = fileName; aLink.href = URL.createObjectURL(blob); aLink.click(); };
var fileBase64 = "";
let sleep = (time) => { return new Promise(resolve => setTimeout(resolve, time)) }
var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { let responseJSON = JSON.parse(xmlhttp.responseText); let wsURL = ""; for (var x in responseJSON) { if (responseJSON[x].url.lastIndexOf("http://hua.61.com/Client.swf") != -1) { wsURL = responseJSON[x].webSocketDebuggerUrl; } }
let ws = new WebSocket(wsURL);
ws.onopen = async function (d) { console.log('chrome remote debugger connected'); ws.send(`{"id": 1, "method": "Emulation.clearDeviceMetricsOverride", "params": {}}`); ws.send(`{"id": 1, "method": "Emulation.setDeviceMetricsOverride", "params": {"mobile":false, "width":` + shotWidth + `, "height":` + shotHeight + `, "deviceScaleFactor": 1}}`); ws.send(`{"id": 1, "method": "Page.navigate", "params": {"url": "javascript:document.getElementsByTagName('embed')[0].Zoom(500);"}}`); await sleep(2000); ws.send(`{"id": 1, "method": "Page.navigate", "params": {"url": "javascript:document.getElementsByTagName('embed')[0].Zoom(` + scale + `);"}}`); await sleep(5000); console.log("flash zoomed"); ws.send(`{"id": 1, "method": "Page.navigate", "params": {"url": "javascript:document.getElementsByTagName('embed')[0].Pan(` + panX + `,` + panY + `,0);"}}`); await sleep(5000); console.log("flash view moved"); await sleep(5000); ws.send(`{"id": 155, "method": "Page.captureScreenshot", "params": {"fromSurface":true}}`); await sleep(5000); ws.send(`{"id": 1, "method": "Emulation.clearDeviceMetricsOverride", "params": {}}`); console.log("cleared emulation"); ws.send(`{"id": 1, "method": "Page.navigate", "params": {"url": "javascript:document.getElementsByTagName('embed')[0].Zoom(500);"}}`); console.log("flash zoom reset");
}
ws.onmessage = function(d) { if (JSON.parse(d.data)['id'] == '155') { console.log('screenshot captured'); console.log('png base64 length: ' + JSON.parse(d.data)['result']['data'].length); fileBase64 = JSON.parse(d.data)['result']['data']; downloadFile('output.png', fileBase64); } } } } xmlhttp.open("GET","http://localhost:9222/json",true); xmlhttp.send();
|