Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// import * as ws from "https://deno.land/std/ws/mod.ts";
//TODO 有効なChromeのパスを探す
const chrome =
"/opt/homebrew-cask/Caskroom/google-chrome/latest/Google Chrome.app/Contents/MacOS/Google Chrome";
async function main() {
const dirName = await Deno.makeTempDir({ prefix: "deno_chrome_temp" });
const width = 400;
const height = 400;
//lorcaの実装を参考にする
//https://github.com/zserge/lorca
const args = [
"--no-first-run", //ようこそみたいなのが表示されるのを防止
"--disable-default-apps",
"--remote-debugging-port=9222",
"--user-data-dir=/" + dirName, //これがないとDevToolの接続受け付けてくれない
"--app=https://deno.land/",
"--disable-sync",
`--window-size=${width},${height}`
];
const proc = await Deno.run({
args: [chrome, ...args]
});
//Chromeが起動するまで待つ。どうやって待つべきか…
//stdout見張るのが良さそうだけどとりあえずこれでいいか
setTimeout(async () => {
const res = await fetch("http://127.0.0.1:9222/json");
const json = await res.json();
const item = json.shift();
console.log(item.webSocketDebuggerUrl);
//TODO wsの使い方を勉強
//https://chromedevtools.github.io/devtools-protocol/
//Denoプロセス落としてもChromeが開きっぱなしになってしまう。
//これもprocess.on("exit", fn)みたいなのがあればいいけど
//Denoでそれやるのどうするんだろ?
// proc.close();
}, 1000);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.