1

I started building a Google Calendar Add-on, which I would like to migrate to a Chrome extension (to have more flexibility for the UI). In Google Scripts add-ons, one can define a trigger function that executes whenever a calendar event is created / updated (see here).

Do you know how I can have a similar behaviour in a Chrome extension? Basically, I would like to define a function to be called whenever the user opens / updates an event (such as in the picture below).

I am very new to front-end dev so any help / pointers would be greatly appreciated.

Many thanks

enter image description here

I researched the Google Calendar API documentation extensively but couldn't find a solution to my problem.

Alex
  • 23
  • 4

1 Answers1

1

I'm new to developing Chrome Extensions myself, so I may be missing something, but I do not think you are able to define triggers in that way with Extension. You're usually just sending messages between the Content and Background pages.

All that being said, you might be able to get what you need from this answer. I haven't tried it within a Chrome Extension myself, but I just tried it out in the Chrome console while on the Google Calendar page and I did get a lot of notifications immediately when I clicked on my calendar to open an event. The "Create an Event" window is enclosed within a "span" element, so that's how I defined the MutationObserver:

 let observer = new MutationObserver(mutations => {
    for(let mutation of mutations) {
         for(let addedNode of mutation.addedNodes) {
             if (addedNode.nodeName === "SPAN") {
                 console.log("Create a Calendar Opened", addedNode);
              }
          }
     }
 });
 observer.observe(document, { childList: true, subtree: true });

You'll probably need to fiddle around with the node selector to get exactly what you want though.