4

If I create a bunch of functions in a chrome extension, is there anyway to access them through the console?

for example:

contentScript.js

function test() {
    console.log('hello')
}

then be able to run test() in the console

ruohola
  • 21,987
  • 6
  • 62
  • 97
Morgan Allen
  • 3,291
  • 8
  • 62
  • 86
  • Switch the [context](https://developers.google.com/web/tools/chrome-devtools/console/reference#context) in devtools console toolbar to your extension. – wOxxOm Nov 05 '19 at 12:41
  • thanks! if you can put this as an answer I'll mark it correct – Morgan Allen Nov 05 '19 at 12:46

2 Answers2

4

The content scripts run in an "isolated world" which is a different context. By default devtools works in the page context so you need to switch the context selector in devtools console toolbar to your extension:

enter image description here

An alternative solution is to expose the functions in the page context by putting them into a <script> element in the web page, but that won't be your content script anymore, it'd be just a normal page script function (more info).

wOxxOm
  • 65,848
  • 11
  • 132
  • 136
-1

You can access your extension's console by right click on the extension popup and then selecting "Inspect".

Mykhaylo K
  • 24
  • 2