Migrate from GWT to JS frameworks

I have a JS library that is embedded into multiple other websites.
This library creates

  1. Widgets (like the usual chat widget seen on multiple apps). These widgets are primarily iFrames
  2. Also it monitors the application state to show certain messages to users on certain actions. This is primarily logic that listens
    to events on page, tracks all mutations etc.

This library is entirely coded in GWT. Facing problems in retaining and hiring FrontEnd developers to work in Java.
Thinking of moving to React for widgets and Typescript for logic.
Queries:

  1. Is React + Typescript a good choice ? I evaluated Vue, Svelte. Are there any other frameworks/libraries that can be considered ?
    [Note that this library sits on top of multiple websites built in variety of ways. Primary requirement is to avoid any kind of javascript namespace conflicts]

  2. For widgets where most of the logic is UI related, and which are restricted to iFrames, we are thinking of rewriting the code in React. Is there something else we can do ?

  3. For logic(where there is no UI related code) , is there a way I can directly convert all GWT code to human readable and maintainable Typescript at once ?

  4. Any other way to undertake this overall migration ?

I need help forwarding a javascript request to my php file to another website with the same headers and everything

I am trying to get the contents of https://thumbnails.roblox.com/v1/batch using a javascript request but obviously CORS is going to block it because the origin does not allow javascript requests. I need help forwarding the javascript request to https://thumbnails.roblox.com/v1/batch with the same headers and request and everything.

How can I call a function for each array item BUT NOT have them all run at the same time [duplicate]

I was surprised I couldn’t find an example of this anywhere, Im sure there is one but I seem to be having a hard time finding one.

I have an array of links…
const array = ["www.google.com", "www.yahoo.com", "www.disney.com"];

and a function that takes a link and goes to the page and does some stuff and then closes with a resolve. I want to run the function using each array item but I don’t want the functions to run all at once.

I tried array.forEach((item) => { functionThatUsesArrayData(item) }) but this runs each scraper all at once.

In one function id like to be able to use an array of links and pass each link the the function but launch them one at a time…so when the first link is done being scraped, the next array item will be used in a function and be scraped.

function(arrayItem).then(()=> function(arrayItem2)).then(()=> function(arrayItem3);
Somthing like this…I feel like I should be able to do this with promises but I just cant seem to figure it out.

This is a small example…the real code I have is a web scraper that has an array of links to scrape but I dont want to have 10 pages of puppeteer up scraping at once, I need it to happen one after the other. Any ideas? Thank you!

async function functionThatUsesArrayData(link) {

    const chromeOptions = {
        headless: false,
        slowMo: 60,
        defaultViewport: null,
        args: ["--no-sandbox", "--disable-setuid-sandbox"],
    };
    const promise = new Promise(async (resolve, reject) => {
        const browser = await puppeteer.launch(chromeOptions);
        const page = await browser.newPage();
        await page.goto(link);
        await browser.close();
        resolve(setTimeout(() => {
            console.log(" TASKS FINSIHED COMPLETED")

        }, 3000))
    })
    console.log(promise)

}

functionThatUsesArrayData()```

Minimum distributables to get typeahead.js working

I’m trying to get started with typeahead.js.

I’m trying some of the examples on the examples page, but nothing is working. The menu wouldn’t come up. And when I finally did get the menu to display, it has a transparent background.

Does anyone know where the minimal steps are documented to get this component working? Do I need some CSS files? Which js files are needed?

Again, I don’t want Bloodhound or anything else beyond the absolute minimum Which files do I need?

Playing a IPTV live tv stream with VideoJS or similar

I’m trying to play live tv channel with videojs. I’ve tried various ways but always get “No compatible source was found for this media.” error. Other videos are playing fine.

The url plays fine in VLC and the codec shows the stream as “MPEG-H Part2/HEVC (H.265) (hevc)”.

I’ve tried across a range of browsers too, chrome, firefox, safari and edge.

This is the bones of the code. Is there a way to play it ?

<link href="https://vjs.zencdn.net/7.17.0/video-js.css" rel="stylesheet" />
<script src="https://vjs.zencdn.net/7.17.0/video.min.js"></script>
<script src="https://unpkg.com/videojs-contrib-dash/dist/videojs-dash.js"></script>
<script src="https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js"></script>

<video id='live-video' class='video-js vjs-default-skin' controls>
</video>

<script>
  var player = videojs('live-video');
  player.src({ src:'https://www.example.com/play.php?OTUxE2NDUN', type:'application/x-mpegurl'});
  player.play();
</script>

“asyncing” new Promise( resolve, reject )

Basically what you see me doing here is “asyncing” a promise that I’m just creating.

Is that some unadvisable, anti-pattern, fatal flow, or silly way to write a promise? If so, why?

function returnSomething(name) {

  return new Promise(async (resolve, reject) => {

    try {

       //some dealings....
 
       const somethingElse = await returnSomethingElse();

       //do some stuff with 'somethingElse'

       resolve(somethingElse);
    
    } catch(error) {

       //some dealings....

       reject(error);
       return;

    }

  });

}

The temptation to do this is basically very easy to explain. I want to avoid the .then().then().then() hell if I return a promise as a result from a promise.

I also wanted to avoid working with something like this:

function returnSomething(name) {

  return new Promise((resolve, reject) => {

       //some dealings....
 
       returnSomethingElse().then((somethingElse) => { 

          //do some stuff with 'somethingElse'

          resolve(somethingElse); 

       }).error((error) => {

          //some dealings....

          reject(error);
          return;
       });
    }

  });

}

Thanks in advance.

Push an object to an array vue.js

I am getting data from excel and trying to save that data into an array. I want to push the objects into an empty array when I upload the excel file, but I am getting this error Uncaught TypeError: Cannot read properties of undefined (reading 'push'). Here is my code:

<template>
  <div id="app">
    <input
      type="file"
      name="xlfile"
      id="xlf"
      v-on:change="displayFile($event)"
    />
    <b-table striped hover bordered :items="itemsList"></b-table>
  </div>
</template>

<script>
import * as XLSX from "xlsx/xlsx.mjs";
export default {
  name: "App",
  data() {
    return {
      itemsList: [],
    };
  },
  methods: {
    displayFile(e) {
      var files = e.target.files,
        f = files[0];
      var reader = new FileReader();
      reader.onload = function (e) {
        var data = e.target.result;
        var workbook = XLSX.read(data, { type: "binary" });
        let sheetName = workbook.SheetNames[0];
        let worksheet = workbook.Sheets[sheetName];
        let rowObject = XLSX.utils.sheet_to_row_object_array(worksheet);
        const finalJsonData = JSON.parse(
          JSON.stringify(rowObject, undefined, 4)
        );
        finalJsonData.map((item) => {
          this.itemsList.push(...item);
        });
        //console.log(typeof finalJsonData);
      };
      reader.readAsArrayBuffer(f);
    },
  },
};
</script>

How to get the id of a tab created in the background, in Google Chrome

I’m writing an extension which needs to collect all the ids of newly created tabs.
Using this snippet, I’m able to get an id of a tab that is created by just clicking “Add a new tab”, as the browser autmatically displays it.

chrome.tabs.onCreated.addListener(() => {
    let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
    tabs.push(tab.id);
});

But what I’m struggling with, is to get the id of a tab that is created when you select to open a link in a new tab, as it doesn’t set it as an active one, but rather stays on the same tab. Is there any option to get that?
Thanks.

Next.js app will not auto refresh to show changes in the browser even though im running npm run dev

I want to see any updates i make to my code reflected in the browser. In VSC terminal I run “npm run dev”. If i make changes to the code nothing happens unless i CTRL + C and run “npm run dev” again.

I have tried “npm run build” “npm start”

im wondering if it has to do with the way ive organized my project

below is my project’s directory organization:

v components
 v web3
  Connected.js
  NotConncted.js
  Web3Button.js
 DashboardSidebar.js
>node_modules
>pages
 >api
 _app.js
 index.js
...etc

enter image description here

How to get the text of H1 tag and copy it to another part of the code with Javascript?

I am in the process of adding “See more” sections to the bottom of some of my web pages. My plan to is to have something like this:

<h1>Unique title</h1>

<h2>See more</h2>
<ul>
<li><a href="/people/YYYY/category1/">More1</a></li>
<li><a href="/people/YYYY/category2/">More2</a></li>
<li><a href="/people/YYYY/category3/">More3</a></li>
<li><a href="/people/YYYY/category4/">More4</a></li>
<ul>

I have many hundreds of these to do so what I’m looking to do is use Javascript to copy the text in the H1 tag and replace ‘YYYY’ in the url with that text within the same page.

I have very limited knowledge of Javascript, I tend to only use WS3 snippets, but I’m struggling to find something for what I need.

Please note: there is more code between the H1 and H2 tags, I just haven’t included it. Also, the urls in the ul are examples only.

How can I format on server side so returned AJAX is formatted in the markup?

My server will return a hollow shell of an html page. In a simple example…

<html>
  <head>
    <title>end-user</title>
  </head>
  <body>
    <div id='prnt'>
    </div>
  </body>
</html>

It then does an AJAX request to return dynamic content. Again a simple example of the content…

  <div id='chld'>
    <div id='gndcld'>
      All kinds of stuff will go in here!
    </div>
  </div>

As the end-user is a developer that will take the markup and modify it for their own specialized use, I want the HTML markup to be formatted for ease of readability, with all the indentions and new lines. So the resulting markup would look something like…

<html>
  <head>
    <title>end-user</title>
  </head>
  <body>
    <div id='prnt'>
      <div id='chld'>
        <div id='gndcld'>
          All kinds of stuff will go in here!
        </div>
      </div>
    </div>
  </body>
</html>

So far I can return the content so that the browser rendering of the markup is what I want, but the markup itself is all in one line. I’ve tried various rn type combinations that either the browser doesn’t like or it simply ignores. Is this even possible? If it is significant, the server code is C++ and I’m using plain JavaScript on the browser side. The server is a microcontroller, so there is not enough room for things like jQuery or other 3rd party libraries.

Thanks for any help you can provide.

use route parameter in the Redux Saga file

How to pass current route parameters to the saga function?

enter image description here

// Saga
 function* findOneReleaseWithFilesSaga() {
   const { productName, releaseId } = useParams()
   try {
     const releaseResponse: AxiosResponse = yield call(findOneWithFiles, releaseId)
                                                       ^^^Error Here^^^
     yield put(getAllReleasesSuccessAction(releaseResponse))
   } catch (error) {
     yield put(getAllReleasesErrorAction(error))
   }
 }

// Fetch Data
 export const findOneWithFiles = async (releaseId:string) => {
   return await Api.get(`/releases/${releaseId}/?populate=data_files`)
     .then((res) => res.data.data)
     .catch((err) => err)
 }

How can i get all GUID’s in parents and children where enabled = true

I have a need to get a list of all nodes (guid) in my json doc where the enabled key is set to true. What is the best and most effective way to read all parent nodes as well as possible children. In my case children will always be under the items key and children can also have there own children. I came up with some basic script that will check 2 levels deep but i was hoping there is a better approach which will make this more flrxible where i dont have to hardcode each level.

const enabledguid = []

function getenabled() {
  mydata.jsondoc.forEach(i => {
    if (i.enabled === true) {
      enabledguid.push(i.guid)
    }
    // Check if Parent has children
    if (i.items && i.items.length > 0){
      console.log('we have children ' + i.items.length)
        i.items.forEach(i => {
          if (i.enabled === true) {
          enabledguid.push(i.guid)
          }
          if (i.items && i.items.length > 0){
          console.log('Child has children ' + i.items.length)
            i.items.forEach(i => {
          if (i.enabled === true) {
          enabledguid.push(i.guid)
          }
            })
          }
    })
  }
  })
  console.log(enabledguid)

  
}

getenabled() 

Here is a sample of a json file

[
    {
        "enabled": true,
        "guid": "F56AAC06-D2EB-4E1C-B84D-25F72973312E",
        "name": "Farms",
        "items": [
            {
                "enabled": true,
                "guid": "144C0989-9938-4AEC-8487-094C23A5F150",
                "name": "New Farm List"
            },
            {
                "enabled": false,
                "guid": "8FBA7B0B-566E-47CD-885B-1C08B57F34F6",
                "name": "Farm Lists"
            },
            {
                "enabled": true,
                "guid": "FCD36DBD-0639-4856-A609-549BB10BEC1A",
                "name": "Farm Upload"
            },
            {
                "enabled": false,
                "guid": "4264DA98-1295-4A65-97C6-313485744B4D",
                "name": "Campaign",
                "items": [
                    {
                        "enabled": false,
                        "guid": "9CBDC6BB-5B3D-4F53-B846-AFE55F34C1E9",
                        "name": "New Campaign"
                    },
                    {
                        "enabled": true,
                        "guid": "281490B5-C67D-4238-9D52-DE1DFA373418",
                        "name": "Campaign List"
                    }
                ]
            }
        ]
    },
    {
        "enabled": true,
        "guid": "1A9127A3-7AC7-4E07-AFA0-B8F8571B1B14",
        "name": "Vendor",
        "items": [
            {
                "enabled": true,
                "guid": "6E6B4DA9-D99D-42D8-A4FE-7C7A82B9F1BE",
                "name": "Vendor List"
            },
            {
                "enabled": false,
                "guid": "63A61762-75FB-466A-8859-25E184C3E016",
                "name": "Add Vendor"
            }
        ]
    }
]

How to get Data using Mongoose

I want to get following data using Mongoose.

This is Schema structure

title: {
    type: String,
},
deadline: {
    type: Number,(day)
},
date: {
    type: Date,
    default: Date.now()
}

In above, “date” field represents start time.
start time = date
end time = date + 24 * 3600 * 1000 * deadline
I want to get data that current date is in between “start time” and “end time”
Please help me.