lino-levan / astral

A high-level puppeteer/playwright-like library for Deno
https://jsr.io/@astral/astral
MIT License
255 stars 17 forks source link

[FR] Self-provided `--user-data-dir` #89

Closed lowlighter closed 2 months ago

lowlighter commented 2 months ago

Currently you always need the temp dir in --allow-write because the following is not gated so you'll always hit a permission request: https://github.com/lino-levan/astral/blob/7e91588e342561a2e5a3b515e7b3cedf6683d02b/src/browser.ts#L253

And the arg --user-data-dir is always set by astral: https://github.com/lino-levan/astral/blob/7e91588e342561a2e5a3b515e7b3cedf6683d02b/src/browser.ts#L261

But it'd be nice if the above lines are ignored if user specify the arg theymselves in args: https://github.com/lino-levan/astral/blob/7e91588e342561a2e5a3b515e7b3cedf6683d02b/src/browser.ts#L232

Basically doing something like:

if (!args.find(arg => arg.startsWith("--user-data-dir=")) {
  const tempDir = Deno.makeTempDirSync(); 
  args.push(`--user-data-dir=${tempDir}`) 
}

I know the workaround from #56, but setting TMPDIR is not always convenient because:

lino-levan commented 2 months ago

Basically doing something like:

if (!args.find(arg => arg.startsWith("--user-data-dir=")) { const tempDir = Deno.makeTempDirSync(); args.push(--user-data-dir=${tempDir}) }

I would support this. If you want to submit a PR this makes sense to me.

I haven't personally tested yet, but firefox may not have this arg

Firefox compatibility is currently really broken. Hoping that #84 fixes it in the medium-long term.