Creating a notification from within a notification - google-chrome

I'm creating an extension for Chrome, and one of the functionalities included is the ability for the end user to add people as contacts.
Currently, the contact is saved to the database via AJAX, after which a desktop notification is displayed telling the user that the deed has been done.
However, I would want to first ask the user if he's sure he wants to do that. So I got the mad idea of wanting to create a new notification from within a notification.
So first, the confirmation HTML notification would be created from the background.html, and displayed. It contains a button, and upon clicking it, it should run the AJAX function and create a second notification, containing the feedback.
However, I seem to be unable to do this. I can't run createNotification() from the notification, sendRequest() doesn't seem to go through neither, and I can't use the onClose listener from background.html, because I want to differentiate between clicking the "Yes" button and the "No" button.
Is there any way I can do this? And if not, how should the confirmation dialog be implemented instead?

Have you tried using chrome.extension.getBackgroundPage()? This may provide the access to your background page's API that you require. For example, your first notification page calls the following when Yes is clicked;
function yesClicked() {
chrome.extension.getBackgroundPage().showSecondNotification();
}
The background page declares the showSecondNotification method as follows;
function showSecondNotification() {
webkitNotifications.createHTMLNotification(
chrome.extension.getURL('notification2.html')
).show();
}
Hopefully, this will cause the second notification to be displayed. I've used a similar method in my extensions before but only to retrieve information from the background page. However, I see no reason this shouldn't work.

Related

How track data with Angular and Google Analytic?

I work on a one single page application (360 virtual visit) with Angular 11. I would like to track user events and especially on buttons.
I started to put the Global site tag in my Index.html file like this: Global Site tag in Index.html
On google analytic, I receive connection data user First Data User
But I have no idea how I can track bouton click with Angular.
Does anyone have an idea that works today ?
do not hesitate to ask me questions for more information. :D
Thank you in advance for your answers. I would share my progress.
For something like Button Clicks, you have to configure custom events in Google Analytics and push that custom event whenever user clicks the button.
You can create onButtonClick() function and call it when user clicks the button. In the function, you should push event to the window.dataLayer:
onButtonClick() {
window.dataLayer.push({
event: 'button_click',
data: {
user: this.current_user._id,
... // Send some custom data that you want to track
}
})
}
You should be careful with SPA when you install gtag the way it is described into docs as it will track page views incorrect. In SPA browser loads the page only once, and all other actions will rerender the content but it still will not be counted as a views.
Instead you will need to set up router events. Here is a great tutorial for that. It also will explain how to set up other events like button clicks.
By the way in the example above they suggest to send user id with event. Instead of it you may send it with config only once, and it will be automatically added to any your event:
gtag('config', 'GA-ID', {
page_path: event.urlAfterRedirects,
user_id: this.user.id
});
You need to configure the Google tag manager to send events to Google Analytics. I've written a post about it: https://pieterjandeclippel.medium.com/angular-or-react-or-whatever-and-google-analytics-97342c909e61
Now it seems that Universal analytics will be on its way out, so you might want to try GA4 instead.
But I haven't tried with that one yet, since my own website has been configured to use UA.
We've added the same feature recently and this guide here, albeit a bit dated, explains it quite well.
It boils down to you using a dedicated GoogleAnalyticsService that enables you track specific events (ie. button clicks, scroll events, etc).

Opening email popups from Adobe AIR application

I need to open several email popups (~30) from Adobe AIR Flex app, I am currently using navigateToURL but I observed that at times some email popups go missing. I have tried callLater as well. WHen I introduce delay between popups it works better but still has a risk of some popup missing. Can anyone advise please? These emails dont have any attachments but have html contents.
I am guessing that you don't want all 25-30 messages to appear at once. If you could try to schedule a better way like the one below, I think that will really help you fix the problem:-
Add references to all the 25-30 objects in an array
Now on click of a button, show the 1st email body. Have a button in the popup which reads something like 'Send and Read next email'. On click event, fire the email to be sent and pop the next object from your array to show contents of the next email.

Populating Request on Back Button Click

So I am running into an issue. I have certain fields that I store within the request from page to page, because each page requires different fields to be populated within a collector that I used cross-page. The problem is the back button.
If I click the link to take my to my login page, the server populates the collector from the request with the appropriate pagename and event name, etc., to allow me to navigate to the login page. (Certain things have to load, so it has to go through a servlet). However, on that page, there are static modules for ads and whatnot, so clicking on one of the ads will take you to a separate, static page that does not require these attributes to access. In Chrome, Safari and FF, if I click the back button after accessing this static page, the browser asks me to reload the request to be able to view the page. In IE8, however, there is no page reload. It just kicks me back to the page, and does not populate the request, and it crashes with my sorry page.
I need to know if there is a way to populate the request on the back button click, and how to do so. Otherwise, my servlet is throwing a null pointer when trying to access the fields because they are all null in the request. Any help would be greatly appreciated. I am not even sure if this is at all possible.
I guess you are using POST requests to navigate to each page. POST should be used only to send some user action different from page view - login, buying something, changing settings, etc. The browsers require the user to confirm that they want to revisit a page using POST, before that implies state change. See What is the difference between POST and GET?
For simple content pages, where the user does not take action, it's better to use GET requests. Also, it is much more common to use request.getSession() to get and store the user fields on the server side. That is, you only send them once, and then look them up for each request. Look up for tutorials on session tracking in java.

chrome extension popup and background ajax

I have a requirement where the background.html continous to update every 10 minutes and when I click on the popup it should trigger the background to update immediately and show the result in the popup.
I have the background updating using ajax working and I have the popup trigger the background to make an immediate update using ajax working as well. However, I am stuck on how to display the latest result in the popup...how can I tell when the background ajax call is complete and show the latest result in the popup?
thanks
Well, if you want to listen for changes on the Background Page, you have two ways to do what you want.
In your Popup, you can register chrome.extension.onRequest.addListener in your Popup page, and in your background page you can chrome.extension.sendRequest when you get stuff updated.
You have direct access to the Popup DOM, you can get an instance from chrome.extension.getViews({type:'popup'}), and once you get that, you can just call a method in that DOM. From the popup, you can access the background page easily too with chrome.extension.getBackgroundPage(). For both cases, you get a DOMWindow returned.
I personally would use #2 because you belong in the same extension process, you do not need to communicate to an injected Content Script.
var popups = chrome.extension.getViews({type: "popup"});
if (popups.length != 0) {
var popup = popups[0];
popup.doSomething();
}
Hope this helps.

show page action popup on click

I'm making a chrome extension that uses pageAction.
I can set when it shows whether I want it to have a popup or handle the click myself.
What I want to do is handle the click myself, but with certain scenarios I don't want to process the normal code, and want to show the user a message. Preferably with a popup.
But it seams I can either make the pageAction have a popup or have an onClick. But not both.
I can show an alert, but that is ugly.
Currently, there is no "neat" or official way to handle both. You can just do either. But there are some work arounds that some Google extension product have done.
First of all, set it up to show the popup. And within your pageAction popup, you can have the initialization code to be something like this:
Page Action Popup:
function init() {
if (getClickBehaviour() == 'popup')
handlePopup();
else
openPage();
}
function getClickBehaviour() {
return localStorage['CLICK_BEHAVIOR'] || 'popup';
}
function openPage() {
chrome.tabs.create({url: 'http://google.ca'});
window.close();
});
}
init();
Then you can let your options, set the click behavior. If you want different behaviors on each click, you can do that too.
As you noticed, we are closing the popup right after for the "default" behavior that we don't want the popup to show. That is currently the only way to implement different behaviors.
I haven't tested this myself yet, but have you tried setting the popup to the empty string when you want to handle the click (chrome.pageAction.setPopup('')) and to your popup when you want to show a message. I'm not perfectly sure if the onClicked event handler gets called in that case (where the popup is dynamically set to the empty string), but it's worth looking into.
As far as I know, there is generally no way to programmatically open a popup window for a page or browser action. (Which is too bad, I would love this functionality; but you can imagine some of the annoyances if this were possible.)