fix: properly generate requestID in webContents.printToPDF() (#20769) (#20811)

This commit is contained in:
Milan Burda
2019-10-30 06:38:09 +01:00
committed by Cheng Zhao
parent 36fd0e9b37
commit 4a5f89d5c7
2 changed files with 23 additions and 2 deletions

View File

@@ -72,7 +72,6 @@ const defaultPrintingSetting = {
headerFooterEnabled: false,
marginsType: 0,
isFirstRequest: false,
requestID: getNextId(),
previewUIID: 0,
previewModifiable: true,
printToPDF: true,
@@ -240,7 +239,10 @@ WebContents.prototype.takeHeapSnapshot = function (filePath) {
// Translate the options of printToPDF.
WebContents.prototype.printToPDF = function (options) {
const printingSetting = Object.assign({}, defaultPrintingSetting)
const printingSetting = {
...defaultPrintingSetting,
requestID: getNextId()
}
if (options.landscape) {
printingSetting.landscape = options.landscape
}

View File

@@ -1279,6 +1279,25 @@ describe('webContents module', () => {
assert.notStrictEqual(data.length, 0)
})
it('does not crash when called multiple times', async () => {
w.destroy()
w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true
}
})
await w.loadURL('data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E')
const promises = []
for (let i = 0; i < 2; i++) {
promises.push(w.webContents.printToPDF({}))
}
const results = await Promise.all(promises)
for (const data of results) {
expect(data).to.be.an.instanceof(Buffer).that.is.not.empty()
}
})
// TODO(miniak): remove when promisification is complete
it('can print to PDF (callback)', (done) => {
w.destroy()