@melaya/runner 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browserBridge.js +45 -0
- package/package.json +1 -1
package/dist/browserBridge.js
CHANGED
|
@@ -41,6 +41,29 @@ import { runSandboxedScript } from "./codeWorker.js";
|
|
|
41
41
|
// ---------------------------------------------------------------------
|
|
42
42
|
// Limits and constants
|
|
43
43
|
// ---------------------------------------------------------------------
|
|
44
|
+
// Injected into every interactive-session page to display a non-interactive
|
|
45
|
+
// Melaya branding overlay (pill badge + pulsing neon border). Defined once
|
|
46
|
+
// here so it is shared between context.addInitScript (persistent across
|
|
47
|
+
// navigations) and the one-shot page.evaluate on the already-open page.
|
|
48
|
+
const MELAYA_BRAND_SCRIPT = `(() => {
|
|
49
|
+
if (window.__melayaBrand) return; window.__melayaBrand = true;
|
|
50
|
+
const ID = "__melaya_brand";
|
|
51
|
+
const inject = () => {
|
|
52
|
+
const root = document.documentElement; if (!root) return;
|
|
53
|
+
if (document.getElementById(ID + "_border")) return;
|
|
54
|
+
const style = document.createElement("style");
|
|
55
|
+
style.id = ID + "_style";
|
|
56
|
+
style.textContent = "@keyframes melBrandPulse{0%,100%{box-shadow:inset 0 0 10px 2px rgba(109,40,217,.55),inset 0 0 34px 7px rgba(34,211,238,.26)}50%{box-shadow:inset 0 0 20px 5px rgba(139,92,246,.9),inset 0 0 66px 15px rgba(34,211,238,.5)}}@keyframes melBrandDot{0%,100%{opacity:.5;transform:scale(.85)}50%{opacity:1;transform:scale(1.15)}}#" + ID + "_border{position:fixed;inset:0;pointer-events:none;z-index:2147483647;border-radius:7px;animation:melBrandPulse 2.4s ease-in-out infinite}#" + ID + "_badge{position:fixed;top:10px;left:50%;transform:translateX(-50%);pointer-events:none;z-index:2147483647;font:600 12px/1 -apple-system,Segoe UI,Roboto,sans-serif;color:#E9D5FF;background:linear-gradient(90deg,rgba(30,58,138,.94),rgba(109,40,217,.94));padding:6px 14px;border-radius:999px;letter-spacing:.3px;box-shadow:0 0 16px 2px rgba(139,92,246,.7),0 0 5px rgba(34,211,238,.6);display:flex;align-items:center;gap:7px;backdrop-filter:blur(4px)}#" + ID + "_dot{width:7px;height:7px;border-radius:50%;background:#22D3EE;box-shadow:0 0 8px 2px #22D3EE;animation:melBrandDot 1.5s ease-in-out infinite}";
|
|
57
|
+
(document.head || root).appendChild(style);
|
|
58
|
+
const border = document.createElement("div"); border.id = ID + "_border";
|
|
59
|
+
const badge = document.createElement("div"); badge.id = ID + "_badge";
|
|
60
|
+
const dot = document.createElement("span"); dot.id = ID + "_dot";
|
|
61
|
+
badge.appendChild(dot); badge.appendChild(document.createTextNode("Controlled by Melaya"));
|
|
62
|
+
root.appendChild(border); root.appendChild(badge);
|
|
63
|
+
};
|
|
64
|
+
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", inject); else inject();
|
|
65
|
+
try { new MutationObserver(() => { if (!document.getElementById(ID + "_border")) inject(); }).observe(document.documentElement, { childList: true }); } catch (e) {}
|
|
66
|
+
})();`;
|
|
44
67
|
const MAX_BODY_BYTES = 512 * 1024; // /browser/run scripts included
|
|
45
68
|
const NODE_CAP = 240; // snapshot node cap (Section 8)
|
|
46
69
|
const SCREENSHOT_MAX_B64 = 1_400_000; // ~1 MB binary; ladder recompresses
|
|
@@ -252,11 +275,15 @@ export async function startBrowserBridge(opts) {
|
|
|
252
275
|
headless: false,
|
|
253
276
|
viewport: { width: 1280, height: 800 },
|
|
254
277
|
acceptDownloads: false,
|
|
278
|
+
// Suppress the "browser is being controlled by automated test
|
|
279
|
+
// software" infobar that Chromium/Brave shows by default.
|
|
280
|
+
ignoreDefaultArgs: ["--enable-automation"],
|
|
255
281
|
args: [
|
|
256
282
|
"--no-first-run",
|
|
257
283
|
"--no-default-browser-check",
|
|
258
284
|
"--disable-background-networking",
|
|
259
285
|
"--disable-sync",
|
|
286
|
+
"--disable-blink-features=AutomationControlled",
|
|
260
287
|
],
|
|
261
288
|
});
|
|
262
289
|
}
|
|
@@ -272,6 +299,24 @@ export async function startBrowserBridge(opts) {
|
|
|
272
299
|
context,
|
|
273
300
|
ephemeralUserDataDir: ephemeral ? userDataDir : null,
|
|
274
301
|
});
|
|
302
|
+
// Install Melaya branding overlay. addInitScript persists it across
|
|
303
|
+
// all navigations and new pages. The one-shot evaluate covers the
|
|
304
|
+
// already-open page (typically about:blank) immediately.
|
|
305
|
+
// Both are wrapped so a branding failure cannot fail the launch.
|
|
306
|
+
try {
|
|
307
|
+
await context.addInitScript(MELAYA_BRAND_SCRIPT);
|
|
308
|
+
}
|
|
309
|
+
catch (brandErr) {
|
|
310
|
+
log(`[browser-launch] branding init-script install failed (non-fatal): ${brandErr?.message || brandErr}`);
|
|
311
|
+
}
|
|
312
|
+
try {
|
|
313
|
+
const firstPage = context.pages()[0];
|
|
314
|
+
if (firstPage)
|
|
315
|
+
await firstPage.evaluate(MELAYA_BRAND_SCRIPT);
|
|
316
|
+
}
|
|
317
|
+
catch (brandErr) {
|
|
318
|
+
log(`[browser-launch] branding evaluate on first page failed (non-fatal): ${brandErr?.message || brandErr}`);
|
|
319
|
+
}
|
|
275
320
|
log(`[browser-launch] interactive session active sessionId=${sessionId.slice(0, 16)} engine=${engineId}`);
|
|
276
321
|
onState(sessionId, "active", engine);
|
|
277
322
|
// Detect browser close: context 'close' fires when the user shuts
|