Take a snapshot of a white-web-sdk scene.
npm install @netless/white-snapshotTake a snapshot of a white-web-sdk scene.
Requires white-web-sdk ≥ 2.16.20.
``js`
import { snapshot } from "@netless/white-snapshot";
// room = await sdk.joinRoom(...)
snapshot(room).then(canvas => {
document.body.append(canvas);
});
`ts`
snapshot(room, {
scenePath: "/init",
padding: 5,
background: 'transparent',
crop: null,
crossorigin: false,
src2dataurl: undefined,
}): Promise
Returns null if failed.
| Option | Type | Default | Description |
| ----------- | ------------------------------------------ | ------------- | ------------------------------------------------------------------------------------------------------- |
| scenePath | string | current scene | Default is displayer.state.sceneState.scenePath. |document.createElement('img')
| padding | number | 5 | Pixels to the border of canvas. |
| background | string | | Background color. |
| crop | Rectangle | null | Apply crop on the snapshot. Note that the snapshot includes padding. |
| crossorigin | boolean | false | Apply hack to to enable crossorigin images. |html2canvas
| src2dataurl | (src: string) ⇒ Promise<string> | | Due to a [limitation][1] in , we must convert images to dataurl before feeding them to it. |
[1]: https://github.com/niklasvh/html2canvas/issues/592#issuecomment-727540799
`bash``
pnpm dev
MIT @ netless