【发布时间】:2023-04-02 05:08:01
【问题描述】:
我正在尝试截取我的 WebGL 应用程序的屏幕截图,但结果不正确。
在 headful 模式下运行 puppeteer 效果很好,但我需要在 headless 模式下运行。
我在 shadertoy 上托管了我的着色器,以便在这里更轻松。
shader 很简单,它使用 PRNG 来绘制星空。
Puppeteer 版本:7.0.1
铬版本:90.0.4403.0
这是我的着色器:
uint hash (uint v) {
v += (v << 10u);
v ^= (v >> 6u);
v += (v << 3u);
v ^= (v >> 11u);
v += (v << 15u);
return v;
}
uint hash (uvec2 v) { return hash(v.x^hash(v.y)); }
uint hash (uvec3 v) { return hash(v.x^hash(v.y)^hash(v.z)); }
uint hash (uvec4 v) { return hash(v.x^hash(v.y)^hash(v.z)^hash(v.w)); }
float floatConstruct (uint v) {
v &= 0x007FFFFFu; // ieee mantissa
v |= 0x3F800000u; // ieee one
return uintBitsToFloat(v)-1.0;
}
float random (vec2 v) { return floatConstruct(hash(floatBitsToUint(v))); }
void mainImage (out vec4 fragColor, in vec2 fragCoord) {
float v = random(fragCoord);
float c = pow((v-0.97)/(1.0-0.97),50.0);
fragColor = vec4(vec3(c), 1.0);
}
这是我的傀儡代码:
const puppeteer = require("puppeteer");
const url = "https://www.shadertoy.com/embed/Wl3fD8?gui=true&t=10&paused=true&muted=false"
const crawl = async () => {
try {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url);
await page.waitForTimeout(5000);
await page.screenshot({ path: "screenshot.png" });
await browser.close();
} catch (e) {
console.log(e);
}
};
(async () => await crawl())();
这是 puppeteer(无头)的结果:
它应该是这样的:
【问题讨论】:
标签: javascript webgl puppeteer chromium headless