Skip to content

API

Eruda Instance

init

Initialize eruda.

Options

NameTypeDesc
containerelementContainer element. If not set, it will append an element directly under html root element
toolstring arrayChoose which default tools you want, by default all will be added
autoScale=truebooleanAuto scale eruda for different viewport settings
useShadowDom=truebooleanUse shadow dom for css encapsulation
defaultsobjectDefault settings

Available default settings:

NameTypeDesc
transparencynumberTransparency, 0 to 1
displaySizenumberDisplay size, 0 to 100
themestringTheme, defaults to Light or Dark in dark mode
javascript
const el = document.createElement('div');
document.body.appendChild(el);

eruda.init({
    container: el,
    tool: ['console', 'elements'],
    useShadowDom: true,
    autoScale: true,
    defaults: {
        displaySize: 50,
        transparency: 0.9,
        theme: 'Monokai Pro'
    }
});

destroy

Destory eruda.

Note: You can call init method again after destruction.

javascript
eruda.destroy();

scale

Set or get scale.

javascript
eruda.scale(); // -> 1
eruda.scale(1.5);

position

Set or get entry button position.

It will not take effect if given pos is out of range.

javascript
eruda.position({x: 20, y: 20});
eruda.position(); // -> {x: 20, y: 20}

get

Get tool, eg. console, elements panels.

javascript
let console = eruda.get('console');
console.log('eruda');

add

Add tool.

javascript
eruda.add(new (eruda.Tool.extend({
    name: 'test'
})));

eruda.add(eruda.Network);

remove

Remove tool.

javascript
eruda.remove('console');

show

Show eruda panel.

javascript
eruda.show();
eruda.show('console');

hide

Hide eruda panel.

javascript
eruda.hide();

Console

Display console logs. Implementation detail follows the console api spec.

Config

NameTypeDesc
asyncRenderbooleanAsynchronous rendering
jsExecutionbooleanEnable JavaScript execution
catchGlobalErrbooleanCatch global errors
overrideConsolebooleanOverride console
displayExtraInfobooleanDisplay extra information
displayUnenumerablebooleanDisplay unenumerable properties
displayGetterValbooleanAccess getter value
lazyEvaluationbooleanStringify object when clicked
displayIfErrbooleanAuto display if error occurs
maxLogNumstringMax log number
javascript
let console = eruda.get('console');
console.config.set('catchGlobalErr', true);

log, error, info, warn, dir, time/timeLog/timeEnd, clear, count/countReset, assert, table, group/groupCollapsed/groupEnd

All these methods can be used in the same way as window.console object.

Note: When called, a corresponding event is triggered.

javascript
let 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'));
console.on('log', function () 
{
    // Do whatever you want, send to server or save on local storage.
});

filter

Filter logs.

NameTypeDesc
filterstring regexp functionCustom filter
javascript
console.filter('eruda');
console.filter(/^eruda/);
console.filter(function (log)
{
    return log.type === 'error';
});

html

Log out html content.

NameTypeDesc
htmlstringHtml string
javascript
console.html('<span style="color:red">Red</span>');

Elements

Check dom element status.

Config

NameTypeDesc
overrideEventTargetbooleanCatch Event Listeners
observeElementbooleanAuto Refresh

select

Select node to show.

NameTypeDesc
nodeChildNodeNode to be selected
javascript
elements.select(document.body);

Network

Display requests.

clear

Clear requests.

requests

Get request data.

javascript
network.clear();

Resources

LocalStorage, sessionStorage, cookies, scripts, styleSheets and images.

Config

NameTypeDesc
hideErudaSettingbooleanHide Eruda Setting

Sources

View object, html, js, and css.

Config

NameTypeDesc
showLineNumbooleanShow Line Numbers

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.

NameTypeDesc
namestringInfo name
contentstring functionInfo content
javascript
info.add('title', 'content');
info.add('location', () => location.href);

get

Get info or infos.

NameTypeDesc
namestringInfo name
returnstring functionInfo content
javascript
info.add('title', 'content')
info.get(); // -> [{name: 'title', val: 'content'}]
info.get('title') // -> 'content'

remove

Remove specified info.

NameTypeDesc
namestringInfo name
javascript
info.remove('title');

Snippets

Allow you to register small functions that can be triggered multiple times.

clear

Clear snippets.

add

Add snippet.

NameTypeDesc
namestringSnippet name
fnfunctionFunction to be triggered
descstringSnippet description

remove

Remove specified snippet.

NameTypeDesc
namestringSnippet to remove

run

Run specified snippet.

NameTypeDesc
namestringSnippet to run
javascript
snippets.add('hello', function ()
{
    console.log('Hello World!');
}, 'Display hello on console');

snippets.run('hello');
snippets.remove('hello');

Settings

Customization for all tools.

clear

Clear settings.

remove

Remove setting.

NameTypeDesc
cfgobjectConfig object
namestringOption name

text

Add text.

NameTypeDesc
strstringString to display

switch

Add switch to toggle a boolean value.

NameTypeDesc
cfgobjectConfig object
namestringOption name
descstringOption description

select

Add select to select a number of string values.

NameTypeDesc
cfgobjectConfig object
namestringOption name
descstringOption description
valuesarrayArray of strings to select

range

Add range to input a number.

NameTypeDesc
cfgobjectConfig object
namestringOption name
descstringOption description
optionobjectMin, max, step

separator

Add a separator.

javascript
import defaults from 'licia/defaults';

let cfg = eruda.Settings.createCfg('test');

cfg.set(defaults(cfg.get(), {
    testBool: true,
    testSelect: 'select1',
    testRange: 1
}));

settings.text('Test')
        .switch(cfg, 'testBool', 'Test Bool')
        .select(cfg, 'testSelect', 'Test Select', ['select1', 'select2'])
        .range(cfg, 'testRange', 'Test Range', {min: 0, max: 1, step: 0.1})
        .separator();

settings.remove(cfg, 'testBool')