1
0
mirror of synced 2025-12-09 07:08:17 +08:00
This commit is contained in:
surunzi
2016-10-31 12:53:28 +08:00
parent 48b5403364
commit f8bce746bd
3 changed files with 0 additions and 1584 deletions

View File

@@ -1,81 +0,0 @@
# Eruda
[![npm version](https://badge.fury.io/js/eruda.svg)](https://badge.fury.io/js/eruda)
Eruda 是一个专为手机网页前端设计的调试面板,类似 DevTools 的迷你版,其主要功能包括:捕获 console 日志、检查元素状态、显示性能指标、捕获XHR请求、显示本地存储和 Cookie 信息、浏览器特性检测等等。
## 功能清单
![Eruda](http://7xn2zy.com1.z0.glb.clouddn.com/eruda_screenshot3.jpg)
1. 按钮拖拽,面板透明度大小设置。
2. Console面板捕获Console日志支持log、error、info、warn、dir、time/timeEnd、clear、count、assert、table支持占位符包括%c自定义样式输出支持按日志类型及正则表达式过滤支持快捷命令加载underscore、jQuery库支持JavaScript脚本执行。
3. Elements面板查看标签内容及属性查看应用在Dom上的样式支持页面元素高亮支持屏幕直接点击选取查看Dom上绑定的各类事件。
4. Network面板图表显示页面加载速度查看页面各资源请求时间Android捕获XHR请求查看发送数据、返回头、返回内容等信息。
5. Resources面板查看并清除localStorage、sessionStorage及cookie查看页面加载脚本及样式文件查看页面加载图片。
6. Sources面板查看页面源码格式化htmlcssjs代码及json数据。
7. Info面板输出URL及User Agent支持自定义输出内容。
8. Snippets面板页面元素添加边框加时间戳刷新页面支持自定义代码片段。
9. Features面板浏览器常用特性检测提供Can I useHtml5Test快捷访问。
## 快速上手
通过npm安装
```bash
npm install eruda --save
```
在页面中加载脚本:
```html
<script src="node_modules/eruda/eruda.min.js"></script>
<script>eruda.init();</script>
```
Js文件对于移动端来说略重gzip后大概80kb。建议通过url参数来控制是否加载调试器比如
```javascript
;(function () {
var src = 'node_modules/eruda/eruda.min.js';
if (!/eruda=true/.test(window.location) && localStorage.getItem('active-eruda') != 'true') return;
document.write('<scr' + 'ipt src="' + src + '"></scr' + 'ipt>');
document.write('<scr' + 'ipt>eruda.init();</scr' + 'ipt>');
})();
```
初始化时可以传入配置:
* container: 用于插件初始化的Dom元素如果不设置默认创建div作为容器直接置于html根结点下面。
* tool指定要初始化哪些面板默认加载所有。
```javascript
var el = document.createElement('div');
document.body.appendChild(el);
eruda.init({
container: el,
tool: ['console', 'elements']
});
```
> 该工具支持自行编写插件,可参考[eruda-fps](https://github.com/liriliri/eruda-fps)。
## Demo
![Demo](http://7xn2zy.com1.z0.glb.clouddn.com/eruda_qrcode2.png)
请扫描二维码或在手机上直接访问:[http://liriliri.github.io/eruda/](http://liriliri.github.io/eruda/)
如果想在其它页面尝试,请在浏览器地址栏上输入以下代码。
```javascript
javascript:(function () { var script = document.createElement('script'); script.src="//liriliri.github.io/eruda/eruda.min.js"; document.body.appendChild(script); script.onload = function () { eruda.init() } })();
```

View File

@@ -1,156 +0,0 @@
# Tool Api
Each default tool provided by eruda can be accessed by `eruda.get('Tool Name')`.
## Console
Display console logs. Implementation detail follows the [console api spec](https://github.com/DeveloperToolsWG/console-object/blob/master/api.md).
### Config
|Name |Type |Desc |
|-------------------|-------|-------------------------------|
|catchGlobalErr |boolean|Catch global errors |
|overrideConsole |boolean|Override console |
|displayExtraInfo |boolean|Display extra information |
|displayUnenumerable|boolean|Display unenumerable properties|
|displayGetterVal |boolean|Access getter value |
|viewLogInSources |boolean|View log in sources panel |
|displayIfErr |boolean|Auto display if error occurs |
|maxLogNum |string |Max log number |
```javascript
var console = eruda.get('console');
console.config.set('catchGlobalErr', true);
```
### log, error, info, warn, dir, time/timeEnd, clear, count, assert, table
All these methods can be used in the same way as window.console object.
```javascript
var console = eruda.get('console');
console.log('eruda is a console for %s.', 'mobile browsers');
console.table([{test: 1}, {test: 2}, {test2: 3}], 'test');
console.error(new Error('eruda'));
```
### filter
Filter logs.
|Name |Type |Desc |
|------|----------------------|-------------|
|filter|string regexp function|Custom filter|
```javascript
console.filter('all'); // String parameter. Log, warn, debug, error is also supported.
console.filter(/^eruda/);
console.filter(function (log)
{
return log.type === 'error';
});
```
### html
Log out html content.
|Name|Type |Desc |
|----|------|-----------|
|html|string|Html string|
```javascript
console.html('<span style="color:red">Red</span>');
```
## Elements
## Network
## Resources
## Sources
## Info
Display special information, could be used for displaying user info to track
user logs.
By default, page url and browser user agent is shown.
### clear
Clear infos.
### add
Add info.
|Name |Type |Desc |
|-------|------|------------|
|name |string|Info name |
|content|string|Info content|
```javascript
info.add('title', 'content');
```
### remove
Remove specified info.
|Name|Type |Desc |
|----|------|---------|
|name|string|Info name|
```javascript
info.remove('title');
```
## Snippets
Allow you to register small functions that can be triggered multiple times.
### clear
Clear Snippets.
### add
Add Snippet.
|Name|Type |Desc |
|----|--------|------------------------|
|name|string |Snippet name |
|fn |function|Function to be triggered|
|desc|string |Snippet description |
```javascript
snippets.add('hello', function ()
{
console.log('Hello World!');
}, 'Display hello on console');
```
### remove
Remove specified snippet.
|Name|Type |Desc |
|----|------|-----------------|
|name|string|Snippet to remove|
```javascript
snippets.remove('hello');
```
## Features
Browser feature detections, thanks to
[modernizr](https://github.com/Modernizr/Modernizr) project.
Red means unsupported, otherwise ok. All buttons is linked directly to
related materials in [Can I Use](http://caniuse.com/) website.
## Settings

File diff suppressed because it is too large Load Diff