]> zoso.dev Git - nano-pow.git/commitdiff
Apply fix for WebGPU not loading in about:blank page but also rejecting HTML content...
authorChris Duncan <chris@zoso.dev>
Tue, 11 Mar 2025 18:03:56 +0000 (11:03 -0700)
committerChris Duncan <chris@zoso.dev>
Tue, 11 Mar 2025 18:03:56 +0000 (11:03 -0700)
cli.js

diff --git a/cli.js b/cli.js
index 62194ff647fa4e9e17882c950f0b888a4ad91cbd..a6f0bc99461a9f0444ffdd9af2156de1f3783572 100755 (executable)
--- a/cli.js
+++ b/cli.js
@@ -59,7 +59,12 @@ let start = performance.now();
                ]
        })
        const page = await browser.newPage()
+       await page.setBypassCSP(true)
+       await page.goto('chrome://newtab')
        page.on('console', async (msg) => {
+               console.log('start test')
+               console.log(msg.text())
+               console.log('end test')
                const output = msg.text().split(' ')
                if (output[0] === 'cli') {
                        if (output[1] === 'exit') {
@@ -73,26 +78,26 @@ let start = performance.now();
                }
        })
        start = performance.now()
-       await page.setContent(`
-               <!DOCTYPE html>
-               <html>
-                       <head>
-                               <script type="module">
-                                       ${NanoPow}
-                                       const hashes = ["${hashes.join('","')}"]
-                                       for (const hash of hashes) {
-                                               try {
-                                                       console.log(\`cli \${hash}\`)
-                                                       const work = await NanoPow.search(hash)
-                                                       console.log(\`cli \${work}\`)
-                                               } catch (err) {
-                                                       console.error(\`cli \${err}\`)
-                                               }
-                                       }
-                                       console.log('cli exit')
-                               </script>
-                       </head>
-                       <body></body>
-               </html>
-       `)
+       await page.addScriptTag({
+               type: 'module',
+               content: `
+                       window.trustedTypes?.createPolicy?.('default', {
+                               createHTML: string => string,
+                               createScriptURL: string => string,
+                               createScript: string => string,
+                       })
+                       ${NanoPow}
+                       const hashes = ["${hashes.join('","')}"]
+                       for (const hash of hashes) {
+                               try {
+                                       console.log(\`cli \${hash}\`)
+                                       const work = await NanoPow.search(hash)
+                                       console.log(\`cli \${work}\`)
+                               } catch (err) {
+                                       console.error(\`cli \${err}\`)
+                               }
+                       }
+                       console.log('cli exit')
+               `
+       })
 })()