LoginSignup
15
14

More than 5 years have passed since last update.

スマホのwebページでコンソール出力できるerudaがいい感じ

Last updated at Posted at 2016-03-17

スマホの検証とかで、実機でしか起きないjsのバグとかあって、実機だからコンソール見れないイライラみたいなのに対応できそうなjsライブラリがあったのでご紹介です。

概要

URLの末尾にクエリストリングでeruda=trueってやると、こんな感じでデバッグ的な画面を表示してくれます。
スクショはPCのChromeですが、、、

スクリーンショット 2016-03-17 9.51.15.png

公式github

使い方

npmでインストールします。

$ npm install eruda --save

そしたら取り込んで、初期化処理を書きます。

index.js
(function() {
  var src = 'node_modules/eruda/dist/eruda.min.js';
  if (!/eruda=true/.test(window.location) && localStorage.getItem('aactive-eruda') != 'true') return;
  document.write('<src' + 'ipt src="' + src + '"></src' + 'ipt>');
})();

あとは、コンソールを確認したいページのURLにeruda=trueをつけるだけ!

https://hoge.com/index?eruda=true

試してみる

こんな感じのお試しを用意

index.html
<html>
  <head>
    <meta http-equiv="Content-Type" charset="UTF-8">

  </head>
  <body>

    <h1 style="line-height: 1.45; font-size: 4em;">テストです</h1>

    <script src="./index.js"></script>
  </body>
</html>
index.js
'use strict';

(function() {
  var src = 'node_modules/eruda/dist/eruda.min.js';
  if (!/eruda=true/.test(window.location) && localStorage.getItem('aactive-eruda') != 'true') return;
  document.write('<src' + 'ipt src="' + src + '"></src' + 'ipt>');
})();

console.log("試しにログ出力してみるよ");

これで実行すると、こんな感じになります

スクリーンショット 2016-03-17 9.56.30.png

右下の方の謎のポチをタップすると、コンソールに切り替わります。

スクリーンショット 2016-03-17 9.57.20.png

これは簡単だし役立ちそう!!

本番環境で表示されないように制御する必要はありますが、、、

15
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
14