Skip to content

Passing a storybook URL that contains a query string parameter fails #984

@josephluck

Description

@josephluck

Running storycap with a URL that contains a query parameter fails to load, for example:

npx storycap http://localhost:6006\?theme\=dark
info Wait for connecting storybook server http://localhost:6006?theme=dark.
info Executable Chromium path: <redacted>
error waiting for function failed: timeout 60000ms exceeded

It appears to be due to storycrawler assuming the URL doesn't contain query string parameters, i.e.:

https://github.com/reg-viz/storycap/blob/master/packages/storycrawler/src/browser/stories-browser.ts#L70

Where it attempts to visit this.connection.url + '/iframe.html?selectedKind=story-crawler-kind&selectedStory=story-crawler-story', which in the above example would resolve to 'http://localhost:6006?theme=dark/iframe.html?selectedKind=story-crawler-kind&selectedStory=story-crawler-story'

Expected outcome

Query parameters are present when storycap loads each story.

Why?

It's possible to initialise Storybook globals using query string parameters. This is useful for capturing multiple themes without needing to re-build Storybook, for example.

How?

Split this.connection.url in to hostname and search. Use hostname as the base URL (this.connection.url) and merge search (query string params) in to the ones that storycrawler adds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions