From: Chris Duncan Date: Tue, 22 Apr 2025 03:23:38 +0000 (-0700) Subject: Intercept dummy https request to get a secure context and set up page content instead... X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=b13ae5be14cf5ba5686cfee829d264a6b9e83ca8;p=nano-pow.git Intercept dummy https request to get a secure context and set up page content instead of writing a dummy file to the file system. --- diff --git a/src/bin/server.ts b/src/bin/server.ts index 68514ac..b4f2a8d 100755 --- a/src/bin/server.ts +++ b/src/bin/server.ts @@ -4,7 +4,7 @@ import { launch } from 'puppeteer' import { subtle } from 'node:crypto' -import { readFile, unlink, writeFile } from 'node:fs/promises' +import { readFile } from 'node:fs/promises' import * as http from 'node:http' import { AddressInfo, Socket } from 'node:net' import { homedir } from 'node:os' @@ -242,35 +242,36 @@ const browser = await launch({ headless: true, args: [ '--headless=new', - '--use-angle=vulkan', - '--enable-features=Vulkan', '--disable-vulkan-surface', - '--enable-unsafe-webgpu' + '--enable-features=Vulkan,DefaultANGLEVulkan,VulkanFromANGLE', + '--enable-gpu', + '--enable-unsafe-webgpu', + '--disable-backgrounding-occluded-windows', + '--disable-background-timer-throttling', + '--disable-renderer-backgrounding' ] }) const page = await browser.newPage() -page.on('console', msg => log(msg.text())) - -const path: string = new URL(import.meta.url).pathname -const dir = path.slice(0, path.lastIndexOf('/')) -const filename = join(dir, `${process.pid}.html`) -await writeFile(filename, '') -await page.goto(import.meta.resolve(filename)) -await page.waitForFunction(async (): Promise => { - return await navigator['gpu'].requestAdapter() -}) -const src = `${NanoPow};window.NanoPow=NanoPow;` +const src = `${NanoPow};window.NanoPow=NanoPowGpu;` const hash = await subtle.digest('SHA-256', Buffer.from(src)) const enc = `sha256-${Buffer.from(hash).toString('base64')}` - -await page.setContent(` +const body = ` -`) -await unlink(filename) +` + +await page.setRequestInterception(true) +page.on('request', async (req): Promise => { + if (req.url() === 'https://nanopow.invalid/') { + req.respond({ status: 200, contentType: 'text/html', body }) + } +}) +page.on('console', msg => log(msg.text())) +await page.goto('https://nanopow.invalid/') + log('Puppeteer initialized') // Listen on configured port