Smooth scrolling for demos

Table of Contents

    07 Apr 2025

    Needed to enable smooth scrolling of a long page in Chrome for a demo video.

    Use Automator > Quick Action > Run AppleScript with:

    tell application "Google Chrome"
        set theTab to active tab of front window
        execute theTab javascript "
            const total = document.body.scrollHeight - window.innerHeight;
            let pos = 0;
            const i = setInterval(() => {
                window.scrollBy(0, 2);
                pos += 2;
                if (pos >= total) clearInterval(i);
            }, 10);
        "
    end tell
    

    or via bookmarklet (ie Chrome bookmark) - though this means you have to click on the bookmark (less sophisticated for video recording):

    javascript:(function(){  const total = document.body.scrollHeight - window.innerHeight;  let pos = 0;  const i = setInterval(() => {    window.scrollBy(0, 2);    pos += 2;    if (pos >= total) clearInterval(i);  }, 10);})();
    

    links

    social