As a js newbie, this is probably a dumb question. But how can I actually use js within a Chrome console. I am trying to interact with my Firebase via the console but when I try to get the Firebase reference I keep getting undefined
. I know I can use Vulcan to visualize my data within the console but how can I actually execute basic javascript?
For example, I just want to get a reference to my Firebase and read data, like this:
var ref = new Firebase("");
// 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 type these mands in the console?
As a js newbie, this is probably a dumb question. But how can I actually use js within a Chrome console. I am trying to interact with my Firebase via the console but when I try to get the Firebase reference I keep getting undefined
. I know I can use Vulcan to visualize my data within the console but how can I actually execute basic javascript?
For example, I just want to get a reference to my Firebase and read data, like this:
var ref = new Firebase("https://docs-examples.firebaseio./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 type these mands in the console?
Share Improve this question asked Jun 16, 2015 at 21:27 stephsteph 7012 gold badges10 silver badges30 bronze badges1 Answer
Reset to default 7Your code will already work if you run it in the Chrome developer tools when you're in the Firebase Dashboard. The Firebase
object is already available there.
In other tabs, the availability depends on how the page includes Firebase. If it includes it globally, you can execute your code. If the page does not expose Firebase
, I normally inject it into the page with a bookmarklet:
javascript:var script = document.createElement('script'); script.src='https://cdn.firebase./js/client/2.2.7/firebase.js'; document.head.appendChild(script);
So you add a bookmark to your Bookmarks Bar (mine is called FB
) and set the URL to be the above JavaScript snippet. Then when you click the FB link, it will inject the Firebase script into the current page.
After that I normally start with a script that I've tied to a keyboard shortcuts:
new Firebase('https://mine.firebaseio./').once('value', function(s) { console.log(JSON.stringify(s.val())); }, console.error)
Then I just replace mine
with the actual name of the Firebase and I'm in a good place to get started.