问题
Sometimes when I'm trying to debug an issue a user is having with my Chrome extension (StayFocusd), it would be useful to have access to the console logs. Right now I just ask them to copy-and-paste the log to me, but it would be nicer if I could programatically generate a file they could just email to me. Is that possible?
Alternately, is at least possible to capture the console contents with Javascript so I could output it to a useful debugging format for myself?
回答1:
There is an experimental API for that: chrome.experimental.devtools.console:
chrome.experimental.devtools.console.getMessages(function(messages) {
messages[0].url // http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
messages[0].text // XHR finished loading
messages[0].line // 4
})
来源:https://stackoverflow.com/questions/10311273/dump-chrome-dev-console-to-text-file