Eruda

Eruda 是一个专为手机网页前端设计的调试面板,类似 DevTools 的迷你版,其主要功能包括:捕获 console 日志、检查元素状态、捕获XHR请求、显示本地存储和 Cookie 信息等等。「Eruda is a debugging panel designed for mobile web front-end , similar to the mini-version of DevTools , its main features include : capture console logs , check the state of the element , capture XHR requests , display local storage and cookie information and so on.」

Github stars Tracking Chart

Eruda

Eruda 是一个专为手机网页前端设计的调试面板,类似 DevTools 的迷你版,其主要功能包括:捕获 console 日志、检查元素状态、捕获XHR请求、显示本地存储和 Cookie 信息等等。

Demo

Demo

请扫描二维码或在手机上直接访问:https://eruda.liriliri.io/

如果想在其它页面尝试,请在浏览器地址栏上输入以下代码。

javascript:(function () { var script = document.createElement('script'); script.src="//cdn.jsdelivr.net/npm/eruda"; document.body.appendChild(script); script.onload = function () { eruda.init() } })();

功能清单

Eruda

  1. 按钮拖拽,面板透明度大小设置。

  2. Console 面板:捕获 Console 日志,支持 log、error、info、warn、dir、time/timeEnd、clear、count、assert、table;支持占位符,包括 %c 自定义样式输出;支持按日志类型及正则表达式过滤;支持 JavaScript 脚本执行。

  3. Elements 面板:查看标签内容及属性;查看应用在 Dom 上的样式;支持页面元素高亮;支持屏幕直接点击选取;查看 Dom 上绑定的各类事件。

  4. Network 面板:捕获请求,查看发送数据、返回头、返回内容等信息。

  5. Resources 面板:查看并清除 localStorage、sessionStorage 及 cookie;查看页面加载脚本及样式文件;查看页面加载图片。

  6. Sources 面板:查看页面源码;格式化 html,css,js 代码及 json 数据。

  7. Info 面板:输出 URL 及 User Agent;支持自定义输出内容。

  8. Snippets 面板:页面元素添加边框;加时间戳刷新页面;支持自定义代码片段。

快速上手

通过CDN使用:

<script src="//cdn.bootcdn.net/ajax/libs/eruda/2.3.3/eruda.js"></script>
<script>eruda.init();</script>

通过 npm 安装:

npm install eruda --save

在页面中加载脚本:

<script src="node_modules/eruda/eruda.js"></script>
<script>eruda.init();</script>

JS 文件对于移动端来说略重(gzip 后大概 100kb)。建议通过 url 参数来控制是否加载调试器,比如:

;(function () {
    var src = '//cdn.jsdelivr.net/npm/eruda';
    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:指定要初始化哪些面板,默认加载所有。
let el = document.createElement('div');
document.body.appendChild(el);

eruda.init({
    container: el,
    tool: ['console', 'elements'],
    useShadowDom: true
});

插件

如果你想要自己编写插件,可以查看这里的教程

相关项目

原文:https://github.com/liriliri/eruda/blob/master/doc/README_CN.md

Overview

Name With Ownerliriliri/eruda
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 4)
PlatformWeb browsers
License:MIT License
Release Count77
Last Release Namev3.0.1 (Posted on )
First Release Namev1.0.0 (Posted on )
Created At2016-03-06 13:45:55
Pushed At2024-04-20 15:02:32
Last Commit At2023-11-05 16:38:12
Stargazers Count17.3k
Watchers Count334
Fork Count1.1k
Commits Count0.9k
Has Issues Enabled
Issues Count315
Issue Open Count60
Pull Requests Count21
Pull Requests Open Count3
Pull Requests Close Count25
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

Console for Mobile Browsers.

NPM version
Build status
Test coverage
Downloads
License

中文

Demo

Demo

Browse it on your phone: https://eruda.liriliri.io/

In order to try it for different sites, execute the script below on browser address bar.

javascript:(function () { var script = document.createElement('script'); script.src="https://cdn.jsdelivr.net/npm/eruda"; document.body.append(script); script.onload = function () { eruda.init(); } })();

Features

  • Console: Display JavaScript logs.
  • Elements: Check dom state.
  • Network: Show requests status.
  • Resources: Show localStorage, cookie information.
  • Info: Show url, user agent info.
  • Snippets: Include snippets used most often.
  • Sources: Html, js, css source viewer.

Install

You can get it on npm.

npm install eruda --save

Add this script to your page.

<script src="node_modules/eruda/eruda.js"></script>
<script>eruda.init();</script>

It's also available on jsDelivr and cdnjs.

<script src="//cdn.jsdelivr.net/npm/eruda"></script>
<script>eruda.init();</script>

The JavaScript file size is quite huge(about 100kb gzipped) and therefore not suitable to include in mobile pages. It's recommended to make sure eruda is loaded only when eruda is set to true on url(http://example.com/?eruda=true), for example:

;(function () {
    var src = '//cdn.jsdelivr.net/npm/eruda';
    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>');
})();

Configuration

When initialization, a configuration object can be passed in.

  • container: Container element. If not set, it will append an element directly
    under html root element.
  • tool: Choose which default tools you want, by default all will be added.

For more information, please check the documentation.

let el = document.createElement('div');
document.body.appendChild(el);

eruda.init({
    container: el,
    tool: ['console', 'elements']
});

Plugins

If you want to create a plugin yourself, follow the guides here.

  • eruda-android: Simple webview with eruda loaded automatically.
  • chii: Remote debugging tool.
  • chobitsu: Chrome devtools protocol JavaScript implementation.
  • licia: Utility library used by eruda.
  • luna: UI components used by eruda.

Third Party

Backers

Contribution

Read Contributing Guide for development setup instructions.

To the top