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..
Related
I have run in to the following problem:
For a customer I have to be able to open websocket connection to different websockets, depending on the current view.
The Connection & Message Handling is no issue & is all working as intended.
However, I wanted to implement a function that closes the open websockets when switching views, so they don't stay running for no reason.
I do this through the following code :
$scope.closeOpenWebsockets = function () {
var socketLength = $scope.openWebsockets.length;
while (socketLength--) {
console.log($scope.openWebsockets[socketLength]);
$scope.openWebsockets[socketLength].close(4999);
}
$scope.openWebsockets = [];
};
$scope.addOpenWebsocket = function (socket) {
$scope.openWebsockets.push(socket);
};
This does work, the only thing I can't get working is changing the close code of the websocket.
Based on the list I found here :
https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
I tried using various codes listed there, but none seem to work. everytime I call the .close() myself, the close code I get back is 1006. Above example is with 4999, a close code normally available for applications. But also did not work when trying to send for example 1000.
The reason I need this is because the connection can also be closed from the other side, & in this case I need to try and reconnect. (It's always a close event & not an error event).
I hoped to do this based on close code, but I wanted to choose the code I sent when closing manually so that I am sure I'm not blocking any other close codes I might receive (I can only do limited tests with the source system & thus I am not 100% sure of all possible codes I might receive)
As probably visible in the code, I'm doing this in AngularJS.
Am I missing something here? I have looked through numerous stackoverflow posts/websocket guides and so on. But I haven't found anything.
Edit : This was one of the guides I found:
https://www.tutorialspoint.com/websockets/websockets_closing_connection.htm
I am working on zapier, where I have created a zap with my app(Test Message) as trigger , now when I test my app as trigger while making a zap it shows "Make sure you have at least one recent Test Message created." and therefore i have to skip the test and make an action without testing my trigger.
Please tell me where i am going wrong.
thanks in advance
This means that your trigger isn't working or you didn't test it per the instructions. You need to cause your external system to perform the action that would have caused your Zap to trigger. For example, if your trigger GitHub > New Repository, you have to actually go make a new repository on GitHub, and then return to Zapier to let it test (you can delete that new repository after you're done). If you can't, it's going to be difficult or possibly impossible to move forward.
This question seems to be a duplicate of getting message “Make sure you have at least one recent message created.” in ZAPIER.
I'm building an android application that uses Parse's push functionality to send messages between single users, and after a lot of finagling around with different solutions (without enabling Client Push because that's apparently a security risk) I settled on this:
// com.myapp.Application.java
public void onCreate(){
...
ParseInstallation i = ParseInstallation.getCurrentInstallation();
i.put("username", ParseUser.getCurrentUser().getUsername());
i.saveInBackground();
...
}
Now, when I want to send a push to a single user, I call a Cloud Code function that does this:
// cloud/main.js
Parse.Cloud.define("pushMessage", function(request,response) {
var from = request.user.getUsername();
var to = request.params["receiver"];
var query = new Parse.Query(Parse.Installation);
query.equalTo('username', to);
Parse.Push.send({
where: query,
data: {
alert: "message from " + from,
// more data
}
}
}
This feels a bit like a hack, but it works. Is it bad form? I can't really wrap my head around the solutions I've seen so far, mostly because they're almost exclusively geared toward iOS and I can't read objective-C.
Okay, so I had to re-do this. I'll answer it just in case someone has the same problems.
The issue with including the username in the installation is that you need to make sure that you handle it correctly. The installation is, as the name implies, tied to the device instead of the user. This means that if your application supports several users, it's one extra step to handle on relog, otherwise users will get pushes not meant for them.
I forgot about doing some of that, and my code turned into sphagetti.
After digging around for a bit, I changed the method to instead subscribe to a channel named after the user's ObjectId, and simply sending pushes to that channel. I then unsubscribe on logout and resubscribe every time the application opens. That way, if you close the application you can still receive pushes. It works just as well, and requires less code.
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
}
});
I am using Parse.com with my iPhone app.
I ran into a problem earlier where I was trying to add the currently logged in user to another user's PFRelation key/column called "friendsRelation" which is basically the friends list.
The only problem, is that you are not allowed to save changes to any other users besides the one that is currently logged in.
I then learned, that there is a workaround you can use, using the "master key" with Parse Cloud Code.
I ended up adding the code here to my Parse Cloud Code: https://stackoverflow.com/a/18651564/3344977
This works great and I can successfully test this and add an NSString to a string column/key in the Parse database.
However, I do not know how to modify the Parse Cloud Code to let me add a user to another user's PFRelation column/key.
I have been trying everything for the past 2 hours with the above Parse Cloud Code I linked to and could not get anything to work, and then I realized that my problem is with the actual cloud code, not with how I'm trying to use it in xcode, because like I said I can get it to successfully add an NSString object for testing purposes.
My problem is that I do not know javascript and don't understand the syntax, so I don't know how to change the Cloud Code which is written in javascript.
I need to edit the Parse Cloud Code that I linked to above, which I will also paste below at the end of this question, so that I can add the currently logged in PFUser object to another user's PFRelation key/column.
The code that I would use to do this in objective-c would be:
[friendsRelation addObject:user];
So I am pretty sure it is the same as just adding an object to an array, but like I said I don't know how to modify the Parse Cloud Code because it's in javascript.
Here is the Parse Cloud Code:
Parse.Cloud.define('editUser', function(request, response) {
var userId = request.params.userId,
newColText = request.params.newColText;
var User = Parse.Object.extend('_User'),
user = new User({ objectId: userId });
user.set('new_col', newColText);
Parse.Cloud.useMasterKey();
user.save().then(function(user) {
response.success(user);
}, function(error) {
response.error(error)
});
});
And then here is how I would use it in xcode using objective-c:
[PFCloud callFunction:#"editUser" withParameters:#{
#"userId": #"someuseridhere",
#"newColText": #"new text!"
}];
Now it just needs to be modified for adding the current PFUser to another user's PFRelation column/key, which I am pretty sure is technically just adding an object to an array.
This should be fairly simple for someone familiar with javascript, so I really appreciate the help.
Thank you.
I would recommend that you rethink your data model, and extract the followings out of the user table. When you plan a data model, especially for a NoSQL database, you should think about your queries first and plan your structure around that. This is especially true for mobile applications, as server connections are costly and often introduces latency issues if your app performs lots of connections.
Storing followings in the user class makes it easy to find who a person is following. But how would you solve the task of finding all users who follow YOU? You would have to check all users if you are in their followings relation. That would not be an efficient query, and it does not scale well.
When planning a social application, you should build for scalabilty. I don't know what kind of social app you are building, but imagine if the app went ballistic and became a rapidly growing success. If you didn't build for scalability, it would quickly fall apart, and you stood the chance of losing everything because the app suddenly became sluggish and therefore unusable (people have almost zero tolerance for waiting on mobile apps).
Forget all previous prioities about consistency and normalization, and design for scalability.
For storing followings and followers, use a separate "table" (Parse class) for each of those two. For each user, store an array of all usernames (or their objectId) they follow. Do the same for followers. This means that when YOU choose to follow someone, TWO tables need to be updated: you add the other user's username to the array of who you follow (in the followings table), and you also add YOUR username to the array of the other user's followers table.
Using this method, getting a list of followers and followings is extremely fast.
Have a look at this example implementation of Twitter for the Cassandra NoSQL database:
https://github.com/twissandra/twissandra