Confusing simulation editing results

@Eric Eric
Thu, 04 Sep 2025 15:15:23 +0000

Hi everyone, I recently encountered a strange phenomenon. I used a headless browser to open Yjs Prosemirror Example, and then simulated input, enabling 10 pages and inputting 40 times on each page to simulate collaborative editing. However, I got an incorrect result, as shown below:
Each ‘This is User’ should have 40 entries, but there were more than that.

and some garbled data.

This is my test code

const puppeteer = require('puppeteer');

(async () => {
    const collabUserCount = 10;
    const typeCount = 40;

    const collabUserList = new Array(collabUserCount).fill(0).map((_, index) => index + 1);
    const collabUserMap = {};

    for(let i=0; i<collabUserList.length; i++) {
        const browser = await puppeteer.launch({ headless: true });
        const page = await browser.newPage();
        await page.goto('https://demos.yjs.dev/prosemirror/prosemirror.html');
        collabUserMap[`page「${i}」`] = page;

    }
    await wait(10000);

    for(let page=0; page<typeCount; page++) {
        for (let userIndex=0; userIndex<collabUserList.length; userIndex++) {
            const currPage = collabUserMap[`page「${userIndex}」`];
            const ProseMirrorContent = await currPage.$('.ProseMirror');
            await ProseMirrorContent.focus();
            const text = 'This is User：' + userIndex + '----' + new Array(20).fill(String(page)).join('');
            await currPage.keyboard.sendCharacter(text);
            await currPage.keyboard.press('Enter');

            await wait(10);
        }
    }
    console.log('End');
})();

function wait(delay) {
    return new Promise(resolve => setTimeout(resolve, delay));
}

There are two odd things here.

1. The same test code at ProseMirror collab example is completely correct.

2. If I adjust the order, Enter first works correctly.

await currPage.keyboard.press('Enter');
await currPage.keyboard.sendCharacter(text);

Can someone help me? This has been bothering me for a long time, thank you very much