Remove interval once the website loads

This commit is contained in:
Kuba Orlik 2022-04-24 20:35:24 +02:00
parent ae54c490d5
commit f3398708ee
3 changed files with 10 additions and 18 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
/node_modules/ /node_modules/
/static/ /static/
/.log/
/yarn-error.log

View File

@ -83,6 +83,7 @@ prepare_firefox(){
keycombo Shift_L F5 #profiler keycombo Shift_L F5 #profiler
grab "after shift-c F5" grab "after shift-c F5"
keycombo Control_L Shift_L e keycombo Control_L Shift_L e
sleep 5 # it needs some time
} }
load_website(){ load_website(){

View File

@ -32,23 +32,12 @@ function attach(docker_id, output_stream) {
output_stream.push(d); output_stream.push(d);
}); });
task.on("close", () => { task.on("close", () => {
const check = spawn("docker", ["ps", "--filter", `id=${docker_id}`]); output_stream.push("</pre>");
let output = ""; output_stream.push(/* HTML */ `<script>
check.on("data", (data) => { clearInterval(window.interval);
output += data; </script>`);
});
check.on("close", () => {
console.log("CHECK", output);
clearInterval(interval); clearInterval(interval);
}); output_stream.push(null);
check.on("error", (error) => {
console.error("error", error);
clearInterval(interval);
});
check.on("exit", (error) => {
console.error("exit", error);
clearInterval(interval);
});
}); });
} }
@ -64,7 +53,7 @@ router.get("/", async (ctx) => {
`<img id="preview" width="1080" height="608" src="/static/${id}/preview.png?id=0"/><br/>` `<img id="preview" width="1080" height="608" src="/static/${id}/preview.png?id=0"/><br/>`
); );
ctx.body.push(/* HTML */ `<script> ctx.body.push(/* HTML */ `<script>
setInterval(() => (preview.src = preview.src + "0"), 500); window.interval = setInterval(() => (preview.src = preview.src + "0"), 500);
</script>`); </script>`);
const params = qs.parse(ctx.querystring); const params = qs.parse(ctx.querystring);
s.push(`Got request to screenshot ${params.url}<pre>`); s.push(`Got request to screenshot ${params.url}<pre>`);