Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function wait_for_devtools
function wait_for_devtools( callback, giveup_after ) {
giveup_after = giveup_after || 10
var start = Date.now()
var timeout
var triggered = false
var element = new Image();
element.__defineGetter__('id', done)
function done() {
if (triggered) return ''
console.log('devtools attached')
triggered = true
setTimeout(callback, 1) // its actually still not ready, need to do setTimeout
return ''
}
function checkit() {
if (triggered) { return }
console.log('waiting for devtools...',element)
if (Date.now() - start > giveup_after * 1000) {
console.log('giving up, just going')
callback()
} else {
timeout = setTimeout( checkit, 200 )
}
}
checkit()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.