【问题标题】:Go to source code line in Chrome dev tools extension?转到 Chrome 开发工具扩展中的源代码行?
【发布时间】:2016-06-28 09:11:39
【问题描述】:
我想创建一个dev tools Chrome extension,让用户可以转到页面源代码中的特定点(每当页面的源代码调用某个全局函数foo,我通过扩展内容脚本注入到页面中时)。
我可以通过让函数foo 抛出异常然后捕获它来获取堆栈跟踪。
但是我怎样才能告诉 Chrome 开发工具导航到源代码中的某一行呢?有 API 调用吗?
【问题讨论】:
标签:
javascript
google-chrome-extension
google-chrome-devtools
【解决方案1】:
为此提供了一个 API 函数,chrome.devtools.panels.openResource。
请注意,此 API 的行号从零开始。
// Opens line 34 of file https://example.com/test.js, assuming this resource is present:
chrome.devtools.panels.openResource("https://example.com/test.js", 33, function() {
// Resource should be open, but no way to test that it succeeded
});