i am implementing pusher with php library for notification system. Everything was running fine until i discovered that including pusher js library fires all the javascript/jQuery events twice. There is a case where admin edits the applicat's details and saves it via ajax request. If i don't include pusher js library it send only one ajax request for saving but if i include pusher library then ajax request are sent twice. i was also having trouble with jQuery toggle() where event is fired twice so instead of showing the content of the div that i applied toggle() event it shows and hide the content of the div in quick succession.
Related
Is there a listener that fires whenever a tab notifies the user of an event?
F.e. whenever a message in Whatsapp-Web or any other webapp messenger arrives?
chrome.tabs does not seem to have one as onUpdated does not fire.
I'm using pusher for a python-vuejs app.
I have a function that sends data to the pusher, the data content is {'message':{'value':id_value}}
The function is executed via an api rest POST request, when I trigger the function and send the data to the pusher on the page with the url host/data-url the pusher console shows the correct informations for the first time.
When I execute the POST request again (without refreshing the page), the data is gotten twice (gotten means that it is physically there not just a pusher console output), if i do the request again it is gotten 3 times and so on.
Does anyone have any idea on how to initialize pusher after each request or something because if I refresh the page and send the data, it works again and i get it only once.
I figured it out if anyone have the same problem.
1.You should subscribe the moment you call the page.
2.If you are triggering the channel.bind with a button click (or any event launcher ) , make sure to unbind before the click and not after.
I am learning the Event Pages for Chrome extension and according to the documentation, the scripts will only be loaded when needed. Then I find that the Google Mail Checker's event page script will add the event listener:
// Some declarations
chrome.browserAction.onClicked.addListener(goToInbox);
// ...
And I write an event script:
chrome.tabs.create({url: 'https://www.google.com'});
function onClickListener() {
chrome.tabs.create({url: 'https://www.bing.com'});
}
chrome.browserAction.onClicked.addListener(onClickListener);
After I reloaded my extension, a new tab of google.com is opened as expected. Seconds later the process of my extension is gone in Chrome's task manager, and I clicked the extension icon. Then, both google.com and bing.com are opened! So I learn that this entire script will be loaded again.
Now look back to the script of Google Mail Checker. The listener will be added repeatedly once the script is loaded, so my question is: is it ok to add listener repeatedly? If the listener's behavior will change from A to B when the script is loaded, which one will be fired on the second load, A or B?
In fact your question is logically impossible, since the documentation has stated that the event listener will only exist in the context of the event page, that means it will be automatically removed once the event page is unloaded. So to some degree, it's ok to add listener repeatedly, although in fact you are adding it only once.
Because the listeners themselves only exist in the context of the event page, you must use addListener each time the event page loads
And Chrome also states that in the first line of best practices when using event pages
Register to receive any events your extension is interested in each time the event page is loaded. The event page will be loaded once for each new version of your extension. After that it will only be loaded to deliver events you have registered for. This generally means that your event listeners should be added at the top level scope of the event page, otherwise they may not be available when the event page reloads.
I have a great working chrome extension now.
It basically loops over a list of HTML of a web auction site, if a user has not paid for to have the image shown in the main list. A default image is shown.
My plugin use a jQuery Ajax request to load the auction page and find the main image to display as a thumbnail for any missing images. WORKS GREAT.
The plugin finds the correct image url and update the HTML Dom to the new image and sets a new width.
The issue is, that the auction site tracks all pages views and saves it to a "recently viewed" section of the site "users can see any auctions they have clicked on"
ISSUE
- My plugin uses ajax and the cookies are sent via the jQuery ajax request. I am pretty sure I cannot modify the cookies in this request so the auction site tracks the request and for any listing that has a missing image this listing is now shown in my "recently viewed" even though I have not actually navigated to it.
Can I remove cookies for ajax request (I dont think I can)
Can chrome remove the cookie (only for the ajax requests)
Could I get chrome to make the request (eg curl, with no cookie?)
Just for the curious.
Here is a page with missing images on this auction site
http://www.trademe.co.nz/Browse/SearchResults.aspx?searchType=all&searchString=toaster&type=Search&generalSearch_keypresses=9&generalSearch_suggested=0
Thanks for any input, John.
You can use the webRequest API to intercept and modify requests (including blanking headers). It cannot be used to modify requests which are created within the context of a Chrome extension though. If you want to use this API for cookie-blanking purposes, you have to load the page in a non-extension context. Either by creating a new tab, or use an off-screen tab (using the experimental offscreenTabs API.
Another option is to use the chrome.cookie API, and bind a onChanged event. Then, you can intercept cookie modifications, and revert the changes using chrome.cookies.set.
The last option is to create a new window+tab in Incognito mode. This method is not reliable, and should not be used:
The user can disallow access to the Incognito mode
The user could have navigated to the page in incognito mode, causing cookie fields to be populated.
It's disruptive: A new window is created.
Presumably this AJAX interaction is being run from a content script? Could you run it from the background page instead and pass the data to the content script? I belive the background page operates in a different context and shouldn't send the normal cookies.
I'm building a Chrome extension that manipulates the content of the page, but the content I'm interested in only shows up when the user has clicked a button and the data has then been loaded from an Ajax call.
At the moment the extension monitors the page with a SetTimeout but it's clumsy.
Can an extension know when an Ajax call has been initiated, and when it ended? or can the extension somehow receive events from the page?
I don't know an easy way to monitor XHR requests, but you can monitor any changes being made to a page structure by listening to DOMSubtreeModified event. So when ajax call is done and elements are added/removed/changed on a page - you will be notified.
document.addEventListener("DOMSubtreeModified", function(event){
//something has changed
});