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: 'function foo(){ document.body.style.background = "hsl(' + r + ',50%,50%)"; }\n\nfoo(); setInterval(foo, 1000);' }, function(err, msg) { if (err) console.log("Err with setScriptSource", params.scriptId, msg.message) else console.log("setScriptSource win:", 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("getScriptSource", msg) }) }) } }); chrome.Debugger.enable(function() { console.log("Debugger enabled") }); });