Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to screenshot a part of the screen #722

Merged
merged 1 commit into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ interface ScreenshotOptions {
waitImages?: boolean; // default true
omitBackground?: boolean; // default false
captureBeyondViewport?: boolean; // default true
clip?: { x: number; y: number; width: number; height: number } | null; // default null
}
```

Expand All @@ -262,6 +263,7 @@ interface ScreenshotOptions {
- `waitImages`: Deprecated. Use `waitAssets`. If set true, Storycap waits until `<img>` in the story are loaded.
- `omitBackground`: If set true, Storycap omits the background of the page allowing for transparent screenshots. Note the storybook theme will need to be transparent as well.
- `captureBeyondViewport`: If set true, Storycap captures screenshot beyond the viewport. See also [Puppeteer API docs](https://github.com/puppeteer/puppeteer/blob/v13.1.3/docs/api.md#pagescreenshotoptions).
- `clip`: If set, Storycap captures only the portion of the screen bounded by x/y/width/height.

### type `Variants`

Expand All @@ -283,6 +285,7 @@ type Variants = {
waitImages?: boolean;
omitBackground?: boolean;
captureBeyondViewport?: boolean;
clip?: { x: number; y: number; width: number; height: number } | null;
};
};
```
Expand Down
1 change: 1 addition & 0 deletions packages/storycap/src/node/capturing-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ export class CapturingBrowser extends StoryPreviewBrowser {
fullPage: emittedScreenshotOptions.fullPage,
omitBackground: emittedScreenshotOptions.omitBackground,
captureBeyondViewport: emittedScreenshotOptions.captureBeyondViewport,
clip: emittedScreenshotOptions.clip ?? undefined,
});

let buffer: Buffer | null = null;
Expand Down
1 change: 1 addition & 0 deletions packages/storycap/src/shared/screenshot-options-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const defaultScreenshotOptions = {
variants: {},
omitBackground: false,
captureBeyondViewport: true,
clip: null,
} as const;

/**
Expand Down
1 change: 1 addition & 0 deletions packages/storycap/src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface ScreenshotOptionFragments {
skip?: boolean;
omitBackground?: boolean;
captureBeyondViewport?: boolean;
clip?: { x: number; y: number; width: number; height: number } | null;
}

export interface ScreenshotOptionFragmentsForVariant extends ScreenshotOptionFragments {
Expand Down