зеркало из https://github.com/electron/electron.git
fix: properly generate requestID in webContents.printToPDF() (#20769)
This commit is contained in:
Родитель
b6246dcf12
Коммит
bd5a5b3ae6
|
@ -71,7 +71,6 @@ const defaultPrintingSetting = {
|
|||
headerFooterEnabled: false,
|
||||
marginsType: 0,
|
||||
isFirstRequest: false,
|
||||
requestID: getNextId(),
|
||||
previewUIID: 0,
|
||||
previewModifiable: true,
|
||||
printToPDF: true,
|
||||
|
@ -204,7 +203,10 @@ WebContents.prototype.executeJavaScript = function (code, hasUserGesture) {
|
|||
|
||||
// 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
|
||||
}
|
||||
|
|
|
@ -1400,6 +1400,19 @@ describe('webContents module', () => {
|
|||
const data = await w.webContents.printToPDF({})
|
||||
expect(data).to.be.an.instanceof(Buffer).that.is.not.empty()
|
||||
})
|
||||
|
||||
it('does not crash when called multiple times', async () => {
|
||||
const w = new BrowserWindow({ show: false, webPreferences: { sandbox: true } })
|
||||
await w.loadURL('data:text/html,<h1>Hello, World!</h1>')
|
||||
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()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('PictureInPicture video', () => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче