diff --git a/src/index.ts b/src/index.ts index eebfa7f6..8695bd8d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ import { launch, LaunchedChrome } from 'chrome-launcher'; import * as CDP from 'chrome-remote-interface'; +import { Readable, Stream } from 'stream'; import { ChromePrintOptions } from './ChromePrintOptions'; import * as CompletionTrigger from './CompletionTrigger'; @@ -50,6 +51,20 @@ export async function create(html: string, options?: CreateOptions): Promise { + try { + const result = await create(html, options); + stream.push(result.toBase64(), 'base64'); + stream.push(null); + } catch (e) { + stream.emit('error', e); + } + })(); + return stream; +} + /** * Connects to Chrome and generates a PDF from HTML or a URL. *