Skip to content

Instantly share code, notes, and snippets.

@kzahel
Last active May 5, 2016 01:11
Show Gist options
  • Select an option

  • Save kzahel/6eb6ebaa7a495e7329bc0392305a2db3 to your computer and use it in GitHub Desktop.

Select an option

Save kzahel/6eb6ebaa7a495e7329bc0392305a2db3 to your computer and use it in GitHub Desktop.

Revisions

  1. kzahel revised this gist May 5, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ function wait_for_devtools( callback, giveup_after ) {
    function checkit() {
    if (triggered) { return }
    console.log('waiting for devtools...',element)
    if (Date.now() - start > giveup * 1000) {
    if (Date.now() - start > giveup_after * 1000) {
    console.log('giving up, just going')
    callback()
    } else {
  2. kzahel created this gist May 5, 2016.
    28 changes: 28 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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 * 1000) {
    console.log('giving up, just going')
    callback()
    } else {
    timeout = setTimeout( checkit, 200 )
    }
    }
    checkit()
    }