31 lines
1.7 KiB
JavaScript
31 lines
1.7 KiB
JavaScript
|
|
// Run the actual injected bridge in an isolated browser; never touch user profiles.
|
||
|
|
import { chromium } from '../tools/playwright/node_modules/playwright/index.mjs';
|
||
|
|
import { readFileSync } from 'node:fs';
|
||
|
|
import assert from 'node:assert/strict';
|
||
|
|
const source = readFileSync(new URL('../crates/lazyboy-core/src/novnc_skin.rs', import.meta.url), 'utf8');
|
||
|
|
const skin = source.split('r###"')[1].split('"###;')[0];
|
||
|
|
const browser = await chromium.launch({headless:true});
|
||
|
|
try {
|
||
|
|
const page = await browser.newPage();
|
||
|
|
await page.addInitScript(() => {
|
||
|
|
window.mutations = 0;
|
||
|
|
const Native = window.MutationObserver;
|
||
|
|
window.MutationObserver = class extends Native {
|
||
|
|
constructor(callback) { super((records, observer) => {
|
||
|
|
window.mutations += records.length;
|
||
|
|
// Bound a broken implementation so the regression cannot itself cause OOM.
|
||
|
|
if (window.mutations > 1000) { observer.disconnect(); return; }
|
||
|
|
callback(records, observer);
|
||
|
|
}); }
|
||
|
|
};
|
||
|
|
});
|
||
|
|
await page.route('http://bridge.test/**', route => route.request().url().endsWith('/app/ui.js')
|
||
|
|
? route.fulfill({contentType:'application/javascript',body:'export default {};'} )
|
||
|
|
: route.fulfill({contentType:'text/html',body:`<!doctype html><html><head>${skin}</head><body><div id="noVNC_control_bar" class="noVNC_open"></div><div id="noVNC_status"></div></body></html>`}));
|
||
|
|
await page.goto('http://bridge.test/vnc.html');
|
||
|
|
await page.waitForTimeout(1200);
|
||
|
|
const mutations=await page.evaluate(()=>window.mutations);
|
||
|
|
assert.ok(mutations < 100, `bridge mutation feedback loop: ${mutations} records`);
|
||
|
|
console.log(`PASS noVNC bridge remains responsive (${mutations} mutation records)`);
|
||
|
|
} finally { await browser.close(); }
|