最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - accessing chrome extension functions in console? - Stack Overflow

programmeradmin1浏览0评论

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

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

Share Improve this question edited Nov 5, 2019 at 12:52 ruohola 24.2k7 gold badges72 silver badges113 bronze badges asked Nov 5, 2019 at 12:37 dropWizarddropWizard 3,55812 gold badges69 silver badges92 bronze badges 2
  • Switch the context in devtools console toolbar to your extension. – woxxom Commented Nov 5, 2019 at 12:41
  • thanks! if you can put this as an answer I'll mark it correct – dropWizard Commented Nov 5, 2019 at 12:46
Add a ment  | 

2 Answers 2

Reset to default 7

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:

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).

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

发布评论

评论列表(0)

  1. 暂无评论