2

我想制作一个dev tools Chrome extension,让用户转到页面源代码中的特定点(每当页面的源代码调用某个全局函数foo时,我通过扩展内容脚本将其注入到页面中)。转到Chrome开发工具扩展的源代码行?

我可以通过函数foo抛出一个异常然后捕获它来获取堆栈跟踪。

但是,我怎么能告诉Chrome开发工具去导航到源代码中的某一行?有没有API调用?

回答

3

这里有一个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 
});