Skip to content

Commit

Permalink
Merge pull request #722 from Jamie5/partialScreenshot
Browse files Browse the repository at this point in the history
Add the ability to screenshot a part of the screen
  • Loading branch information
Quramy authored Apr 19, 2023
2 parents d8b02ab + c8b7678 commit d014ec9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
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

0 comments on commit d014ec9

Please sign in to comment.