0

Background: While coding in Javascript, Python, Java, or C#.NET, I want a consistent API aggregator (library?) so that I can code something like as follows:

  self.clould.aws.api-runtime.getBackgroundRemoteAPIClient = function() { ....

For example, Chromium Extentions (2015) to Chrome in Javascript have syntax as follows:

  self.chrome.runtime.getBackgroundClient = function() {

Let's start with Javascipt. Is there any such Javascript library/extension "cloud aggregator API" that might allow me to write something similar to the following:

// Copyright 2022 The CloudAPI 8814 Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This function is returned to appropriate ServiceWorkerThread (browser-specific)
// then executed, passing in dependencies as function arguments.
//
// |backgroundUrl| is the URL of the extension's background page.
// |wakeEventPage| is a function that wakes up the current extension's event
// page, then runs its callback on completion or failure.
// |logging| is an object equivalent to a subset of base/debug/logging.h, with
// CHECK/DCHECK/etc.
(function(browser, cloudAPI, backgroundUrl, wakeEventPage, logging) {
  'use strict';
    // Browser is Chrome, Safari, or Edge
  self.chrome = self.chrome || {};
  self.chrome.runtime = self.chrome.runtime || {};
  // Safari - removed for clarity
  // Edge - removed for clarity

  // Returns a Promise that resolves to the background page's client, or null
  // if there is no background client.
  // Example only: 2022-Nov-19, the WHAT the API does is less relevant than the AGGREGATION
  //     SEEKING: Aggregator API that works consistent syntax whether run in Chrome or Safari. 
  //     WIP: Working on such API for a while, since I cannot locate any.
  // Chromium-specific syntax (2022):
  function findBackgroundClient() {
    return self.clients.matchAll({
      includeUncontrolled: true,
      type: 'window'
    }).then(function(clients) {
      return clients.find(function(client) {
        return client.url == backgroundUrl;
      });
    });
  }

  // Chromium-specific syntax (2022):
  // Returns a Promise wrapper around wakeEventPage, that resolves on success,
  // or rejects on failure.
  function makeWakeEventPagePromise() {
    return new Promise(function(resolve, reject) {
      wakeEventPage(function(success) {
        if (success)
          resolve();
        else
          reject('Failed to start background client "' + backgroundUrl + '"');
      });
    });
  }


  // Chromium-specific syntax (2022):
  // The chrome.runtime.getBackgroundClient function is documented in
  // runtime.json. It returns a Promise that resolves to the background page's
  // client, or is rejected if there is no background client or if the
  // background client failed to wake.
  self.chrome.runtime.getBackgroundClient = function() {
    return findBackgroundClient().then(function(client) {
      if (client) {
        // Background client is already awake, or it was persistent.
        return client;
      }

      // Event page needs to be woken.
      return makeWakeEventPagePromise().then(function() {
        return findBackgroundClient();
      }).then(function(client) {
        if (!client) {
          return Promise.reject(
            'Background client "' + backgroundUrl + '" not found');
        }
        return client;
      });
    });
  };
});

Context: I guess my question is in the context of "using a web browser such as Chrome, Edge, Safari." It seems each browser has a distinct model for extension-runtime? So far, I'm familiar with Chromium extensions for Chrome. Less familiar with extension-runtime models for Edge or Safari. Nice-to-have is works same on Web as Mobile(iPhone, Android).

Currently, I need to write Chrome-specific Javascript. Then Safari-specific Javascript. All I want is to write a "cross-browser" Javascript syntax. The purpose is to interaction in "cross-cloud" compatibility, where possible (Azure, AWS, SalesForce).

There are multiple questions about to unpack. Any direction, tips or help location "cross-browser APIs" and "cross-cloud APIs" (I.e. Aggregators) is greatly appreciated!

Q2: What did I do so far? This is a research question. This is a prototype I've written and used, and it does work. But it could work better if someone already had a useful or novel (free open-source) API?

I tried to Google it. I tried to look at StackOverflow for it. I tried to read up on blogs, libraries, etc for npm/Node. I tried to read up on blogs, libraries, etc for developer.Apple. I tried to "Bing it" for open-source javascript cross browser API. This was promising. I tried to Google it for open-source javascript cross browser API. Nothing.

This is javascript that I can probably make work, just need to re-write for each Browser:CloudAPI combo. What I want is a consistent API (so-called aggregator API, facade API pattern, adapter broker patterns).

React.js is good at HTML/CSS interactions. React.js might have API interactions with something like GraphQL (backend Cloud APIs). '' What is a react js the way to learn? '' BUT what I really want is a simple, consistent Javascript API that runs in any browser, for any Cloud.

It seems like no such Javascript library may exist? If so, then I'm sure there is even a good idea why none exists. This is not a Web 3.0 thing is It?

0 Answers0