Skip to content

Instantly share code, notes, and snippets.

@ybootin
Last active January 6, 2016 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ybootin/fe380cd7265a90fa9e35 to your computer and use it in GitHub Desktop.
Save ybootin/fe380cd7265a90fa9e35 to your computer and use it in GitHub Desktop.
A simple polyfill of DOM ProgressEvent, work in PhantomJS
(function(window) {
// http://engineering.shapesecurity.com/2015/01/detecting-phantomjs-based-visitors.html
if (/PhantomJS/.test(window.navigator.userAgent)) {
var ProgressEvent = function(type, eventInit) {
this.type = type
this.lengthComputable = eventInit.lengthComputable
this.loaded = eventInit.loaded
this.total = eventInit.total
}
ProgressEvent.prototype = Object.create(Event.prototype)
ProgressEvent.prototype.constructor = ProgressEvent
window.ProgressEvent = ProgressEvent
}
})(window)
(function(window) {
// http://engineering.shapesecurity.com/2015/01/detecting-phantomjs-based-visitors.html
if (/PhantomJS/.test(window.navigator.userAgent)) {
interface IProgressEventInit {
lengthComputable: boolean
loaded: number
total: number
}
var ProgressEvent = function(type: string, eventInit:IProgressEventInit): void {
this.type = type
this.lengthComputable = eventInit.lengthComputable
this.loaded = eventInit.loaded
this.total = eventInit.total
}
ProgressEvent.prototype = Object.create(Event.prototype)
ProgressEvent.prototype.constructor = ProgressEvent
window.ProgressEvent = ProgressEvent
}
})(window)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment