webview_deno icon indicating copy to clipboard operation
webview_deno copied to clipboard

How to run in background?

Open rj-hwang opened this issue 1 year ago • 2 comments

rj-hwang avatar Jan 15 '23 06:01 rj-hwang

You want to run webiview without freezing the main script ? As I know, there is no simple way to run in background since webview handle the client event loop. You can run webview in a worker or a sub process and send data to client via websocket but you don't have direct access of the server part. I'm working on a pull request to solve that via an async api but this project seems to be slowing down.

JOTSR avatar Jan 17 '23 19:01 JOTSR

If what you want is what JOTSR described, you can achieve this by doing an non-awaited asynchronous function as I did.

import {Webview, SizeHint} from "jsr:@webview/webview";
import {loadImage} from "https://deno.land/x/[email protected]/mod.ts";

(async () => {
	const image = await loadImage("E:/AniWorld.png");

	const webview = new Webview(false, {height: image.height(), width: image.width(), hint: SizeHint.FIXED});

	// Load image file at "E:\AniWorld.png"
	webview.navigate("E:/AniWorld.png");
	webview.run();
})();

const urls = [
	"https://aniworld.to/anime/stream/golden-time",
];

console.log(urls.join("\n"));

The main part is

(async () => { /* Code here */ })()

DNAScanner avatar Mar 30 '24 22:03 DNAScanner