Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support ignoreHTTPSErrors when Playwright browser opens a new page #531

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,13 @@ Options:
(ex: https://vivliostyle.vercel.app/)
--viewer-param <parameters> specify viewer parameters. (ex:
"allowScripts=false&pixelRatio=16")
--proxy-server <proxyServer> HTTP/SOCK proxy server url for underlying Playwright
--proxy-bypass <proxyBypass> optional comma-separated domains to bypass proxy
--proxy-user <proxyUser> optional username for HTTP proxy authentication
--proxy-pass <proxyPass> optional password for HTTP proxy authentication
--log-level <level> specify a log level of console outputs (choices: "silent",
"info", "verbose", "debug", default: "info")
--ignore-https-errors true to ignore HTTPS errors when Playwright browser opens a new page
-h, --help display help for command
```

Expand Down Expand Up @@ -165,8 +170,13 @@ Options:
Vivliostyle viewer [chromium]
Currently, Firefox and Webkit support preview command only!
(choices: "chromium", "firefox", "webkit")
--proxy-server <proxyServer> HTTP/SOCK proxy server url for underlying Playwright
--proxy-bypass <proxyBypass> optional comma-separated domains to bypass proxy
--proxy-user <proxyUser> optional username for HTTP proxy authentication
--proxy-pass <proxyPass> optional password for HTTP proxy authentication
--log-level <level> specify a log level of console outputs (choices: "silent",
"info", "verbose", "debug", default: "info")
--ignore-https-errors true to ignore HTTPS errors when Playwright browser opens a new page
-h, --help display help for command
```

Expand Down
10 changes: 10 additions & 0 deletions docs/api-javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,18 @@ Open a preview of the publication.
| `executableBrowser?` | `string` | - |
| ~~`executableChromium?`~~ | `string` | **Deprecated** |
| `http?` | `boolean` | - |
| `ignoreHttpsErrors?` | `boolean` | - |
| `image?` | `string` | - |
| `input?` | `string` | - |
| `language?` | `string` | - |
| `logLevel?` | `"silent"` \| `"info"` \| `"verbose"` \| `"debug"` | - |
| `preflight?` | `"press-ready"` \| `"press-ready-local"` | - |
| `preflightOption?` | `string`[] | - |
| `pressReady?` | `boolean` | - |
| `proxyBypass?` | `string` | - |
| `proxyPass?` | `string` | - |
| `proxyServer?` | `string` | - |
| `proxyUser?` | `string` | - |
| `quick?` | `boolean` | - |
| `readingProgression?` | `"ltr"` \| `"rtl"` | - |
| `renderMode?` | `"local"` \| `"docker"` | - |
Expand Down Expand Up @@ -160,13 +165,18 @@ Open a preview of the publication.
| `executableBrowser?` | `string` | - |
| ~~`executableChromium?`~~ | `string` | **Deprecated** |
| `http?` | `boolean` | - |
| `ignoreHttpsErrors?` | `boolean` | - |
| `image?` | `string` | - |
| `input?` | `string` | - |
| `language?` | `string` | - |
| `logLevel?` | `"silent"` \| `"info"` \| `"verbose"` \| `"debug"` | - |
| `preflight?` | `"press-ready"` \| `"press-ready-local"` | - |
| `preflightOption?` | `string`[] | - |
| `pressReady?` | `boolean` | - |
| `proxyBypass?` | `string` | - |
| `proxyPass?` | `string` | - |
| `proxyServer?` | `string` | - |
| `proxyUser?` | `string` | - |
| `quick?` | `boolean` | - |
| `readingProgression?` | `"ltr"` \| `"rtl"` | - |
| `renderMode?` | `"local"` \| `"docker"` | - |
Expand Down
10 changes: 10 additions & 0 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ import {

export async function launchBrowser({
browserType,
proxy,
executablePath,
headless,
noSandbox,
disableWebSecurity,
disableDevShmUsage,
}: {
browserType: BrowserType;
proxy:
| {
server: string;
bypass: string | undefined;
username: string | undefined;
password: string | undefined;
}
| undefined;
executablePath: string;
headless: boolean;
noSandbox?: boolean;
Expand All @@ -42,6 +51,7 @@ export async function launchBrowser({
: []),
],
env: { ...process.env, LANG: 'en.UTF-8' },
proxy: proxy,
}
: // TODO: Investigate appropriate settings on Firefox & Webkit
{ executablePath, headless };
Expand Down
30 changes: 30 additions & 0 deletions src/commands/build.parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,30 @@ It is useful that using own viewer that has staging features. (ex: https://vivli
// Currently, Firefox and Webkit support preview command only!`,
// ).choices(['chromium', 'firefox', 'webkit']),
// )
.addOption(
new Option(
'--proxy-server <proxyServer>',
`HTTP/SOCK proxy server url for underlying Playwright`,
),
)
.addOption(
new Option(
'--proxy-bypass <proxyBypass>',
`optional comma-separated domains to bypass proxy`,
),
)
.addOption(
new Option(
'--proxy-user <proxyUser>',
`optional username for HTTP proxy authentication`,
),
)
.addOption(
new Option(
'--proxy-pass <proxyPass>',
`optional password for HTTP proxy authentication`,
),
)
.addOption(
new Option(
'--log-level <level>',
Expand All @@ -161,6 +185,12 @@ It is useful that using own viewer that has staging features. (ex: https://vivli
.choices(['silent', 'info', 'verbose', 'debug'])
.default('info'),
)
.addOption(
new Option(
'--ignore-https-errors',
`true to ignore HTTPS errors when Playwright browser opens a new page`,
),
)
.addOption(new Option('--bypassed-pdf-builder-option <json>').hideHelp())
// TODO: Remove it in the next major version up
.addOption(new Option('--executable-chromium <path>').hideHelp())
Expand Down
5 changes: 5 additions & 0 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ try {
viewer: options.viewer,
viewerParam: options.viewerParam,
// browser: options.browser,
proxyServer: options.proxyServer,
proxyBypass: options.proxyBypass,
proxyUser: options.proxyUser,
proxyPass: options.proxyPass,
logLevel: options.logLevel,
ignoreHttpsErrors: options.ignoreHttpsErrors,
bypassedPdfBuilderOption: options.bypassedPdfBuilderOption,
executableChromium: options.executableChromium, // TODO: Remove it in the next major version up
}).catch(gracefulError);
Expand Down
30 changes: 30 additions & 0 deletions src/commands/preview.parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ It is useful that using own viewer that has staging features. (ex: https://vivli
Currently, Firefox and Webkit support preview command only!`,
).choices(['chromium', 'firefox', 'webkit']),
)
.addOption(
new Option(
'--proxy-server <proxyServer>',
`HTTP/SOCK proxy server url for underlying Playwright`,
),
)
.addOption(
new Option(
'--proxy-bypass <proxyBypass>',
`optional comma-separated domains to bypass proxy`,
),
)
.addOption(
new Option(
'--proxy-user <proxyUser>',
`optional username for HTTP proxy authentication`,
),
)
.addOption(
new Option(
'--proxy-pass <proxyPass>',
`optional password for HTTP proxy authentication`,
),
)
.addOption(
new Option(
'--log-level <level>',
Expand All @@ -77,6 +101,12 @@ Currently, Firefox and Webkit support preview command only!`,
.choices(['silent', 'info', 'verbose', 'debug'])
.default('info'),
)
.addOption(
new Option(
'--ignore-https-errors',
`true to ignore HTTPS errors when Playwright browser opens a new page`,
),
)
// TODO: Remove it in the next major version up
.addOption(new Option('--executable-chromium <path>').hideHelp())
.addOption(new Option('--verbose').hideHelp());
Expand Down
5 changes: 5 additions & 0 deletions src/commands/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ try {
viewer: options.viewer,
viewerParam: options.viewerParam,
browser: options.browser,
proxyServer: options.proxyServer,
proxyBypass: options.proxyBypass,
proxyUser: options.proxyUser,
proxyPass: options.proxyPass,
logLevel: options.logLevel,
ignoreHttpsErrors: options.ignoreHttpsErrors,
executableChromium: options.executableChromium, // TODO: Remove it in the next major version up
}).catch(gracefulError);
} catch (err) {
Expand Down
27 changes: 27 additions & 0 deletions src/input/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,13 @@ export interface CliFlags {
viewer?: string;
viewerParam?: string;
browser?: 'chromium' | 'firefox' | 'webkit';
proxyServer?: string;
proxyBypass?: string;
proxyUser?: string;
proxyPass?: string;
readingProgression?: 'ltr' | 'rtl';
logLevel?: 'silent' | 'info' | 'verbose' | 'debug';
ignoreHttpsErrors?: boolean;
/** @deprecated */ executableChromium?: string;
}

Expand Down Expand Up @@ -239,11 +244,20 @@ export type MergedConfig = {
sandbox: boolean;
executableBrowser: string;
browserType: BrowserType;
proxy:
| {
server: string;
bypass: string | undefined;
username: string | undefined;
password: string | undefined;
}
| undefined;
image: string;
httpServer: boolean;
viewer: string | undefined;
viewerParam: string | undefined;
logLevel: 'silent' | 'info' | 'verbose' | 'debug';
ignoreHttpsErrors: boolean;
} & ManifestConfig;

const DEFAULT_TIMEOUT = 2 * 60 * 1000; // 2 minutes
Expand Down Expand Up @@ -612,6 +626,16 @@ export async function mergeConfig<T extends CliFlags>(
const timeout = cliFlags.timeout ?? config?.timeout ?? DEFAULT_TIMEOUT;
const sandbox = cliFlags.sandbox ?? false;
const browserType = cliFlags.browser ?? config?.browser ?? 'chromium';
const proxyServer =
cliFlags.proxyServer ?? process.env.HTTP_PROXY ?? undefined;
const proxy = proxyServer
? {
server: proxyServer,
bypass: cliFlags.proxyBypass ?? process.env.NOPROXY ?? undefined,
username: cliFlags.proxyUser,
password: cliFlags.proxyPass,
}
: undefined;
const executableBrowser =
cliFlags.executableBrowser ?? getExecutableBrowserPath(browserType);
const image = cliFlags.image ?? config?.image ?? CONTAINER_IMAGE;
Expand All @@ -622,6 +646,7 @@ export async function mergeConfig<T extends CliFlags>(
cliFlags.logLevel ??
((cliFlags.verbose && 'verbose') || undefined) ??
'silent';
const ignoreHttpsErrors = cliFlags.ignoreHttpsErrors ?? false;

const rootThemes = cliFlags.theme
? [
Expand Down Expand Up @@ -810,11 +835,13 @@ export async function mergeConfig<T extends CliFlags>(
sandbox,
executableBrowser,
browserType,
proxy,
image,
httpServer,
viewer,
viewerParam,
logLevel,
ignoreHttpsErrors,
};
if (!cliFlags.input && !config) {
throw new Error(
Expand Down
4 changes: 4 additions & 0 deletions src/output/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export async function buildPDF({
customUserStyle,
singleDoc,
executableBrowser,
proxy,
browserType,
image,
sandbox,
Expand All @@ -94,6 +95,7 @@ export async function buildPDF({
viewer,
viewerParam,
logLevel,
ignoreHttpsErrors,
}: BuildPdfOptions): Promise<string | null> {
const isInContainer = checkContainerEnvironment();
logUpdate(`Launching build environment`);
Expand Down Expand Up @@ -130,6 +132,7 @@ export async function buildPDF({
}
const browser = await launchBrowser({
browserType,
proxy,
executablePath: executableBrowser,
headless: true,
noSandbox: !sandbox,
Expand All @@ -149,6 +152,7 @@ export async function buildPDF({
width: 800,
height: 600,
},
ignoreHTTPSErrors: ignoreHttpsErrors,
});

page.on('pageerror', (error) => {
Expand Down
8 changes: 6 additions & 2 deletions src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function preview(cliFlags: PreviewCliFlags) {
quick: config.quick,
});

const { browserType, executableBrowser } = config;
const { browserType, proxy, executableBrowser } = config;
debug(`Executing browser path: ${executableBrowser}`);
if (!checkBrowserAvailability(executableBrowser)) {
if (isPlaywrightExecutable(executableBrowser)) {
Expand Down Expand Up @@ -156,12 +156,16 @@ export async function preview(cliFlags: PreviewCliFlags) {

const browser = await launchBrowser({
browserType,
proxy,
executablePath: executableBrowser,
headless: false,
noSandbox: !config.sandbox,
disableWebSecurity: !config.viewer,
});
const page = await browser.newPage({ viewport: null });
const page = await browser.newPage({
viewport: null,
ignoreHTTPSErrors: config.ignoreHttpsErrors,
});

// Terminate preview when the previewing page is closed
function onPageClose() {
Expand Down
Loading