فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

test(windows-vm): enable WebView2 CDP through documented per-exe registry fallback on new runtimes

davoodmehraban89 committed Oct 16, 2026 at 18:10 UTC ef67f9206903c20420495d10565038dcc563d15d
1 file changed +35 -1
tests/windows-vm-installed-tauri-cdp.cjs
+35 -1
@@ -5,7 +5,7 @@
5 const assert = require('node:assert/strict');
6 const fs = require('node:fs');
7 const path = require('node:path');
8 -const { spawn } = require('node:child_process');
8 +const { spawn, execFileSync } = require('node:child_process');
9
10 const [exe, profile, mode, expectedVersion, reportPath] = process.argv.slice(2);
11 assert.equal(process.platform, 'win32');
@@ -14,6 +14,36 @@ assert.ok(fs.existsSync(exe), 'installed Windows executable missing');
14 fs.mkdirSync(profile, { recursive: true });
15 const port = mode === 'seed' ? 9371 : mode === 'upgrade' ? 9372 : 9373;
16 const PASSWORD = 'VmOnly-Factor-83471!'; // Synthetic password, never printed.
17 +
18 +const REG_POLICY = [
19 + 'HKCU\Software\Policies\Microsoft\Edge\WebView2\AdditionalBrowserArguments',
20 + 'HKLM\SOFTWARE\Policies\Microsoft\Edge\WebView2\AdditionalBrowserArguments'
21 +];
22 +const EXE_NAME = path.basename(exe);
23 +function setDebugPolicies() {
24 + const active = [];
25 + for (const key of REG_POLICY) {
26 + try {
27 + // Newer WebView2 runtimes may ignore the environment variable for
28 + // CDP debugging. Microsoft documents the per-EXE policy alternative.
29 + execFileSync('reg.exe', [
30 + 'add', key, '/v', EXE_NAME, '/t', 'REG_SZ', '/d',
31 + '--remote-debugging-port=' + port + ' --remote-allow-origins=*', '/f'
32 + ], { stdio: 'ignore', timeout: 5000 });
33 + active.push(key);
34 + } catch (_) { /* Fall back to the documented WebView2 environment variable. */ }
35 + }
36 + return active;
37 +}
38 +function cleanDebugPolicies(keys) {
39 + for (const key of keys) {
40 + try {
41 + execFileSync('reg.exe', ['delete', key, '/v', EXE_NAME, '/f'],
42 + { stdio: 'ignore', timeout: 5000 });
43 + } catch (_) {}
44 + }
45 +}
46 +
47 const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
48 async function eventually(fn, timeoutMs = 65000, delayMs = 300) {
49 let last;
@@ -75,7 +105,10 @@ async function connect(url) {
105 dpapi: 'not-run', browserOrigin: null, status: 'FAILED'
106 };
107 let proc, cdp;
108 + let debugPolicyKeys = [];
109 try {
110 + debugPolicyKeys = setDebugPolicies();
111 + report.debugPolicyKeysApplied = debugPolicyKeys.length;
112 const env = {
113 ...process.env,
114 WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS:
@@ -172,6 +205,7 @@ async function connect(url) {
205 if (reportPath) fs.writeFileSync(reportPath, JSON.stringify(report, null, 2) + '\n');
206 try { cdp?.close(); } catch {}
207 try { proc?.kill(); } catch {}
208 + cleanDebugPolicies(debugPolicyKeys);
209 await wait(700);
210 }
211 })().catch(error => { console.error(error); process.exitCode = 1; });