Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(x-content): survive a busy render loop when pausing the clock, and a page with no body

nirholase02e47e9bef4
diff --git a/api/_lib/x-content/reel.js b/api/_lib/x-content/reel.js
index bc6179f7f..5e8e2d602 100644
--- a/api/_lib/x-content/reel.js
+++ b/api/_lib/x-content/reel.js
@@ -75,6 +75,8 @@ const CUT_BADGE_AFTER_SEC = 2;
const CUT_BADGE_FRAMES = 45;
const MOVE_FRAMES = 12;
const LOCATE_FRAMES = 60;
+const PAUSE_MARGIN_MS = 750;
+const PAUSE_ATTEMPTS = 4;
const RIPPLE_FRAMES = 9;
const TYPE_FRAMES_PER_CHAR = 2;
@@ -140,6 +142,7 @@ export function scenarioProblems(scenario) {
break;
case 'press':
if (typeof step.press !== 'string' || !step.press) problems.push(`${at}: press needs a key name such as Enter`);
+ if (step.hold !== undefined && !between(step.hold, LIMITS.holdMs)) problems.push(`${at}: hold is ${LIMITS.holdMs[0]} to ${LIMITS.holdMs[1]} ms of the key held down`);
break;
case 'expect':
if (typeof step.expect !== 'string' || !step.expect.trim()) problems.push(`${at}: expect needs the text that only appears once the feature worked`);
@@ -378,11 +381,22 @@ class Take {
this.cuts = [];
}
+ // The pause lands a little ahead of the page's clock. A page with a live
+ // render loop can run past a narrow margin between the read and the pause
+ // ("Cannot fast-forward to the past"), so the margin is generous and a miss
+ // is read again and retried.
async pause() {
if (this.paused) return;
- const pageNow = await this.page.evaluate(() => Date.now());
- await this.page.clock.pauseAt(pageNow + 50);
- this.paused = true;
+ for (let attempt = 1; attempt <= PAUSE_ATTEMPTS; attempt++) {
+ const pageNow = await this.page.evaluate(() => Date.now());
+ try {
+ await this.page.clock.pauseAt(pageNow + PAUSE_MARGIN_MS * attempt);
+ this.paused = true;
+ return;
+ } catch (err) {
+ if (attempt === PAUSE_ATTEMPTS || !/past/i.test(String(err.message))) throw err;
+ }
+ }
}
async resume() {
@@ -570,11 +584,19 @@ const STEPS = {
}
return `typed ${step.type.length} characters${await settleResponse(take, step, index, run, pending)}`;
},
+ // A tap by default. With `hold`, the key stays down for that much page
+ // time, filmed, which is how a character is walked with W or an arrow key.
async press(take, step, index, run) {
const pending = armResponse(take, step);
- await take.page.keyboard.press(step.press);
+ if (step.hold) {
+ await take.page.keyboard.down(step.press);
+ await take.frames(Math.round((step.hold / 1000) * take.fps));
+ await take.page.keyboard.up(step.press);
+ } else {
+ await take.page.keyboard.press(step.press);
+ }
await take.frames(6);
- return `pressed ${step.press}${await settleResponse(take, step, index, run, pending)}`;
+ return `${step.hold ? `held ${step.press} for ${step.hold} ms` : `pressed ${step.press}`}${await settleResponse(take, step, index, run, pending)}`;
},
async expect(take, step, index) {
const within = step.within ?? 45_000;
diff --git a/api/_lib/x-content/verify.js b/api/_lib/x-content/verify.js
index cb8318f3e..47473df79 100644
--- a/api/_lib/x-content/verify.js
+++ b/api/_lib/x-content/verify.js
@@ -103,13 +103,16 @@ export function createPageReader() {
{ polling: 1000, timeout: 30_000 },
)
.catch(() => {});
- const text = await page.evaluate(() => document.body.innerText);
+ // A page can answer before its body has mounted; an empty body is
+ // a failed check, not a crash of the whole review.
+ const text = await page.evaluate(() => document.body?.innerText || document.documentElement?.innerText || '');
// The page without its shell. A claim check matches against the
// whole body, correctly, because that is what a reader sees; but
// a fact harvested for an announcement must come from the surface
// itself, and the site's mega-menu puts three hundred lines of
// other products' copy above every page's own first word.
const main = await page.evaluate(() => document.querySelector('main')?.innerText || '');
+ if (!text.trim()) return { status, text: '', raw: '', main: '' };
// `text` is normalized for substring checks; `raw` keeps the line
// breaks and casing the announcement brief harvests facts from.
const result = { status, text: normalize(text), raw: text, main };
diff --git a/docs/x-story-authoring.md b/docs/x-story-authoring.md
index 7cbc1bad3..ba62f683c 100644
--- a/docs/x-story-authoring.md
+++ b/docs/x-story-authoring.md
@@ -108,7 +108,7 @@ covers the thing you meant to film.
| `{ "click": "Search" }` | Moves the pointer to the control with that text and clicks it. `{ "click": { "selector": "#go" } }` when the control has no text. | yes |
| `{ "hover": "Preview" }` | Moves the pointer onto a control. | yes |
| `{ "type": "trading bots", "into": "Search by meaning" }` | Clicks the field whose placeholder or label matches `into`, then types. | yes |
-| `{ "press": "Enter" }` | Presses a key. | yes |
+| `{ "press": "Enter" }` | Presses a key. `{ "press": "w", "hold": 2000 }` holds it down for 2 s of page time, which is how a character is walked. | yes |
| `{ "drag": [[0.3, 0.5], [0.7, 0.5]], "ms": 1500 }` | Drags across the viewport, as fractions of its width and height. This is how you orbit a 3D scene. | yes |
| `{ "scroll": 500, "ms": 1000 }` | Scrolls by pixels, or to a text: `{ "scroll": "Pricing" }`. | yes |
| `{ "expect": "Closest to", "within": 45000 }` | Waits until the text is on screen. Add `"film": true` to film the wait. | no |