admin管理员组文章数量:1289845
I do web development with an Android (not rooted) phone and look for a method to show the browser (Chrome or Firefox) console messages. Neither Android Chrome nor Firefox has web inspector/console and I don't found Firefox (working) add-on.
Update: I can't connect my phone to a puter (ADB, Chrome remote tool... are unavailable).
Anybody can hint me a viable solution?
I do web development with an Android (not rooted) phone and look for a method to show the browser (Chrome or Firefox) console messages. Neither Android Chrome nor Firefox has web inspector/console and I don't found Firefox (working) add-on.
Update: I can't connect my phone to a puter (ADB, Chrome remote tool... are unavailable).
Anybody can hint me a viable solution?
Share Improve this question edited Aug 6, 2018 at 7:32 Ek1noX asked Aug 5, 2018 at 17:22 Ek1noXEk1noX 4936 silver badges13 bronze badges 3- I have done some mobile development, and I used chrome Dev tools, I just had to plug in my phone to my laptop and use chrome dev tools on my laptop. It should display all errors and console logs and such. You can also edit the HTML and stuff on your puter and see it change on your phone. developers.google./web/tools/chrome-devtools Let me know if that helps – Kieran McWilliams Commented Aug 5, 2018 at 17:27
- Did you checked this answer - stackoverflow./a/10816652/1380032 – Rahul Commented Aug 5, 2018 at 17:41
- Thanks and sorry, I forgot to say I can't connect to a puter... Mobile dev only (question updated)! – Ek1noX Commented Aug 6, 2018 at 7:29
2 Answers
Reset to default 8Try https://github./liriliri/eruda, very good approximation of Dev Tools.
All you need to do is add this snippet on top of the page:
<script src="//cdn.jsdelivr/npm/eruda"></script>
<script>eruda.init();</script>
Edit
A practical solution can be found at https://stackoverflow./a/60106504/1025638
Original (self) answer
I don't found a "just work" solution to solve my problem so I made a short tool to send the logs and errors from the browser to a backend server.
It uses a Proxy around window.console object and implements the function window.onerror to post the messages to the server.
I structured the code to use it as an expressjs middleware for reusability. It isn't perfect and it may not be patible with all browsers, but it really helps if there isn't dev tools in a browser.
Anyone can test it through repl.it.
// Use this module as middleware with expressjs patible server:
//
// In the server:
// consoleWrapperMiddleware(basePath, app)
// basePath: URL path to send browser messages
// app: expressjs application reference
// return: nothing
//
// In the html page:
// <script src="basePath" />
// basePath: URL path to send browser messages
function consoleWrapper(oldConsole, oldOnerror, serverUrl) {
function _post(log) {
const req = new XMLHttpRequest()
req.open('POST', serverUrl, true)
req.setRequestHeader('Content-Type', 'application/json')
req.send(JSON.stringify(log))
}
const console = new Proxy(oldConsole, {
get: (target, propKey, receiver) => {
const origMethod = target[propKey]
return function (...args) {
if (origMethod === undefined) {
const message = 'unknown console method: '+propKey
_post({ level: 'wrap', message: [message]})
return message
}
else {
let result = origMethod.apply(this, args)
_post({ level: origMethod.name, message: args })
return result
}
}
}
})
const onerror = function(msg, url, line, col) {
if (typeof oldOnerror === 'function')
oldOnerror(arguments)
const content = [ msg, url+':'+line+':'+col ]
_post({ level: 'js-err', message: content })
}
return [ console, onerror ]
}
function consoleWrapperMiddleware(basePath, app) {
app.get(basePath, (req, res) => {
res.status(200).send('[ window.console, window.onerror ] = '+consoleWrapper.toString()+'(window.console, window.onerror, location.protocol.concat("//").concat(location.host).concat("'+basePath+'"))')
console.log('Console wrapper sent')
})
app.post(basePath, (req, res) => {
let body = []
req.on('data', (chunk) => {
body.push(chunk)
}).on('end', () => {
body = Buffer.concat(body).toString()
const logMsg = JSON.parse(body)
console.log('['+logMsg.level+']', ...logMsg.message)
res.writeHead(200)
res.end()
})
})
console.log('Log server listening from',basePath)
}
module.exports = consoleWrapperMiddleware
本文标签: javascriptShow console messages on Android browserStack Overflow
版权声明:本文标题:javascript - Show console messages on Android browser - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741407896a2377055.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论