How to call function defined in a Chrome Extension content script from the page's console?

Viewed 73

content.js

function foo(){
  console.log('bar');
}
foo();

Manifest

"content_scripts": [{"matches": ["<all_urls>"],"js": ["content.js"]}]

Everything works fine and the function executes when the page is loaded but is it possible to call this function through the console by myself?

1 Answers

As Ivàn already pointed out, you need to change the context of execution from the Developers Tools' console. In the top left corner there is a dropdown menu, from there you can change the context. I attached a screenshot to help you find it.

enter image description here

Related