reg-viz / storycap

A Storybook Addon, Save the screenshot image of your stories :camera: via puppeteer.
https://www.npmjs.com/package/storycap
MIT License
701 stars 89 forks source link

Navigation timeout of 30000 ms exceeded while waiting for stories definition #800

Open acbonnyac opened 1 year ago

acbonnyac commented 1 year ago

In our team CI/CD pipeline, sometimes it can be slow and failed with timeout error while waiting for Storybook definitions.

Here's an error message:

info Executable Chromium path: /usr/bin/chromium
debug Wait for stories definition.
info => Using default Webpack5 setup
<A bunch of debug logs like "<s> [webpack.Progress] 75% sealing chunk optimization MergeDuplicateChunksPlugin">
error Navigation timeout of 30000 ms exceeded
TimeoutError: Navigation timeout of 30000 ms exceeded
    at <projectRootDir>/node_modules/puppeteer-core/lib/cjs/puppeteer/common/LifecycleWatcher.js:106:111

If I'm guessing right, it probably failed on this line https://github.com/reg-viz/storycap/blob/master/packages/storycrawler/src/browser/stories-browser.ts#L56 while it's waiting for the page to be fully loaded. By default page.goto probably has a timeout of 30 seconds.

If so, could someone help create this as a new option that we can customize, just like serverTimeout? Maybe we can add storiesDefinitionTimeout as another option?

acbonnyac commented 1 year ago

Here's the current workaround I'm using to get around this by spawning a Storybook server ahead and have my own timeout:

import { spawn } from 'child_process';
import { chromium } from 'playwright';
import waitOn from 'wait-on';

async function spawnStorybookServer() {
    const storybookUrl = 'http://localhost:6006';

    console.log(`Starting Storybook server with "npm run ${storybookCommand}"`);
    const storybookServer = spawn(`npm run ${storybookCommand}`, { shell: true });

    console.log(`Waiting for Storybook server to start at ${storybookUrl}`);
    await waitOn({ resources: [storybookUrl], timeout: storybookServerTimeout });
    console.log('Storybook server started');

    console.log('Waiting for Storybook to finish loading');
    const browser = await chromium.launch({
        args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'],
        executablePath: process.env.CHROME_PATH,
    });
    const page = await browser.newPage();
    await page.goto(storybookUrl, { timeout: storybookLoadTimeout });
    await browser.close();
    console.log('Storybook finished loading');

    return storybookServer;
}

await spawnStorybookServer();

This is a code snippet so there are some variables that need to be replaced. But you should get an idea.