Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i debug a programmatically injected JS file in google chrome?

i'm injecting a js file to every page in google chrome via

chrome.browserAction.onClicked.addListener(function(tab) {  
  chrome.tabs.executeScript(null,{file:"js/content.js"},function(resultArr){
    console.log(resultArr);
  });  
});

content.js

console.log("hello stackoverflow");

I can see hello stackoverflow printed in the console of the webpage. But i'm not able to find the source file, so i can debug it. Any idea how?

like image 393
shahalpk Avatar asked Nov 19 '13 08:11

shahalpk


People also ask

How do I debug JavaScript Errors in Chrome?

In Chrome, navigate to Tools > Advanced > Error Console. The error console will open. Select JavaScript and Errors from the two drop downs. To find the error location, expand one of the errors.


1 Answers

Use the debugger keyword. This is like inserting a breakpoint into your JS code

so in content.js

debugger;
console.log("hello stackoverflow");
like image 132
jasonscript Avatar answered Sep 28 '22 16:09

jasonscript