Skip to content

Commit 32af9b3

Browse files
authored
fix: expose correct puppeteer launch options interface (#98)
1 parent c36efbc commit 32af9b3

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/lib/config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { WatchOptions } from 'chokidar';
22
import { MarkedOptions } from 'marked';
33
import { resolve } from 'path';
4-
import { FrameAddScriptTagOptions, LaunchOptions, PDFOptions } from 'puppeteer';
4+
import { FrameAddScriptTagOptions, launch, PDFOptions } from 'puppeteer';
55

66
export const defaultConfig: Config = {
77
basedir: process.cwd(),
@@ -114,7 +114,7 @@ interface BasicConfig {
114114
*
115115
* @see https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions
116116
*/
117-
launch_options: LaunchOptions;
117+
launch_options: PuppeteerLaunchOptions;
118118

119119
/**
120120
* Markdown file encoding. Default: `utf-8`.
@@ -144,3 +144,5 @@ interface BasicConfig {
144144
*/
145145
watch_options?: WatchOptions;
146146
}
147+
148+
export type PuppeteerLaunchOptions = Parameters<typeof launch>[0];

src/test/api.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,13 @@ test('compile the MathJax test', async (t) => {
6969
t.true(text.startsWith('Formulas with MathJax'));
7070
t.true(text.includes('a≠0'));
7171
});
72+
73+
test('compile passing some Puppeteer args', async (t) => {
74+
const pdf = await mdToPdf(
75+
{ path: resolve(__dirname, 'basic', 'test.md') },
76+
{ launch_options: { args: [ '--no-sandbox' ] } });
77+
78+
t.is(pdf.filename, '');
79+
t.truthy(pdf.content);
80+
t.truthy(pdf.content instanceof Buffer);
81+
});

src/test/api.type-spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { HtmlOutput, PdfOutput } from '../lib/generate-output';
77
expectType<PdfOutput>(await mdToPdf({ path: 'foo.md' }));
88

99
expectType<PdfOutput>(await mdToPdf({ path: 'foo.md' }, { as_html: false }));
10+
expectType<PdfOutput>(await mdToPdf({ content: 'foo' }, { launch_options: { args: [ '--no-sandbox' ] } }));
1011

1112
expectType<HtmlOutput>(await mdToPdf({ content: 'foo' }, { as_html: true }));
1213
expectType<HtmlOutput>(await mdToPdf({ path: 'foo.md' }, { as_html: true }));

0 commit comments

Comments
 (0)