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 
});