Using the Chrome Console with Firebase

As a js newbie this is probably a dumb question. But how can I use js in Chrome console. I am trying to interact with my Firebase through the console, but when I try to get the Firebase link I keep getting undefined

. I know I can use Vulcan to render my data in the console, but how can I actually run the basic javascript?

For example, I just want to get a link to my Firebase and read the data, like this:

var ref = new Firebase("https://docs-examples.firebaseio.com/web/saving-data/fireblog/posts");
// Attach an asynchronous callback to read the data at our posts reference
ref.on("value", function(snapshot) {
    console.log(snapshot.val());
}, function (errorObject) {
    console.log("The read failed: " + errorObject.code);
});

      

How can I enter these commands in the console?

+3


source to share


1 answer


Your code will work if you run it in Chrome Developer Tools when you are in the Firebase Dashboard. The object is Firebase

already available there.

In other tabs, accessibility depends on how the page includes Firebase. If it includes it globally, you can execute your code. If the page doesn't expand Firebase

, I usually embed it into the page using a bookmarklet:

javascript:var script = document.createElement('script'); script.src='https://cdn.firebase.com/js/client/2.2.7/firebase.js'; document.head.appendChild(script);

      

So you add a bookmark to your bookmark bar (mine is called FB

) and set the url, which should be the above JavaScript snippet. Then when you click on the FB link, it will inject the Firebase script into the current page.



After that, I usually start with a script that I have bound to keyboard shortcuts:

new Firebase('https://mine.firebaseio.com/').once('value', function(s) { console.log(JSON.stringify(s.val())); }, console.error)

      

Then I just replace mine

with the actual name of Firebase and I'm in a good place to start.

+4


source







All Articles