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/
/static/
/.log/
/yarn-error.log

View File

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

View File

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