Skip to content

Commit

Permalink
Initial qutebrowser support
Browse files Browse the repository at this point in the history
Closes #1190
  • Loading branch information
glacambre committed Sep 26, 2021
1 parent fa6406d commit 29bbe39
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/firenvim
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/python3

import json
import os
import random
import re
import subprocess

password = random.getrandbits(64)

# Start firenvim script, send password, get port
firenvim = subprocess.Popen(["/home/me/.local/share/firenvim/firenvim"], stdout = subprocess.PIPE, stdin = subprocess.PIPE, stderr = subprocess.PIPE)
request = 'abcde{"newInstance":true,"password":"' + str(password) + '"}'
firenvim.stdin.write(bytes(request, 'utf-8'))
outs, errs = firenvim.communicate()
result = json.loads(outs[4:])

# Write port and password to HTML file
with open("/home/me/.local/share/qutebrowser/userscripts/firenvim.js", "r") as f:
html = f.read()
with open("/home/me/.local/share/qutebrowser/userscripts/firenvim.js", "w") as f:
f.write(re.sub(r"^const port = .*; const password= .*;$",
"const port = " + str(result["port"]) + "; const password = " + str(password) + ";",
html))


with open(os.environ["QUTE_FIFO"], "w") as f:
f.write("jseval --file /home/me/.local/share/qutebrowser/userscripts/firenvim.js")
39 changes: 39 additions & 0 deletions src/firenvim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const port = 12345; const password = 12345;
const content = new Blob([`
<html oncontextmenu="return false;">
<head>
<meta charset="utf-8"/>
<style>
html, body {
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
overflow: hidden;
}
#keyhandler {
height: 1px;
opacity: 0.01;
overflow: hidden;
outline: none;
border: none;
position: absolute;
margin: 0px;
padding: 0px;
}
#canvas {
position: absolute;
top: 0px;
margin: 0px;
padding: 0px;
}
</style>
<style id="mouse_cursor"></style>
<script>alert("hello")</script>
</head>
<body oncontextmenu="return false;"><textarea id="keyhandler"></textarea><canvas id="canvas" oncontextmenu="return false;"></canvas></body>
</html>
`], {type: "text/html; charset=utf-8"});
const iframe = document.createElement("iframe");
iframe.src = URL.createObjectURL(content);
document.body.appendChild(iframe);

0 comments on commit 29bbe39

Please sign in to comment.