iOS 6 调试控制台不见了?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12587063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS 6 debug console gone?
提问by Matt
I used to use the "Debug Console" for mobile Safari to print out console.log messages when I'm troubleshooting. With iOS 6, in Safari's advanced settings, the "Web Inspector" replaced the "Debug Console." Unfortunately, my company doesn't allow me to plug the phones we're testing with into the computers we're developing on.
我曾经使用移动 Safari 的“调试控制台”在我进行故障排除时打印出 console.log 消息。在 iOS 6 中,在 Safari 的高级设置中,“Web Inspector”取代了“Debug Console”。不幸的是,我的公司不允许我将正在测试的手机插入我们正在开发的计算机上。
Does anyone know how to enable messages printed by using console.log() to be show on iPhones with iOS 6?
有谁知道如何启用使用 console.log() 打印的消息在 iOS 6 的 iPhone 上显示?
回答by reekogi
I have found it helpful to output any JS errors with an alert on window.onerror->
我发现在window.onerror上输出任何带有警报的 JS 错误很有帮助->
window.onerror = function(error) {
alert(error);
};
I paste that into the top of scripts so that any runtime errors will be output in a native alert. Works on desktop too.
我将其粘贴到脚本的顶部,以便任何运行时错误都将在本机警报中输出。也适用于桌面。
回答by user139078
They removed it. You will now be required to debug through Safari.
他们删除了它。您现在需要通过 Safari 进行调试。
http://www.mobilexweb.com/blog/iphone-5-ios-6-html5-developers
http://www.mobilexweb.com/blog/iphone-5-ios-6-html5-developers
It's actually pretty easy to setup.
1) Make sure your Web Inspector setting is turned on under iPhone Settings => Safari => Advanced.
2) Plug in your phone to a Mac OSX computer.
3) Open Safar 6 and make sure Develop mode is on Safari Preferences => Advanced => Show Develop Menu
它实际上很容易设置。
1) 确保您的 Web Inspector 设置在 iPhone 设置 => Safari => 高级下打开。
2) 将手机插入 Mac OSX 计算机。
3) 打开 Safar 6 并确保开发模式在 Safari Preferences => Advanced => Show Develop Menu
回答by bernard
If you don't have Mac OSX you can use this script as console replacement:
如果您没有 Mac OSX,您可以使用此脚本作为控制台替换:
https://github.com/robotnic/waterbug
https://github.com/robotnic/waterbug
It shows error message, it's possible to log all kind of variables, you have to turn your iPhone or iPad 90° to the right to open the console.
它显示错误消息,可以记录所有类型的变量,您必须将 iPhone 或 iPad 向右旋转 90° 才能打开控制台。
回答by Mattio
Another possible option is Steve Souders' mobile performance bookmarklet. It includes Firebug Lite, which has a console and a good bit more. It doesn't work quite the same as the previous Mobile Safari console and you must have a connection to use it.
另一种可能的选择是 Steve Souders 的移动性能书签。它包括Firebug的精简版,其中有一个控制台和更加好一点。它的工作方式与之前的 Mobile Safari 控制台不太一样,您必须有连接才能使用它。
回答by Joey
Just create your own console at the bottom of the screen. This is a quick solution but its better than making alerts all over the place. Make sure to put this in the root html file (bottom) or convert to all JS and put in the root JS file (top).
只需在屏幕底部创建您自己的控制台。这是一个快速解决方案,但它不是使警报所有的地方更好。确保将其放入根 html 文件(底部)或转换为所有 JS 并放入根 JS 文件(顶部)。
<div id="console"></div>
<style media="screen">
#console {
resize: both;
height :200px;
overflow: scroll;
background: white;
color: black;
border: 1px solid black;
width: 95vw;
padding: 5px;
margin: auto;
}
</style>
<script type="text/javascript">
logger = (...params) => {
const newLog = document.createElement("div");
newLog.textContent = params.reduce((str, param) => {
if (typeof param === 'string') return `${str} ${param}`;
return `${str} ${JSON.stringify(param)}`;
}, '');
document.getElementById('console').appendChild(newLog);
}
window.onerror = (error) => {
const newLog = document.createElement("div");
newLog.style.color = 'red';
newLog.textContent = error;
document.getElementById('console').appendChild(newLog);
};
console.log = logger;
console.warn = logger;
</script>