diff --git a/src/index.ts b/src/index.ts index eebfa7f6..23a32870 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'; @@ -86,6 +87,20 @@ async function generate(html: string, options: CreateOptions): Promise { + try { + const result = await generate(html, options); + stream.push(result.toBase64(), 'base64'); + stream.push(null); + } catch (e) { + stream.emit('error', e); + } + })(); + return stream; +} + /** * Throws an exception if the operation has been canceled. *