Files
faunosteo/docker/csp-proof/run.mjs
T

18 lines
1.0 KiB
JavaScript

import { chromium } from 'playwright-core'
const exe = process.env.CHROME
const browser = await chromium.launch({ executablePath: exe, headless: true })
for (const [name, port] of [['without wasm-unsafe-eval', 8091], ['with wasm-unsafe-eval', 8092]]) {
const page = await browser.newPage()
const logs = []
page.on('console', (m) => logs.push(`${m.type()}: ${m.text()}`))
page.on('pageerror', (e) => logs.push(`pageerror: ${e.message}`))
const resp = await page.goto(`http://127.0.0.1:${port}/`)
const csp = resp.headers()['content-security-policy']
await page.waitForFunction(() => document.title !== 'pending', null, { timeout: 10000 }).catch(() => {})
const wasmResp = await page.request.get(`http://127.0.0.1:${port}/pkg/faunosteo_wasm_bg.wasm`)
console.log(`== ${name}: title="${await page.title()}" csp-has-wasm-unsafe-eval=${csp.includes('wasm-unsafe-eval')} wasm-content-type=${wasmResp.headers()['content-type']}`)
for (const l of logs) console.log(' ' + l.slice(0, 220))
await page.close()
}
await browser.close()