fix: properly generate requestID in webContents.printToPDF() (#20812)
This commit is contained in:
Родитель
f607693679
Коммит
7801e3e560
|
@ -71,7 +71,6 @@ const defaultPrintingSetting = {
|
|||
headerFooterEnabled: false,
|
||||
marginsType: 0,
|
||||
isFirstRequest: false,
|
||||
requestID: getNextId(),
|
||||
previewUIID: 0,
|
||||
previewModifiable: true,
|
||||
printToPDF: true,
|
||||
|
@ -265,7 +264,10 @@ WebContents.prototype.takeHeapSnapshot = function (filePath) {
|
|||
|
||||
// Translate the options of printToPDF.
|
||||
WebContents.prototype.printToPDF = function (options, callback) {
|
||||
const printingSetting = Object.assign({}, defaultPrintingSetting)
|
||||
const printingSetting = {
|
||||
...defaultPrintingSetting,
|
||||
requestID: getNextId()
|
||||
}
|
||||
if (options.landscape) {
|
||||
printingSetting.landscape = options.landscape
|
||||
}
|
||||
|
|
|
@ -1284,5 +1284,30 @@ describe('webContents module', () => {
|
|||
})
|
||||
w.loadURL('data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E')
|
||||
})
|
||||
|
||||
it('does not crash when called multiple times', (done) => {
|
||||
w.destroy()
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
sandbox: true
|
||||
}
|
||||
})
|
||||
w.webContents.once('did-finish-load', () => {
|
||||
const count = 2
|
||||
let current = 0
|
||||
for (let i = 0; i < count; i++) {
|
||||
w.webContents.printToPDF({}, function (error, data) {
|
||||
assert.strictEqual(error, null)
|
||||
assert.strictEqual(data instanceof Buffer, true)
|
||||
assert.notStrictEqual(data.length, 0)
|
||||
if (++current === count) {
|
||||
done()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
w.loadURL('data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Загрузка…
Ссылка в новой задаче