Skip to content

Instantly share code, notes, and snippets.

@mattdesl
Last active December 30, 2015 03:53
Show Gist options
  • Select an option

  • Save mattdesl/5040b80e1f5422de636f to your computer and use it in GitHub Desktop.

Select an option

Save mattdesl/5040b80e1f5422de636f to your computer and use it in GitHub Desktop.

Revisions

  1. mattdesl revised this gist Feb 12, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion launch.md
    Original file line number Diff line number Diff line change
    @@ -21,4 +21,6 @@ Err with setScriptSource 43 Uncaught Script not found

    On Chrome Canary 42.0.2303.0.

    Same problem with Chrome 40.0.2214.111.
    Same problem with Chrome 40.0.2214.111.

    OSX Yosemite 10.10.1
  2. mattdesl revised this gist Feb 12, 2015. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion debugger.js
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,17 @@ Chrome({
    scriptSource: ';document.body.style.background = "rgb(' + r + ',255,255);"',
    }, function(err, msg) {
    if (err)
    console.log("Err with", params.scriptId, msg.message)
    console.log("Err with setScriptSource", params.scriptId, msg.message)
    else
    console.log(msg)
    })

    //getScriptSource always seems to work fine
    chrome.Debugger.getScriptSource({
    scriptId: params.scriptId
    }, function(err, msg) {
    if (err)
    console.log("Err with getScriptSource", params.scriptId, msg.message)
    else
    console.log(msg)
    })
  3. mattdesl revised this gist Feb 12, 2015. 2 changed files with 8 additions and 2 deletions.
    1 change: 1 addition & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    document.body.style.background = 'blue'
    9 changes: 7 additions & 2 deletions launch.md
    Original file line number Diff line number Diff line change
    @@ -15,5 +15,10 @@ and reload page in Chrome (without opening dev tools). Output:
    ```
    Debugger enabled
    got script ID 43
    Err with 43 Uncaught Script not found
    ```
    Err with setScriptSource 43 Uncaught Script not found
    { scriptSource: 'document.body.style.background = \'blue\'' }
    ```

    On Chrome Canary 42.0.2303.0.

    Same problem with Chrome 40.0.2214.111.
  4. mattdesl created this gist Feb 12, 2015.
    35 changes: 35 additions & 0 deletions debugger.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    var Chrome = require('chrome-remote-interface')

    Chrome({
    chooseTab: function(tabs) {
    var idx = 0
    tabs.forEach(function(tab, i) {
    if (tab.url === 'http://localhost:9966/')
    idx = i
    })
    return idx
    }
    }, function(chrome) {
    chrome.on('Debugger.scriptParsed', function(params) {
    if (params.url.indexOf('http://') > -1) {
    //will print ID of index.js e.g. 36
    console.log("got script ID", params.scriptId)

    //now to change index.js to something else
    var r = Math.floor(Math.random() * 255)
    chrome.Debugger.setScriptSource({
    scriptId: params.scriptId,
    scriptSource: ';document.body.style.background = "rgb(' + r + ',255,255);"',
    }, function(err, msg) {
    if (err)
    console.log("Err with", params.scriptId, msg.message)
    else
    console.log(msg)
    })
    }
    });

    chrome.Debugger.enable(function() {
    console.log("Debugger enabled")
    });
    });
    10 changes: 10 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title></title>
    </head>
    <body>
    <script src="index.js"></script>
    </body>
    </html>
    19 changes: 19 additions & 0 deletions launch.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    first serve folder on 9966

    ```http-server -p 9966```

    then open remote debugging chrome:

    ```/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary http://localhost:9966/ --remote-debugging-port=9222```

    then run debugger

    ```node debugger.js```

    and reload page in Chrome (without opening dev tools). Output:

    ```
    Debugger enabled
    got script ID 43
    Err with 43 Uncaught Script not found
    ```