Skip to content
Snippets Groups Projects
Commit cb3ad598 authored by Fred Chasen's avatar Fred Chasen
Browse files

Merge branch 'emulate_media' into 'main'

Emulate print media

See merge request !34
parents 3b758ece 53c3d483
No related branches found
No related tags found
1 merge request!34Emulate print media
Pipeline #35899 passed with stages
in 1 minute and 29 seconds
......@@ -41,6 +41,8 @@ program
collect, [])
.option("--browserEndpoint <browserEndpoint>", "Use a remote Chrome server with browserWSEndpoint")
.option("--browserArgs <browserArgs>", "Launch Chrome with comma separated args", commaSeparatedList)
.option("--media [media]", "Emulate \"print\" or \"screen\" media, defaults to print.")
.parse(process.argv);
function collect(value, previous) {
......@@ -115,7 +117,8 @@ if (typeof input === "string") {
additionalScripts: options.additionalScript,
browserEndpoint: options.browserEndpoint,
timeout: options.timeout,
browserArgs: options.browserArgs
browserArgs: options.browserArgs,
emulateMedia: options.media
};
if (options.forceTransparentBackground) {
......
......@@ -30,6 +30,7 @@ class Printer extends EventEmitter {
this.overrideDefaultBackgroundColor = options.overrideDefaultBackgroundColor;
this.timeout = options.timeout || 0;
this.closeAfter = typeof options.closeAfter !== "undefined" ? options.closeAfter : true;
this.emulateMedia = options.emulateMedia || "print";
this.pages = [];
}
......@@ -73,6 +74,8 @@ class Printer extends EventEmitter {
const page = await this.browser.newPage();
page.setDefaultTimeout(this.timeout);
await page.emulateMediaType(this.emulateMedia);
if (this.overrideDefaultBackgroundColor) {
page._client.send("Emulation.setDefaultBackgroundColorOverride", { color: this.overrideDefaultBackgroundColor });
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment