how to debug an event listener - html

Kindly help in debugging an event listener. I have written a popstate event listener to window object.
window.addEventListener('popstate',function);
The popstate event should be triggered when a browser back button is clicked but how however it get triggered when i add history using HTML5 history api.
history.pushstate();
How to debug an event listener which triggered the event or previous step of execution using firebug or other developer tools. Kindly guide me as I am new to UI development.

Can you get this information from the call stack if you put a breakpoint in your callback?
Also, note the docs indicate that popstate can be called more often then your question indicates:
The popstate event
A popstate event is dispatched to the window every time the active history entry changes. If the history entry being activated was created by a call to pushState or affected by a call to replaceState, the popstate event's state property contains a copy of the history entry's state object.
https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history

Related

Why is the fetch event not firing in ServiceWorker on Google Chrome?

The "fetch" event never fired. I tried everything, registering/unregistering, changing the scope, refreshing, clearing cache/app data, etc.

g-suite Google Calender Apps script On Event Save/Update

First of all, i am new to Google Workspace and this is the first time i am developing an addon.
I am trying to develop a Google Workspace(gsuite) Addon using Google Apps Script,
My main objectives are:
Whenever i create/save/update an event in Google Calender, i want to make an alert asking for ok and cancel, if i click cancel the event should not be created and if i click ok then the event should be created and the script function should call my API endpoint with the following parameters:
{
summary: summary_of_the_event,
created: event_created_or_updated_date,
googleCalendarId: calender_id
}
Here is the reference to Apps script Google calender:
https://developers.google.com/apps-script/reference/calendar/calendar-app
I appreciate the help.
Some thoughts about calendar add-ons
CalendarApp features the installable calendar trigger with the specification:
Calendar triggers fire when a user's calendar events are updated (created, edited, or deleted).
Installble triggers can be used in Google Workspace add-ons
Howver, this installable trigger only fire after the event has been created / updated, so it can help you to cancel event creation, but rather no manually delete the event a posteriori.
Mind also that the when the trigger fires, it does not give you any information about the created / updated event - you have to manually find this event e.g. by querying for the least created / updated event in user's calendar.
Google Workspace Calendar add-ons feature the manifest trigger for updating calendar events calendar.eventUpdateTrigger
Thereby:
This trigger only fires if the user makes one or more of the following edits:
Adds one or more attendees.
Removes one or more attendees.
Adds or switches to a different conferencing solution.
Google Workspace Calendar add-ons also feature the manifest trigger calendar.eventOpenTrigger
It fires when you open an event (this is what you want!).
However, this work only for already existing events - not when a user opens the Calendar UI interface to create a new event
Instead of letting a user create / update events through the regular Calendar UI, you can use Card Service to create a custom add-on interface where the user can specify that he wants to create an event
Within the card interface, it is easier to implement an ok / cancel functionality (as a card) and then (in case "ok" is clicked) create an event for the user programmatically.

eventOpenTrigger - Google appsscript only fire's the first time

Trying to build an addon for Google Calendar. When I first click on an event it triggers the eventOpenTrigger function. This works as expected.
If I click on another event again eventOpenTrigger triggers. If I then again click on the original event then eventOpenTrigger is not fired. Is this by design? Seems like this only triggers once for each unique event. I would like to update some information in the card every time the event is clicked on.
unfortunately there is no refresh from code, the action is bound to "eventOpenTrigger" when the calendar event is opened, if you want to re-run the function onCalendarEventOpen(event) you need to create an action such as
var action = CardService.newAction()
.setFunctionName('onCalendarEventOpen')
.setLoadIndicator(CardService.LoadIndicator.SPINNER)
you can provide a refresh button and add this action to button click, only this way i was able to get the event data that is required, if you do not want any event data and just need to call this function you can return onCalendarEventOpen from another and use calendar api to fetch the event details
const eventFromAPI = Calendar.Events.get(calendarId, eventId);
this is the only work-around i have been following

Google script change events queuing

I have set up a change event trigger on my google spreadsheet. This works well, except when several users access the sheet simultaneously. I have noticed some data corruption (rows overwritten).
Is there a way to make sure that some code triggered from a change event has to wait for code triggered from a prior change event to complete?

cancel a drag'n'drop operation after it has started

I am looking for a way to cancel a drag and drop operation after the dragstart event handler has returned.
My aim is to allow or disallow a drag and drop operation based on an asynchronous AJAX response that has been sent on the dragstart event.