Commit 839d73b0 authored by lukas.niegsch's avatar lukas.niegsch

created connection to headless chromium

parent 64e6dd7c
class HeadlessChromium
{
constructor(websocketUrl)
{
this.websocketUrl = websocketUrl
this.websocket = new WebSocket(websocketUrl)
}
isConnected()
{
return this.websocket.readyState == WebSocket.OPEN
}
runCommand(method, params = {}, callback)
{
var command = {id: 0, method: method, params: params}
this.websocket.send(JSON.stringify(command))
this.websocket.onmessage = (response) => {
callback(response.data)
}
}
}
......@@ -7,10 +7,24 @@
<script src="connection.js"></script>
<script src="chromium.js"></script>
<script>
var searchParams = (new URL(window.location.href)).searchParams
var websocketUrl = searchParams.get("websocket")
var browser = new HeadlessChromium(websocketUrl)
function mainloop()
{
console.log("Hello, World " + test())
setTimeout(mainloop, 5 /* seconds */ * 1000)
if (browser.isConnected())
{
browser.runCommand("Browser.getVersion", {}, (version) => {
console.log(version)
})
}
else
{
console.log("Not connected!")
}
setTimeout(mainloop, 2 /* seconds */ * 1000)
}
mainloop()
</script>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment