Forum Discussion

_anomDiebolt_'s avatar
_anomDiebolt_
Qrew Elite
7 years ago

Service Worker to the Rescue

There has been a lot of traffic opining about the new release that changed various aspects of the GUI. To be honest I didn't read most of the posts in detail nor do I have any problem overcoming any of the undesirable changes. That is because I can modify any aspect of QuickBase using Service Workers. You can to.

As an example, here is a grid edit viewof an application that shows the current green New Record button which I want to remove using a Service Worker:



Here is a screenshot of the same page where a Service Worker has removed the green button:



Now you may be wondering what the left hand panel is and why the URL is showing the domain https://cloudflareworkers.com/. In a nutshell, cloudflare has implemented a jsfiddle like service where you can demonstrate and share the implementation of a Service Worker as applied to any URL. It just turns out that this is an easier way for me to publiclly share a Service Worker demo rather than implement it wholly within QuickBase.

Here is full source of the Service Worker used above:

addEventListener("fetch", event => {
  event.respondWith(fetchAndModify(event.request));
});
async function fetchAndModify(request) {
  console.log("got a request:", request);
  // Send the request on to the origin server.
  const response = await fetch(request);
  // Read response body.
  const text = await response.text();
  // Modify it.
  const modified = text.replace(
  '<a onclick="GE_embMenu_newRec(this)" id="GE_NewRecordPick">New Record</a>',
  "");
  // Return modified response.
  return new Response(modified, {
    status: response.status,
    statusText: response.statusText,
    headers: response.headers
  });
}

Basically the Service Worker looks for the <a> element associated with the New Record button and removes it - BEFORE THE BROWSER EVEN STARTS TO RENDER THE PAGE.

Now the important thing to notice is that this very same Service Worker implemented as a part of the CloudFlareWorker demo can be used as a client side Service Worker. (wholly within QuickBase)

Now I could write a hundred pages extolling the virtues of using Service Workers with QuickBase but the bottom line is there is nothing Service Workers can't do. Service Workers is god mode for QuickBase.

UPDATE: I forgot to post the link:

https://cloudflareworkers.com/#28a28d6d0a693d85a38d856f44a8de37:https://haversineconsulting.quickbas...~

Similar to a jsfiddle, you can modify the Service Worker code in the left panel and create your own version for experimentation before porting the code to your own application.

20 Replies

  • Interesting stuff I think I am so used to iol its hard for me to wrap my head around using anything else. I am currently trying to make a button that gets the value from a QuickBase input without having to save first, then sends a post to google calendar and saves after. Currently, it is a two-step process.
    The user has to save then they can send the POST to google calendar API.
  • SystemsBVI's avatar
    SystemsBVI
    Qrew Assistant Captain
    Hi Dan,

    So, we can take this javascript as is and add it just like the IOL technique or is there a different way to ingest this javascript into quickbase ?

    Thx!
    • _anomDiebolt_'s avatar
      _anomDiebolt_
      Qrew Elite
      Service Workers have to  be registered using code similar to this:

      navigator.serviceWorker.register('DBID?act=dbpage&pagename=sw.js');

      Once registered a Service Worker sits between your browser and the QuickBase server and listens for domain events and  can replace or modify the request and response or processes other events such as going offline, caching, syncing, notifications etc. 



      The above graphic needs to be updated as Service Workers also work in Edge, UC Browser and are in development for Safari.

      Nothing like this has ever been possible before without installing a client side proxy. Service Workers is like god mode for QuickBase and it can modify any aspect of the application.
    • SystemsBVI's avatar
      SystemsBVI
      Qrew Assistant Captain
      Thanks Dan! Do you have a full working demo somewhere on how this registration needs to be done etc ? I am confused on where exactly we would call the registration code?_
    • _anomDiebolt_'s avatar
      _anomDiebolt_
      Qrew Elite
      There is a series of posts I wrote called Service Worker Travel Log you can find in the forum. I sort of stopped midway posting to the series as these suckers are so powerful they are difficult to live demo without having an account dedicate to just to the Service Workers. But I assure you the are rightfully called god mode for QuickBase as there is nothing they can't do. But I get tired extolling their virtues as it takes years of promoting techniques such as IOL before it sinks in how powerful these scripting techniques are.
  • SystemsBVI's avatar
    SystemsBVI
    Qrew Assistant Captain
    Awesome! That is great. I think i can get started with this now...fun fun!!!
    Thanks much Dan!!
  • SystemsBVI's avatar
    SystemsBVI
    Qrew Assistant Captain
    So, ideally if i have service worker script for each table, we dont really need the old style IOL technique anymore. right ? All that could be done via IOL can be done from within the service worker scripts ?
    • _anomDiebolt_'s avatar
      _anomDiebolt_
      Qrew Elite
      A Service Worker has the concept of a scope which restricts what URLs will execute the Service Worker. A Service Worker will only execute against URL paths that are at the same level or lower. Because of QuickBase's URL architecture you can register a Service Worker against the scope https://SUBDOMAIN.quickase.com/db (basically the entire account) or against the scope of a single dbid https://SUBDOMAIN.quickase.com/db/DBID.

      Once registered the Service Worker will execute against any page in the defined scope (not just add, view, edit, report or grid pages). Every page including charts and  administrative pages. So within your Service worker you have to put the appropriate logic to decode what particular code should be executed based on the current URL or query parameters or some other condition..
    • SystemsBVI's avatar
      SystemsBVI
      Qrew Assistant Captain
      right. which would mean that we don't need to use the old style IOL technique (of embedding a field into each form). right ?