Skip to main content

Frontend development · Intermediate · 25 min

Lazy-load and reveal content with Intersection Observer

By Padding · Updated 18 Nov 2026
Modern browsers · Intersection Observer API · Node.js 26.13 · checked in Chromium with Playwright 1.65.1 on node:26

You will build a noticeboard whose list loads the next page as you near the end, reports which notices were actually read, fades items in only for people who allow motion, and stays usable by keyboard, with a Playwright test that proves it.

On this page

An endless list is quick to start and hard to finish well. The common version listens to scroll, measures the page on every event, and loads more when the user is near the bottom. It runs a lot of code during scrolling, it breaks when the list sits inside a scrolling panel, and it often leaves keyboard users unable to reach the footer, because every time they get close, more content arrives and pushes it away.

IntersectionObserver replaces the measuring. You give it elements to watch and it tells you, off the scroll path, when each one enters or leaves the viewport (or a margin around it). This tutorial uses it for three separate jobs on one page:

  • Loading the next page of a long list when a real "Load more notices" button gets near the viewport. The button stays on the page and works on its own.
  • Reporting which items were actually seen: at least half on screen for a full second, not merely scrolled past.
  • Fading items in as they arrive, but only for people whose system does not ask for reduced motion.

The page is a residents' association noticeboard with 60 notices, served 12 at a time by a small Node.js server. Everything runs on your own machine. The auto-loading also respects data cost, which matters to readers on prepaid mobile data, common across much of Africa: it stops after two automatic pages and does none at all when the browser reports a Save-Data preference.

Step 1 · Serve the notices from a small Node server

Make a demo folder with a public folder for the page. The server has three jobs: return a page of notices as JSON from /api/notices?page=N, accept "seen" reports at /api/seen, and serve the files in public. It uses only Node's built-in modules, so there is nothing to install yet.

Bash
mkdir -p ~/noticeboard-demo/public
cd ~/noticeboard-demo
cat > app.mjs <<'JS'
import { createServer } from 'node:http';
import { readFile } from 'node:fs/promises';
import { extname, join, sep } from 'node:path';
import { fileURLToPath } from 'node:url';

const root = fileURLToPath(new URL('./public', import.meta.url));
const PAGE_SIZE = 12;
const TOTAL = 60;
const topics = ['Water supply', 'Market day', 'School run', 'Clinic hours', 'Bus route', 'Youth club'];

const notices = Array.from({ length: TOTAL }, (_, i) => ({
  id: i + 1,
  title: `${topics[i % topics.length]}: notice ${i + 1}`,
  body: `Posted by the Riverside residents' association. This is notice ${i + 1} of ${TOTAL}.`,
}));

const types = {
  '.html': 'text/html; charset=utf-8',
  '.css': 'text/css; charset=utf-8',
  '.js': 'text/javascript; charset=utf-8',
  '.svg': 'image/svg+xml',
};

export const seen = [];

export function createApp() {
  return createServer(async (req, res) => {
    const url = new URL(req.url, 'http://localhost');

    if (url.pathname === '/api/notices') {
      const page = Math.max(1, Number.parseInt(url.searchParams.get('page'), 10) || 1);
      const start = (page - 1) * PAGE_SIZE;
      const body = {
        items: notices.slice(start, start + PAGE_SIZE),
        nextPage: start + PAGE_SIZE < TOTAL ? page + 1 : null,
        total: TOTAL,
      };
      res.writeHead(200, { 'content-type': 'application/json' });
      res.end(JSON.stringify(body));
      return;
    }

    if (url.pathname === '/api/seen' && req.method === 'POST') {
      let raw = '';
      for await (const chunk of req) raw += chunk;
      try {
        const { id } = JSON.parse(raw);
        if (Number.isInteger(id)) {
          seen.push(id);
          console.log(`seen: notice ${id}`);
        }
      } catch {
        // Ignore malformed reports.
      }
      res.writeHead(204);
      res.end();
      return;
    }

    const file = join(root, url.pathname === '/' ? 'index.html' : url.pathname);
    if (!file.startsWith(root + sep)) {
      res.writeHead(403);
      res.end();
      return;
    }
    try {
      const data = await readFile(file);
      res.writeHead(200, { 'content-type': types[extname(file)] ?? 'application/octet-stream' });
      res.end(data);
    } catch {
      res.writeHead(404);
      res.end('Not found');
    }
  });
}
JS
cat > serve.mjs <<'JS'
import { createApp } from './app.mjs';

const port = Number(process.env.PORT) || 8173;
createApp().listen(port, () => {
  console.log(`Noticeboard on http://localhost:${port}`);
});
JS

The server is split in two on purpose. app.mjs builds the server without starting it, so the browser test at the end can start its own copy on a free port. serve.mjs is the one you run. Each JSON page carries nextPage, which is null on the last page, so the browser never has to work out where the list ends.

Start it in its own terminal window and leave it running while you work:

Bash
cd ~/noticeboard-demo
node serve.mjs

Check it worked

The terminal prints Noticeboard on http://localhost:8173. Open http://localhost:8173/api/notices?page=5 in your browser: you see JSON with 12 notices, ids 49 to 60, and "nextPage":null. Opening http://localhost:8173/ shows Not found for now, because there is no page yet.

Step 2 · Build the list with a working Load more button

Write the page first without any observer. The button must load the next page by itself, so the list works for everyone before you automate anything.

Bash
cd ~/noticeboard-demo/public
cat > index.html <<'HTML'
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Riverside noticeboard</title>
  <link rel="stylesheet" href="style.css">
  <script src="app.js" defer></script>
</head>
<body>
  <header>
    <h1>Riverside noticeboard</h1>
    <p>Notices from the residents' association, newest first.</p>
  </header>
  <main>
    <ol id="notices" class="notices"></ol>
    <p id="status" class="status" role="status"></p>
    <button id="more" class="more" type="button">Load more notices</button>
  </main>
  <footer>
    <h2>Find the association office</h2>
    <img src="map.svg" width="600" height="300" loading="lazy"
         alt="Sketch map: the association office is beside the market, across the road from the clinic">
    <p>Open Monday to Friday, 09:00 to 17:00. <a href="mailto:office@example.org">Email the office</a></p>
  </footer>
</body>
</html>
HTML
cat > style.css <<'CSS'
* { box-sizing: border-box; }
body {
  margin: 0;
  background: #f1f2f4;
  color: #0b0c0e;
  font-family: system-ui, sans-serif;
  line-height: 1.5;
}
header, main, footer { max-width: 40rem; margin: 0 auto; padding: 1rem; }
h1 { margin: 0 0 0.25rem; font-size: 1.75rem; }
.notices { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.75rem; }
.notice {
  min-height: 9rem;
  padding: 1rem;
  background: #ffffff;
  border: 1px solid #d9dce1;
  border-radius: 0.5rem;
}
.notice h2 { margin: 0 0 0.5rem; font-size: 1.125rem; }
.notice h2:focus-visible, .more:focus-visible, footer a:focus-visible {
  outline: 3px solid #2a2d33;
  outline-offset: 3px;
}
.status { min-height: 1.5rem; color: #2a2d33; }
.more {
  min-height: 3rem;
  width: 100%;
  border: 0;
  border-radius: 0.5rem;
  background: #0b0c0e;
  color: #ffffff;
  font: inherit;
  font-weight: 600;
}
footer { border-top: 1px solid #d9dce1; margin-top: 2rem; }
footer img { display: block; max-width: 100%; height: auto; }
footer a { color: inherit; }
CSS
cat > map.svg <<'SVG'
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 300" width="600" height="300">
  <rect width="600" height="300" fill="#f1f2f4"/>
  <rect x="0" y="130" width="600" height="40" fill="#d9dce1"/>
  <rect x="60" y="40" width="160" height="70" fill="#9ba1ac"/>
  <text x="140" y="80" font-family="system-ui, sans-serif" font-size="18" text-anchor="middle" fill="#0b0c0e">Market</text>
  <rect x="240" y="40" width="120" height="70" fill="#0b0c0e"/>
  <text x="300" y="80" font-family="system-ui, sans-serif" font-size="18" text-anchor="middle" fill="#ffffff">Office</text>
  <rect x="240" y="190" width="160" height="70" fill="#6a707b"/>
  <text x="320" y="230" font-family="system-ui, sans-serif" font-size="18" text-anchor="middle" fill="#ffffff">Clinic</text>
</svg>
SVG
cat > app.js <<'JS'
const list = document.querySelector('#notices');
const statusLine = document.querySelector('#status');
const moreButton = document.querySelector('#more');

let nextPage = 1;
let loading = false;
let shown = 0;

function renderNotice(notice) {
  const item = document.createElement('li');
  item.className = 'notice';
  item.dataset.id = String(notice.id);
  const heading = document.createElement('h2');
  heading.tabIndex = -1;
  heading.textContent = notice.title;
  const body = document.createElement('p');
  body.textContent = notice.body;
  item.append(heading, body);
  return item;
}

async function loadNextPage() {
  if (loading || nextPage === null) return [];
  loading = true;
  statusLine.textContent = 'Loading notices…';
  try {
    const response = await fetch(`/api/notices?page=${nextPage}`);
    if (!response.ok) throw new Error(`HTTP ${response.status}`);
    const data = await response.json();
    const added = data.items.map(renderNotice);
    list.append(...added);
    shown += added.length;
    nextPage = data.nextPage;
    if (nextPage === null) {
      moreButton.hidden = true;
      statusLine.textContent = `All ${data.total} notices shown.`;
    } else {
      statusLine.textContent = `Showing ${shown} of ${data.total} notices.`;
    }
    list.dispatchEvent(new CustomEvent('notices:added', { detail: added }));
    return added;
  } catch {
    statusLine.textContent = 'Could not load notices. Check your connection and press Load more to try again.';
    return [];
  } finally {
    loading = false;
  }
}

moreButton.addEventListener('click', async () => {
  const added = await loadNextPage();
  // Move focus to the first new notice, so keyboard and screen reader
  // users carry on reading where the new content starts.
  if (added.length > 0) added[0].querySelector('h2').focus();
});

loadNextPage();
JS

A few choices here carry the accessibility:

  • Focus moves only after a button press. When someone presses Load more, focus lands on the first new notice's heading, which has tabindex="-1" so a script can focus it without adding it to the Tab order. Without this, focus would stay on the button at the bottom and the new notices would sit unread above it.
  • role="status" makes the status line a polite live region, so a screen reader announces "Showing 24 of 60 notices." after the current sentence instead of interrupting.
  • The notices:added event is a seam for the next steps. Each observer listens for it and starts watching the new items, so loadNextPage never needs to know about them.

The "…" at the end of "Loading notices…" is a single ellipsis character, so a screen reader does not read out three full stops.

Check it worked

Open http://localhost:8173/. You see the heading, 12 white notice cards, Showing 12 of 60 notices. and a dark Load more notices button, then the footer with a small grey map. Press Tab until the button is focused (a dark ring appears around it) and press Enter. Twelve more notices appear, the status says Showing 24 of 60 notices., and the page scrolls to Water supply: notice 13, which now has the focus ring.

Step 3 · Load the next page as the button nears the viewport

Now automate it. Rather than an invisible sentinel element, watch the Load more button itself. It is always directly after the last notice, so "the button is close to the screen" means "the reader is close to the end of the list". If the observer never fires, for any reason, the button is still there.

Append the auto-loader to app.js:

Bash
cd ~/noticeboard-demo/public
cat >> app.js <<'JS'

// Job 1: load the next page when the Load more button nears the viewport.
const saveData = navigator.connection?.saveData === true;
let autoLoadsLeft = saveData ? 0 : 2;

const autoLoader = new IntersectionObserver(async (entries) => {
  if (!entries.some((entry) => entry.isIntersecting)) return;
  autoLoader.unobserve(moreButton);
  autoLoadsLeft -= 1;
  await loadNextPage();
  if (nextPage === null) {
    autoLoader.disconnect();
  } else if (autoLoadsLeft > 0) {
    // Observing again gives an immediate reading, so if the button is
    // still inside the margin on a tall screen, the next page loads too.
    autoLoader.observe(moreButton);
  } else {
    statusLine.textContent += ' Press Load more to see older notices.';
  }
}, { rootMargin: '0px 0px 600px 0px' });

// Start watching only once the first page is on screen.
list.addEventListener('notices:added', () => {
  if (autoLoadsLeft > 0) autoLoader.observe(moreButton);
}, { once: true });
JS

How the options shape it:

  • rootMargin: '0px 0px 600px 0px' grows the viewport by 600 pixels at the bottom, for the observer's purposes only. The button counts as intersecting when it is still 600 pixels below the screen, so the next page usually arrives before the reader gets there. A negative value would shrink the area instead.
  • No threshold means the default of 0: the callback runs as soon as any part of the button enters that area, and again when it leaves.
  • unobserve before loading stops a second callback from firing while the request is in flight. observe again afterwards is the trick that handles tall screens: a fresh observe() always delivers one immediate reading, so if 12 notices were not enough to push the button out of range, the next page loads straight away. A callback only fires on a change otherwise, and nothing would have changed.
  • disconnect() stops watching everything once the server says there is no next page.

The cap of two automatic pages is what keeps the footer reachable. Someone paging down with the Space bar or a screen reader's reading keys would otherwise chase a footer that keeps moving. After two pages the list waits for a button press, which is also the moment focus management takes over. Infinite scroll that never stops makes the footer unreachable by keyboard, which fails WCAG 2.2 success criterion 2.1.1 Keyboard; the cap and the real button avoid that.

navigator.connection.saveData is true when someone has turned on a data saver that the browser passes on. Only Chromium-based browsers expose it, which is why the code uses ?. and treats "unknown" as "no preference". Data saver users get no automatic loads at all, so every megabyte they spend is one they chose.

Check it worked

Reload the page and scroll down slowly. Before you reach the end of the first 12 notices, the status changes to Showing 24 of 60 notices., then later Showing 36 of 60 notices. with Press Load more to see older notices. after it. Keep scrolling: no more load by themselves, and you can scroll right down to the footer. Press Load more once: the list grows to 48 and focus lands on notice 37. Press Tab twice: focus goes to the Load more button, then to the Email the office link in the footer, and nothing new loads on the way.

Step 4 · Report notices that were actually seen

A notice that flew past during a fast scroll has not been read. Here, a notice counts as seen when at least half of it has been on screen for one second. Each notice is reported once, then no longer watched.

Bash
cd ~/noticeboard-demo/public
cat >> app.js <<'JS'

// Job 2: report a notice once at least half of it has been visible for 1 s.
const SEEN_AFTER_MS = 1000;
const seenTimers = new Map();

function markSeen(item) {
  seenTimers.delete(item);
  seenObserver.unobserve(item);
  item.dataset.seen = 'true';
  navigator.sendBeacon('/api/seen', JSON.stringify({ id: Number(item.dataset.id) }));
}

const seenObserver = new IntersectionObserver((entries) => {
  for (const entry of entries) {
    const item = entry.target;
    if (entry.isIntersecting && entry.intersectionRatio >= 0.5) {
      if (!seenTimers.has(item)) {
        seenTimers.set(item, setTimeout(() => markSeen(item), SEEN_AFTER_MS));
      }
    } else {
      clearTimeout(seenTimers.get(item));
      seenTimers.delete(item);
    }
  }
}, { threshold: 0.5 });

list.addEventListener('notices:added', (event) => {
  for (const item of event.detail) seenObserver.observe(item);
});
JS

threshold: 0.5 asks for a callback whenever a notice crosses the halfway mark in either direction: when it becomes at least half visible, and when it drops back below. The code still checks intersectionRatio because the immediate reading after observe() arrives for every new notice, including ones only a sliver of which is showing. The timer starts on the way in and is cancelled on the way out, so only a notice that stays put for a second gets reported.

navigator.sendBeacon sends a small POST that the browser finishes even if the reader closes the tab straight after, and it never delays the page. The server prints each report and keeps the ids in memory. In a real product this is where you would batch reports and store them, and say so in your privacy notice.

Check it worked

Restart the server to clear the reports it holds in memory from earlier visits (Ctrl+C, then node serve.mjs), reload the page and wait a second. The server terminal prints lines such as seen: notice 1, seen: notice 2 and so on for the notices on your screen. Scroll quickly to the bottom: notices that flew past are not printed. Stop on one notice for a second and it is printed once; scroll away and back and it is not printed again.

Step 5 · Fade notices in only when motion is welcome

The third job is decoration, so it must never hide content from anyone. Two rules make that safe. The hidden starting state only applies when the html element has a reveal-ready class, which the script adds, so without JavaScript nothing is hidden. And the script skips the whole effect when the system asks for reduced motion.

Bash
cd ~/noticeboard-demo/public
cat >> style.css <<'CSS'

@media (prefers-reduced-motion: no-preference) {
  .reveal-ready .notice {
    transition: opacity 400ms ease-out, transform 400ms ease-out;
  }
  .reveal-ready .notice:not(.is-revealed) {
    opacity: 0;
    transform: translateY(1rem);
  }
}
CSS
cat >> app.js <<'JS'

// Job 3: fade notices in as they scroll into view, unless motion is reduced.
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;

if (!reduceMotion) {
  document.documentElement.classList.add('reveal-ready');
  const revealer = new IntersectionObserver((entries) => {
    for (const entry of entries) {
      if (!entry.isIntersecting) continue;
      entry.target.classList.add('is-revealed');
      revealer.unobserve(entry.target);
    }
  }, { rootMargin: '0px 0px -10% 0px' });

  list.addEventListener('notices:added', (event) => {
    for (const item of event.detail) revealer.observe(item);
  });
}
JS

Here the margin is negative: -10% at the bottom shrinks the observed area, so a notice starts its fade once it is a little way into the screen rather than while still at the very edge, where nobody would see it. Each notice is unobserved after its reveal, so scrolling back up does not fade it again.

The media query and the script check the same preference. The CSS check alone would be enough to stop the movement, but checking in the script too means people who asked for less motion do not run an observer for an effect they will never see.

Check it worked

Reload. The first notices fade and slide up into place, and as you scroll, each new notice does the same once it is a short way onto the screen. Now turn on your system's reduced motion setting (on macOS: System Settings, Accessibility, Display, Reduce motion; on Windows: Settings, Accessibility, Visual effects, Animation effects off; on Android, something like Settings, Accessibility, Color and motion, Remove animations) and reload: the notices are there at once, with no fade.

Step 6 · Leave images to loading="lazy"

You may be tempted to lazy-load images with the same observer: put the address in data-src and copy it to src on intersection. For ordinary images, do not. The footer map already uses the browser's own lazy loading:

HTML
<img src="map.svg" width="600" height="300" loading="lazy"
     alt="Sketch map: the association office is beside the market, across the road from the clinic">

loading="lazy" beats a hand-made observer on every count that matters. It works with JavaScript turned off or failed. The address stays in src, where the browser, search engines and the srcset choice can all see it. And the browser decides how far ahead to start loading, taking the connection into account, which a fixed rootMargin cannot. The width and height attributes reserve the right space before the file arrives, so nothing jumps.

Two rules go with it. Never lazy-load the image people see first on screen, such as a hero image, because that delays the most important picture on the page. And keep IntersectionObserver for things the browser cannot do for you: data, analytics and effects, as in this tutorial. Choosing the right image file for each screen is covered in serve responsive images with srcset and picture.

Check it worked

In your browser's developer tools, inspect the map in the footer: the img element shows loading="lazy", width="600" and height="300". Open the Network panel, filter it to images and reload with the page at the top: on a fast connection, with the footer several screens down, map.svg is not in the list until you scroll towards the footer. Exactly how early it loads depends on your browser and connection.

Step 7 · Prove it in a browser with Playwright

Clicking through by hand catches problems once. A test catches them every time the code changes. Install Playwright in the demo folder. --with-deps also installs the system libraries Chromium needs on Linux, and can ask for your password:

Bash
cd ~/noticeboard-demo
npm init -y > /dev/null
npm install playwright@1.65.1
npx playwright install --with-deps chromium

The test starts its own copy of the server on a free port, so it does not clash with the one you left running. It checks all three jobs on a phone-sized screen, then the reduced motion case in a second browser context.

Bash
cd ~/noticeboard-demo
cat > test-noticeboard.mjs <<'JS'
import { chromium } from 'playwright';
import assert from 'node:assert/strict';
import { createApp, seen } from './app.mjs';

const server = createApp().listen(0);
await new Promise((resolve) => server.once('listening', resolve));
const url = `http://localhost:${server.address().port}/`;

const browser = await chromium.launch();
const viewport = { width: 390, height: 844 };
const page = await browser.newPage({ viewport, reducedMotion: 'no-preference' });
const notices = page.locator('.notice');
const status = page.getByRole('status');
const toBottom = () => page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));

// First page only: the button starts more than 600px below the screen.
await page.goto(url);
await status.filter({ hasText: 'Showing 12 of 60' }).waitFor();
await page.waitForTimeout(500);
assert.equal(await notices.count(), 12, 'no automatic load before scrolling');

// Seen: notice 1 is reported after a second on screen; notice 12 is not.
await page.locator('.notice[data-id="1"][data-seen="true"]').waitFor();
assert.equal(await page.locator('.notice[data-id="12"]').getAttribute('data-seen'), null);

// Reveal: notice 12 starts hidden and fades in once scrolled to.
const notice12 = page.locator('.notice[data-id="12"]');
assert.equal(await notice12.evaluate((el) => getComputedStyle(el).opacity), '0');
await notice12.evaluate((el) => el.scrollIntoView({ block: 'center' }));
await page.waitForFunction(() => getComputedStyle(document.querySelector('.notice[data-id="12"]')).opacity === '1');
await page.locator('.notice[data-id="12"][data-seen="true"]').waitFor();

// Auto-load: scrolling to notice 12 brings page 2, the bottom brings page 3, then it stops.
await page.waitForFunction(() => document.querySelectorAll('.notice').length >= 24);
await toBottom();
await page.waitForFunction(() => document.querySelectorAll('.notice').length >= 36);
await toBottom();
await page.waitForTimeout(800);
assert.equal(await notices.count(), 36, 'no third automatic load');
assert.match(await status.textContent(), /Showing 36 of 60 notices\. Press Load more/);

// Keyboard: Enter on the button loads page 4 and moves focus to notice 37.
const more = page.getByRole('button', { name: 'Load more notices' });
await more.focus();
await page.keyboard.press('Enter');
await status.filter({ hasText: 'Showing 48 of 60' }).waitFor();
assert.equal(await page.evaluate(() => document.activeElement.closest('.notice')?.dataset.id), '37');

// Tab from the heading reaches the button, and the next Tab the footer link.
await page.keyboard.press('Tab');
assert.equal(await page.evaluate(() => document.activeElement.id), 'more');
await page.keyboard.press('Tab');
assert.equal(await page.evaluate(() => document.activeElement.textContent), 'Email the office');

// The last page hides the button and says so.
await more.click();
await status.filter({ hasText: 'All 60 notices shown.' }).waitFor();
assert.equal(await notices.count(), 60);
assert.equal(await more.isHidden(), true);

// Each seen notice was reported to the server once.
await page.waitForTimeout(300);
assert.ok(seen.includes(1) && seen.includes(12), 'notices 1 and 12 reported');
assert.equal(new Set(seen).size, seen.length, 'no duplicate reports');

// The footer map is lazy and has its space reserved.
const map = page.getByRole('img', { name: /Sketch map/ });
assert.equal(await map.getAttribute('loading'), 'lazy');
await map.scrollIntoViewIfNeeded();
await page.waitForFunction(() => document.querySelector('footer img').complete);
assert.ok(await map.evaluate((img) => img.naturalWidth > 0), 'map loaded');

// Reduced motion: nothing is hidden and no reveal class is set.
const calm = await browser.newPage({ viewport, reducedMotion: 'reduce' });
await calm.goto(url);
await calm.getByRole('status').filter({ hasText: 'Showing 12 of 60' }).waitFor();
assert.equal(await calm.evaluate(() => document.documentElement.classList.contains('reveal-ready')), false);
assert.equal(await calm.locator('.notice[data-id="12"]').evaluate((el) => getComputedStyle(el).opacity), '1');

await browser.close();
server.closeAllConnections();
server.close();
console.log('PASS: noticeboard loads, reports and reveals as expected');
JS
node test-noticeboard.mjs

The test reads the page the way people do. It waits for the status text a screen reader would announce, presses Enter and Tab instead of calling functions, and checks where focus ends up. The pauses after scrolling (waitForTimeout) give an observer that should not fire a fair chance to fire, so "no third automatic load" is a real result and not a race.

Check it worked

The output includes seen: notice lines from the server and ends with PASS: noticeboard loads, reports and reveals as expected. To watch it fail for the right reason, change let autoLoadsLeft = saveData ? 0 : 2; to : 5 in public/app.js and run node test-noticeboard.mjs again: the next scroll to the bottom loads a fourth page, so it stops with an AssertionError at "no third automatic load" (48 notices, not 36) and prints no PASS line. Change it back and the test passes.

Step 8 · Clean up

Stop the server you started earlier with Ctrl+C in its terminal. Then remove the demo folder, which also removes the local Playwright install. The Chromium build Playwright downloaded stays in its shared cache; npx playwright uninstall removes it too if you no longer need it.

Bash
cd ~
rm -rf ~/noticeboard-demo

Check it worked

ls ~/noticeboard-demo reports that there is no such file or directory, and http://localhost:8173/ no longer loads in your browser.

Next steps

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Digital Transformation

Get new tutorials

New tutorials, about twice a month.