如何从页面控制台调用 Chrome 扩展内容脚本中定义的函数?
content.js
function foo(){
console.log('bar');
}
foo();
Manifest
"content_scripts": [{"matches": ["<all_urls>"],"js": ["content.js"]}]
一切正常,并且该函数在页面加载时执行,但是我可以通过控制台调用该函数吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 Ivàn 已经指出的那样,您需要从开发人员工具控制台更改执行上下文。左上角有一个下拉菜单,您可以从那里更改上下文。我附上了屏幕截图以帮助您找到它。
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.