Firebase realtime database once method doesn't work in web extensions - firebase-realtime-database

i'm using Firebase API to anonymously login and get data from Tampermonkey extension. Works as charm in Chrome but doesn't work in Firefox at all.
firebase.auth().signInAnonymously().catch(function(error) {
console.log("login error: "+ error);
});
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
firebase.database().ref().once("value").then(function(snapshot) {
debugger; // never gets here
GM_setValue("lastUpdate", new Date());
GM_setValue("lastState", snapshot.val());
}).catch(function(error) {
debugger; // never gets here
console.log("error reading DB: " + error);
});
}
});
it never comes to debugger in Firefox. No errors in console at all. what could be a reason? GM_xmlhttprequest instead works more or less in both, but i need auth as well so wanted to use official API.
thank you
UPDATE: after recent Chrome update it doesn't work there as well. Silently dies somewhere...

it turns that there is a value in localStorage that preventing everything from working. code below at application init solves issue.
if (localStorage) { // fix for API
localStorage.removeItem("firebase:previous_websocket_failure");
}
something sets it to true and nobody is cleaning it. there are issues about it since 2017 on github about this, seems not resolved yet.

Related

ElectronJS autoupdater.setFeedURL() throw exception ["Update check failed. The server sent an invalid response. Try again later."]

I'am working on a desktop app using electron everything is working well, except for the autoUpdater.setFeedURL() method, it returns always this exception : "Update check failed. The server sent an invalid response. Try again later."
if(!isDev)
{
autoUpdater.setFeedURL({
"url":"https://github.com/MyUsername/MyRepos/releases/"
});
autoUpdater.checkForUpdates();
}
enter image description here
Yeah! after 2 days of headache, I found that simply I was using a deprecated version of autoUpdater, I should be using this :
const { autoUpdater } = require('electron-updater');
So what I did next is just remove the setFeedURL line and instead of autoUpdater.checkForUpdates() I used autoUpdater.checkForUpdatesAndNotify()
if(!isDev)
{
autoUpdater.checkForUpdatesAndNotify();
}

Parse-server Cloud Code Error 141 Invalid Function

I am running parse-server on Heroku, I am working on implementing a custom cloud code function, however every implementation returns invalid function code: 141, Version:1.12.0
I have successfully gotten the "hello" function to work, including 1 change I made to it:
Parse.Cloud.define('hello', function(req, res) {
console.log("received.........");
res.success('Hi');
});
The custom function I am trying to get working is a simple query to my database:
Parse.Cloud.define("titleQuery", function(request, response) {
var query = new Parse.Query("StudentNotes");
query.equalTo("title", request.params.title);
query.find({
success: function(results) {
console.log("received........." + results);
response.success(results);
},
error: function() {
console.log("received........." + error);
response.error("title lookup failed");
}
});
});
When I run this on iOS with the following code:
PFCloud.callFunctionInBackground("titleQuery", withParameters: ["title": "testTitle"]) {
(response: AnyObject ? , error : NSError ? ) - > Void in
let hello = response // as? String
print(hello)
}
I am querying my database in class "StudentNotes" for object title with the name "testTitle", I know for a fact that that object exists, however due to it throwing error 141 I do not receive anything. Any help would be greatly appreciated.
EDIT2: I have gotten custom cloud functions to work, however I cannot get any queries to my database to work. Can anyone post a confirmed working query that returns an object? Perhaps from the _User table so that I can copy/paste and ensure that my cloud code can access my database?
My process:
I edit the Main.js file and add in my cloud function.
Then i commit & push (successfully)
finally i restart my Heroku server
Then i still get an error 141 invalid function return
I have successfully solved this problem and gotten regular queries to work. The problem was in my Heroku config vars in the dashboard. My server URL was invalid, never changed from the default of "http://yourappname.com/parse/" I have to manually enter "yourappname".

Service Worker and transparent cache updates

I am trying to install a ServiceWorker for a simple, yet old, Django web app. I started working with the example read-through caching example from the Chrome team
This works well but isn't ideal because I want to update the cache, if needed. There are two recommended ways to do this based on reading all the other service-worker answers here.
Use some server-side logic to know when the stuff you show has updated and then update your service worker to change what is precached. This is what sw-precache does, for example.
Just update the cache version in the service worker JS file (see comments in the JS file on the caching example above) whenever resources you depend on update.
Neither are great solutions for me. First, this is a dumb, legacy app. I don't have the application stack that sw-precache relies on. Second, someone else updates the data that will be shown (it is basically a list of things with a details page).
I wanted to try out the "use cache, but update the cache from network" that Jake Archibald suggested in his offline cookbook but I can't quite get it to work.
My original thinking was I should just be able to return the cached version in my service worker, but queue a function that would update the cache if the network is available. For example, something like this in the fetch event listener
// If there is an entry in cache, return it after queueing an update
console.log(' Found response in cache:', response);
setTimeout(function(request, cache){
fetch(request).then(function(response){
if (response.status < 400 && response.type == 'basic') {
console.log("putting a new response into cache");
cache.put(request, response);
}
})
},10, request.clone(), cache);
return response;
But this doesn't work. The page gets stuck loading.
whats wrong with the code above? Whats the right way to get to my target design?
It sounds like https://jakearchibald.com/2014/offline-cookbook/#stale-while-revalidate is very close to what you're looking for
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.open('mysite-dynamic').then(function(cache) {
return cache.match(event.request).then(function(response) {
var fetchPromise = fetch(event.request).then(function(networkResponse) {
// if we got a response from the cache, update the cache
if (response) {
cache.put(event.request, networkResponse.clone());
}
return networkResponse;
});
// respond from the cache, or the network
return response || fetchPromise;
});
})
);
});
On page reload you can refresh your service worker with new version meanwhile old one will take care of request.
Once everything is done and no page is using old service worker, It will using newer version of service worker.
this.addEventListener('fetch', function(event){
event.responseWith(
caches.match(event.request).then(function(response){
return response || fetch(event.request).then(function(resp){
return caches.open('v1').then(function(cache){
cache.put(event.request, resp.clone());
return resp;
})
}).catch(function() {
return caches.match('/sw/images/myLittleVader.jpg');
});
})
)
});
I recommend you to walk through below link for detailed functionality
https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers

Nodejs Socket.io working on desktop safari & chrome, but not iPhone

I have an issue related to socket.io on its nodejs server. Issue is something related to socket.io is not working on IOS mobile browser in IOS8+. I have searched for it and went through some solutions but nothing worked.
Here are the issue links:
https://github.com/Automattic/socket.io/issues/976
http://www.codedisqus.com/7yzSqUgqge/socketio-working-on-desktop-safari-chrome-but-not-mobile.html
Here is the code
io.sockets.on('connection', function(socket) {
process.emit('client-connection', socket.id);
socket.on('authenticate', function(message) {
console.log('Authenticating client with key "' + message.authToken + '"');
authenticateClient(socket, message);
});
socket.on('message', function(message) {
if (io.sockets.sockets[socket.id] && message.hasOwnProperty('type')) {
if (message.hasOwnProperty('channel')) {
if (settings.clientsCanWriteToChannels || ChannelIsClientWritable(message.channel)) {
process.emit('client-message', socket.id, message);
}
}
return;
}
});
socket.on('disconnect', function () {
console.log("in disconnect");
process.emit('client-disconnect', socket.id);
cleanupSocket(socket);
});
})
Please let me know.
The basic issue is that when I try to open a session on browser it works fine and if I try to do the same on iPhone device browser it fails to work.
As per requirement the issue was IOS socket was not opening over SSL in mobile browsers. I have reinstalled the SSL certificate with complete code packet and it worked for me.
There might be some issue with SSL code packet due to which configuration was not complete.

Auth pop up returning blank page

When I submit an auth call to google to I get the popup from the google window, then when I submit my credentials and press submit it forwards on to something like
https://auth.firebase.com/v2/FIREBASEREF/auth/google/callback?state= etc
And then all I get is a blank (blue background) screen.
$('#loginButton').click(function() {
myFirebaseRef.authWithOAuthPopup("google", function(error, authData) {
if (error) {
console.log("Login Failed!", error);
alert("Login Failed, please try again.")
} else {
console.log("Authenticated successfully with payload:", authData);
myUserID = authData.uid;
}
});
});
The same is also happening when trying to auth with Github, I can press "submit" or "login" etc. and then it just loads a blank page at auth.firebase.com
Any ideas?
Thanks
FWIW if anyone ends up on this issue: I was getting the exact same thing... the oauth popup was blank and not doing anything. I fixed it by removing the async/await from my form handler:
<form onSubmit={this.onSubmit}>
<button type="submit">Sign In with Google</button>
</form>
...
onSubmit = async event => {
await this.auth.signInWithPopup(this.googleProvider)
.then(....
Sometimes this should be an permissions issue related with the domain where you're trying to do the request like localhost or 127.0.0.1.
In that case, Go to Firebase Console -> Authentication -> Sign-In Method then scroll down to Authorized domains and add your current domain from you're trying to sign in e.g. 127.0.0.1.
Note: This is just for dev purposes, in case you want to deploy your app to Prod, you shouldn't have this configuration. For multiples environments you should check here
Another Note: If you're working with Javascript, you might add an event.preventDefault() before to call firebase.authWithOAuthPopup(...) to be able to obtain the result of the promise that return the authWithOAuthPopup function.
My solution was adding inAppBrowser from cordova and it no longer returned blank page.

Resources