Skip to content

Commit

Permalink
fix: 🐛 (xgplayer) 修复截图在部分机型失败的问题 #1396
Browse files Browse the repository at this point in the history
  • Loading branch information
gemxx committed May 14, 2024
1 parent 8c5828e commit 2e6ba92
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/xgplayer/src/plugins/screenShot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,26 @@ export default class ScreenShot extends IconPlugin {
const saveLink = document.createElement('a')
saveLink.href = data
saveLink.download = filename
const event = document.createEvent('MouseEvents')
event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
saveLink.dispatchEvent(event)

let event
try {
if (typeof MouseEvent !== 'undefined') {
event = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
})
} else {
event = document.createEvent('MouseEvents')
event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
}
} catch (e) {
console.error('MouseEvent unsupported', e)
}

if (event) {
saveLink.dispatchEvent(event)
}
}

createCanvas (width, height) {
Expand Down

0 comments on commit 2e6ba92

Please sign in to comment.