fix: bad error passing webContents.print(null)
(#38612)
fix: bad error passing webContents.print(null)
This commit is contained in:
parent
86824c070e
commit
c5972ba43c
1 changed files with 27 additions and 29 deletions
|
@ -335,36 +335,34 @@ WebContents.prototype.printToPDF = async function (options) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
WebContents.prototype.print = function (options: ElectronInternal.WebContentsPrintOptions = {}, callback) {
|
// TODO(codebytere): deduplicate argument sanitization by moving rest of
|
||||||
// TODO(codebytere): deduplicate argument sanitization by moving rest of
|
// print param logic into new file shared between printToPDF and print
|
||||||
// print param logic into new file shared between printToPDF and print
|
WebContents.prototype.print = function (printOptions: ElectronInternal.WebContentsPrintOptions, callback) {
|
||||||
if (typeof options === 'object') {
|
const options = printOptions ?? {};
|
||||||
// Optionally set size for PDF.
|
if (options.pageSize) {
|
||||||
if (options.pageSize !== undefined) {
|
const pageSize = options.pageSize;
|
||||||
const pageSize = options.pageSize;
|
if (typeof pageSize === 'object') {
|
||||||
if (typeof pageSize === 'object') {
|
if (!pageSize.height || !pageSize.width) {
|
||||||
if (!pageSize.height || !pageSize.width) {
|
throw new Error('height and width properties are required for pageSize');
|
||||||
throw new Error('height and width properties are required for pageSize');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dimensions in Microns - 1 meter = 10^6 microns
|
|
||||||
const height = Math.ceil(pageSize.height);
|
|
||||||
const width = Math.ceil(pageSize.width);
|
|
||||||
if (!isValidCustomPageSize(width, height)) {
|
|
||||||
throw new Error('height and width properties must be minimum 352 microns.');
|
|
||||||
}
|
|
||||||
|
|
||||||
options.mediaSize = {
|
|
||||||
name: 'CUSTOM',
|
|
||||||
custom_display_name: 'Custom',
|
|
||||||
height_microns: height,
|
|
||||||
width_microns: width
|
|
||||||
};
|
|
||||||
} else if (PDFPageSizes[pageSize]) {
|
|
||||||
options.mediaSize = PDFPageSizes[pageSize];
|
|
||||||
} else {
|
|
||||||
throw new Error(`Unsupported pageSize: ${pageSize}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dimensions in Microns - 1 meter = 10^6 microns
|
||||||
|
const height = Math.ceil(pageSize.height);
|
||||||
|
const width = Math.ceil(pageSize.width);
|
||||||
|
if (!isValidCustomPageSize(width, height)) {
|
||||||
|
throw new Error('height and width properties must be minimum 352 microns.');
|
||||||
|
}
|
||||||
|
|
||||||
|
options.mediaSize = {
|
||||||
|
name: 'CUSTOM',
|
||||||
|
custom_display_name: 'Custom',
|
||||||
|
height_microns: height,
|
||||||
|
width_microns: width
|
||||||
|
};
|
||||||
|
} else if (PDFPageSizes[pageSize]) {
|
||||||
|
options.mediaSize = PDFPageSizes[pageSize];
|
||||||
|
} else {
|
||||||
|
throw new Error(`Unsupported pageSize: ${pageSize}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue