I have a chrome app that I am going to be updating and the update will break previous saves. Now I would like to alert the users of the app upon successful completion of the update. I do have an chrome api that I am trying to use which is:
chrome.runtime.onInstalled.addListener(function(){
});
Now I have read the chrome.runtime developer docs and it says that I can use:
chrome.runtime.onInstalled.addListener(function callback)
With a callback function of:
function(object details) {...};
The problem is that I can not figure out what exactly to do with the info as I have tried a couple of different set ups with this code but none work. any help with this issue would be appreciated
Please note that I am trying to display a window that would contain this message. Also my current code is in the background.js of my app although as said the code does not work.
Documentation mentions one property of details:
reason
enum of "install", "update", "chrome_update", or "shared_module_update"
The reason that this event is being dispatched.
So your code needs to check that:
chrome.runtime.onInstalled.addListener(function(details){
if(details.reason == "update") {
// Inform the user of the sad news
}
});
Related
I want to display the UserId on the website, so users can communicate it to us whenever they encounter a problem. However, in code, appInsights.context is undefined. How can I access this?
window.appInsights = appInsights;
appInsights.trackPageView();
console.log(appInsights.context);
is logged as undefined. However, I can access it in the developer console when I run the application. It seems like the context is being removed/not added yet.
I believe this is because the appInsights context is not necessarily created right away?
you may need to do this work "asynchronously" by adding events to the ai queue:
appInsights.queue.push(function () {
console.log(appInsights.context);
});
I had to include some js from a large company that's doing business with my employer. Apparently that js includes push notifications.
The page I'm making now asks "would you like to receive notifications?". How can I, in Chrome, find the line of code that's causing the prompt?
I've opened up devtools and searched for "notification" "subscribe" "pushmanager" etc in the "search all files" function & don't see it in there. I just want to know what they're making us include.
You should look for push notification subscription code. It should look like this:
serviceWorkerRegistration.pushManager.subscribe()
Search for one of these terms and you should find the piece of code you are looking for.
Assuming the other answer is correct (I honestly don't know)..
var swr = serviceWorkerRegistration.pushManager.subscribe;
serviceWorkerRegistration.pushManager.subscribe = function(){
swr();
console.log((new Error()).stack);
};
This should print the stack trace in the console whenever that function is called, allowing you to find the origin script and line numbers and stuff..
I'm trying to get a Meteor user's Facebook ID (who is signed in through Facebook). The following line is giving me trouble:
var userID = Meteor.user().services.facebook.id;
In the console it says
TypeError: Meteor.user(...).services is undefined
From my understanding this is because the user().services hasn't been initialized yet. I wrapped the code in if(Meteor.user()) to confirm the user has been initialized. The code is executed when a button is pressed, so it definitely has enough time to start. This started happening when I removed autopublish (although that could be unrelated). Is there anything additional I need to do to make it work without autopublish?
Solved it with the following:
Meteor.publish("getUserData", function () {
return Meteor.users.find({_id: this.userId});
});
and subscribing to that. Once that subscription is filled all of the Meteor.user.services data is available.
The services key is not included by default in the user's document on the client because it contains security details. You could fetch it via a method call or publish it specifically from the server and subscribe to it.
I'm currently developing a little Website with Firebase. I got a couple of HTML files and each file contains a logout button which calls the function
function logout(){
auth.logout();
console.log("logout successfull");
location.href="index.html";
}
After getting redirected I tried to login again but it always failed with the following error message:
Error: FirebaseSimpleLogin: An unknown server error occurred.
It took me some time to realise that the redirection to the index page caused the problem. When I delte the location.href="index.html"; line, everything works fine.
Problem is, I really need something that redirects me to the front page, when the user isn´t loged in. Is this a known problem and/or can someone come up with a solution to this problem?
Thanks in advance :)
PS.: I realised that I could "fix" the problem (after getting redirected to the index page) when I cause an error (f.e. calling a undefined function). Idk if this information helps...
Ok, thanks for your reply Kato!
I changed quite a lot, since I started the "project". Instead of using mutliple HTML files I copied everything into the index.html and work now with mutliple (hidden) DIVs.
But unfortunatly, the problem still exists.
I offer two different Login possibilites. One with Facebook (works 100% of the time for me) and one with the SimpleLogin (works barely).
I´m pretty sure I did the initialization the same way like it´s done in the tutorials on firebase.com.
This is how I connect to the Firebase DB
var ref = new Firebase('https://partyfinder-db.firebaseio.com/');
var auth = new FirebaseSimpleLogin(ref, function(error, user) {
if (error) {
// an error occurred while attempting login
alert(error);
} else if (user) {
// Here I work with user.id etc.
} else {
// user is logged out
}
});
And that is how I try to login the user...
function login() {
//I probably should use jQuery here...
var _email = document.getElementById("emailLogin").value;
var _pw1 = document.getElementById("passwordLogin").value;
var _rememberMe = document.getElementById("rememberMe").checked;
auth.login('password', {
email: _email,
password: _pw1,
rememberMe: _rememberMe
});
showMain(); //Hide and show DIVs and stuff...
}
I call this function on the SignIn Button. The whole Javascript file is linked in the head part of the HTML file.
So, calling this function is normally causing the following error
Error: FirebaseSimpleLogin: An unknown server error occurred.
I already figured out that this message only shows up when the connection to the DB already was successful. For example, when I type in an invalide email adress, the following message appears:
Error: FirebaseSimpleLogin: The specified user does not exist.
There are a few things that can "fix" the problem. For example, when I use the Facebook Login and logout after this was successful, I can sign in using firebase simpleLogin. Sometimes (unfortunatly not always) it helps when I`m causing an error, f.e. calling a non existing function. After the error message is displayed in the console, I can continue logging in (successfully).
But to be honest I`ve absolutly no idea what this tells me about the error and if this is somehow a hint to the solution. I also tried to set some breaking points and debug through the relevant code (using google chrome) but didn´t find anything.
I uploaded the page to a free webspace, where you can test this whole thing by yourself.
But please note, this project is just for testing purpos. I´m not planning to release it somehow, it´s just for me to figure out multiple things and I find it easier to learn something when I can set it in a context. I´m pretty sure it´s quite bad coded and contains many mistakes, etc. But I´m always grateful for feedback beside the actual problem :)
For the login you can use
email: user#email.com
password: user
If you use the FB-Login, your Name and your email adress will be saved to the Database (but I can delete this section of the code if you want/need to use it and feel uncomfortable about it).
http://partyfinder.lima-city.de/
Most of the comments are in german, sorry for that...
I am creating an app on facebook and I am trying to post to a friend's wall. I'm using the facebook javascript SDK and the FB.ui method to do this. In short here is my code:
function test() {
var obj = {
method: 'feed',
to: '######'
};
function callback(response) {
alert(response['post_id']);
}
FB.ui(obj, callback);
}
Note that I made this code very simple for testing purposes.
When I run it, a facebook feed dialog opens correctly and at the top says "Post Story to friendsname's Wall". I type in a message and press Share. My alert pops up with a response['post_id'] number. Because there is a response['post_id'] the story should've been posted successfully right? However when I navigate to the friend's wall there is no story. I've tried this multiple times in slightly different ways and haven't been able to get it to work. If I remove the 'to' parameter and simply post to my own wall it -does- work. So for some reason, posting to a friend's wall breaks it?
I know it's a rather broad question but I was wondering if anybody had any ideas why this doesn't work. Thanks
I suspect the problem may be because your application is in sandbox mode - https://developers.facebook.com/docs/ApplicationSecurity/
When testing your apps, place them into Sandbox Mode. This hides your
app entirely from all users who you have not authorized in the
developer app to see the app, for the roles described below. Please
note that when your app is in Sandbox Mode, you cannot call any API
calls on behalf of users who cannot see your app.
Basically, if your application is in sandbox mode, nothing your application does can be seen by users who have not authorized your application or by users that have not been specifically listed in the "roles" within your applications settings.
Remove you application from sandbox mode or add some users to specific "roles" within your application.