fetch or https in node returning text [object Promise], seems like await isn’t waiting

This JavaScript code runs successfully but the response text received is [Object promise]. I’ve tried using a few different styles (e.g. .then patterns) and also the https function which doesn’t seem to work properly either. It seems like the await is blowing out early. Curl, Python, Powershell, and some JavaScript running in Chrome work fine with the same REST API. The browser JavaScript that works is running on simpleSecretService.com on the editing page.

try {
    let response = await fetch(url);
    if (!response.ok) {
        throw response;
    }
    let response_text = await response.text();
    session = response_text;
}
catch (error) {
    throw error;
}

Server side lambda code is returning:

2024-01-19T14:24:45.628Z    cbac292b-a8cf-449b-a85f-238ffc646ab6    INFO    {
  statusCode: 200,
  body: 'eyJraWQiOiJwS1ZvaHVOSnVTTk9Ic3FXdksyM3krSUp5QU5wMEFtSktxbEVWaTdzWmhnPSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiIyMTJiYjUwMC1lMGQxLTcwOGMtNGFlZi0yN2ZjNDY2ODk1ZmEiLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMi5hbWF6b25hd3MuY29tXC91cy1lYXN0LTJfMFNrcURubHVhIiwiY29nbml0bzp1c2VybmFtZSI6InBldGVyMiIsIm9yaWdpbl9qdGkiOiI4N2E5MTMzOS0wZmQxLTRiOWItOTFiYS01NjZmZjYyY2JhZWIiLCJhdWQiOiI1MHZmMXJkY242cjBmMGk2cGxuam5rNWE2MSIsImV2ZW50X2lkIjoiNThkOTY5OGEtNWE4MC00M2Y2LTg1YjctZDllODI4NzgxY2YwIiwidG9rZW5fdXNlIjoiaWQiLCJhdXRoX3RpbWUiOjE3MDU2NzQyODUsImV4cCI6MTcwNTcxNzQ4NSwiaWF0IjoxNzA1Njc0Mjg1LCJqdGkiOiIwYTkxNTVhZi0zMWIwLTQzMDktOTk5Ni01YmVhYjgwZWM2NzAiLCJlbWFpbCI6ImFwaWVuaGFuY2VtZW50c0BnbWFpbC5jb20ifQ.Ehmke8viL7lV6FjulWPU4k41EPovvLCKHgaE9fLI5VGb6YDuPlw1SNQjO95kiLUh-c2WEFGVGjNacJE7Tpl_n6xJ44P9UvmhuaSBPtJP3kEJQtlbGcwkY8yjSE-MalzJ_WzGQPhMvfRU54vP1d_udNr0Aklz18BfFBtOB4xuq8qCvK4sc6QQNI-TJO-974Pwm1dBRHu4mpgu8Rs-yfcium0GUVouaqaEInBf-dw80v3wxq96YkG54LYWFAPX39OGJYxyzD1EOh2dYMBJ5J4dwHaRQo09AOxdze7fcjigfrKL3uwYL3fRkX0CLIz-o5dC4WVknFHJ7qS2K7zAdhqc4Q',
  headers: {
    'Content-Type': 'text/plain',
    'Access-Control-Allow-Methods': 'GET,PUT,DELETE,POST',
    'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With'
  }
}

Which payment gateway is best in Pakistan for node.js?

Payment gateways in Pakistan which can be implemented in Mern Stack. plus if anyone has a code or documentation for node.js it will be really appreciated.
Not asking from any legal perspective, just from the implementation side like which one is bit easy to implement.

code or documentation for node.js.

Is there a simple way to reorganize my db?

I am new to working with mongoDB and csv’s, and I have a dataset that I am working on. I downloaded the dataset as a csv, and am wondering if there is a way to re-organize the data? Currently each entry looks like this:

{
  "_id": {
    "$oid": "65a9be67f8523e6277bf7500"
  },
  "Country": "BANGLADESH",
  "Country Code": "BGD",
  "Year": 2017,
  "Wind Electricity Produced": 0.01,
  "Hydro Electricity Produced": 1.03,
  "Solar Electricity Produced": 0.25,
  "Renewable bioenergy (TWh)": 0.03,
  "Total Percentage of Renewables": 1.9155419,
  "Population Rank": 8,
  "Population": 169828911,
  "Hydro ELECTRIC SHARE ONLY  (% electricity)": 1.4947032,
  "Hydro SHARE ALL (% equivalent primary energy)": 0.7132308,
  "Electricity CONSUMPTION From Hydro ": 1.03,
  "Wind SHARE ELECTRIC ONLY  (% electricity)": 0.014511681,
  "Wind SHARE ALL  (% equivalent primary energy)": 0.003521487,
  "Electricty Generated From Wind ": 0.01,
  "Solar ELECTRICITY ONLY (% electricity)": 0.36279202,
  "Solar SHARE ALL (% equivalent primary energy)": 0.17552204,
  "Solar Electricity Usage": 0.25,
  "City": "Dhaka",
  "Air Pollution": 80,
  "Coordinates": "23.777176, 90.399452."
},

I would like to reorganize it so that it looks like this: 
 "Country": "BANGLADESH",
    {
        "City": "Dhaka",
            {
                "_id": {
                    "$oid": "65a9be67f8523e6277bf7500"
                },
                "Country Code": "BGD",
                "Year": 2017,
                "Wind Electricity Produced": 0.01,
                "Hydro Electricity Produced": 1.03,
                "Solar Electricity Produced": 0.25,
                "Renewable bioenergy (TWh)": 0.03,
                "Total Percentage of Renewables": 1.9155419,
                "Population Rank": 8,
                "Population": 169828911,
                "Hydro ELECTRIC SHARE ONLY  (% electricity)": 1.4947032,
                "Hydro SHARE ALL (% equivalent primary energy)": 0.7132308,
                "Electricity CONSUMPTION From Hydro ": 1.03,
                "Wind SHARE ELECTRIC ONLY  (% electricity)": 0.014511681,
                "Wind SHARE ALL  (% equivalent primary energy)": 0.003521487,
                "Electricty Generated From Wind ": 0.01,
                "Solar ELECTRICITY ONLY (% electricity)": 0.36279202,
                "Solar SHARE ALL (% equivalent primary energy)": 0.17552204,
                "Solar Electricity Usage": 0.25
                "Air Pollution": 80,
                "Coordinates": "23.777176, 90.399452."
            },
        }
    }

This way when converting the dataset to a JSON it can reference each country and then city to only return the data in each city.

Would it be best to use a Python groupby, and make it a new dataset with each country and city? or is there a simpler way to do this either in mongodb or just in Python or JS?

how to add URL parameters if the traffic comes from Google Search Engine?

I need to know how to detect if the traffic in the browser comes from Google Search Engine (SEO) programmatically using Google Tag Manager, and then convert it to URL paramaters

so if the user comes to my website from Google Search Engine after typing the keywords, then I need to add URL parameters utm_source=google and utm_medium=organic. so if the user comes from search engine then the URL should be like this

https://myWeb.com/?utm_source=google&utm_medium=organic

how to do that using Google Tag Manager in Javascript?

Why is html2canvas causing incorrect display on Firefox for LaTeX output but works fine on Edge and Chrome?

I am building a site that allows LaTeX input for .png output. Currently, it works to provide a perfect .png picture of a LaTeX equation on Edge/Chrome but I am unable to replicate using the same code on Firefox.

Here is the output on Chromium browsers:
equation on Chromium browswers

equation on Firefox browswers

No errors exist on the Chromium platforms, but errors exist on Firefox:

#1 0ms Starting document clone with size 1920x955 scrolled to 0,0 html2canvas.min.js:20:191994
#1 162ms Unable to access cssRules property DOMException: CSSStyleSheet.cssRules getter: Not allowed to access cross-origin stylesheet
    createStyleClone https://www.pangram-world.com/scripts/html2canvas.min.js:20
    createElementClone https://www.pangram-world.com/scripts/html2canvas.min.js:20
    cloneNode https://www.pangram-world.com/scripts/html2canvas.min.js:20
    appendChildNode https://www.pangram-world.com/scripts/html2canvas.min.js:20
    cloneChildNodes https://www.pangram-world.com/scripts/html2canvas.min.js:20
    cloneNode https://www.pangram-world.com/scripts/html2canvas.min.js:20
    appendChildNode https://www.pangram-world.com/scripts/html2canvas.min.js:20
    cloneChildNodes https://www.pangram-world.com/scripts/html2canvas.min.js:20
    cloneNode https://www.pangram-world.com/scripts/html2canvas.min.js:20
    fn https://www.pangram-world.com/scripts/html2canvas.min.js:20
    Js https://www.pangram-world.com/scripts/html2canvas.min.js:20
    e https://www.pangram-world.com/scripts/html2canvas.min.js:20
    e https://www.pangram-world.com/scripts/html2canvas.min.js:20
    a https://www.pangram-world.com/scripts/html2canvas.min.js:20
    a https://www.pangram-world.com/scripts/html2canvas.min.js:20
    Js https://www.pangram-world.com/scripts/html2canvas.min.js:20
    <anonymous> https://www.pangram-world.com/scripts/html2canvas.min.js:20
    convertToImage https://www.pangram-world.com/scripts/symbolsLatex.js:82
    renderEquation https://www.pangram-world.com/scripts/symbolsLatex.js:37
html2canvas.min.js:20:192835
#1 393ms Document cloned, element located at -9999,675.2999877929688 with size 169.43333435058594x35.01666259765625 using computed rendering html2canvas.min.js:20:191994
#1 393ms Starting DOM parsing html2canvas.min.js:20:191994
#1 428ms Starting renderer for element at -9999,675.2999877929688 with size 170x36 html2canvas.min.js:20:191994
#1 430ms Canvas renderer initialized (170x36) with scale 1 html2canvas.min.js:20:191994
#1 449ms Finished rendering html2canvas.min.js:20:191994
Source map error: Error: request failed with status 404
Resource URL: https://www.pangram-world.com/style/bootstrap.css
Source Map URL: bootstrap.css.map

Note: I downloaded html2canvas and Bootstrap and it is working as expected on Chromium and Bootstrap is working as expected on Firefox. But the outputs of the LaTeX are not the same.

This is the codeblock that prints the image for html2canvas:

function convertToImage() {
    const mathContainer = document.getElementById('mathContainer');
    // Temporarily position the mathContainer off-screen
    mathContainer.style.position = 'absolute';
    mathContainer.style.left = '-9999px';
    mathContainer.style.visibility = 'visible';

    // Render the image with html2canvas
    html2canvas(mathContainer, {
        backgroundColor: background === 'transparent' ? 'rgba(0,0,0,0)' : 'white',
    }).then(canvas => {
        // Now that the image is rendered, reset the mathContainer's style
        mathContainer.style.position = '';
        mathContainer.style.left = '';
        mathContainer.style.visibility = 'hidden';

        // Set the source of the result image and display it
        const resultImage = document.getElementById('resultImage');
        resultImage.src = canvas.toDataURL('image/png');
        resultImage.style.display = 'block'; // Show the image
        resultImage.style.margin = 'auto'; // Center the image if needed

        // Create the download link
        createDownloadLink(canvas.toDataURL('image/png'));

        // Create and display the copy button
        createCopyButton(canvas.toDataURL('image/png'));
    });
}

The initial position is to stop a double-up on rendering. I can’t seem to work out what the error is suggesting is wrong or why it is wrong on Firefox and what are my workarounds.

I had considered just stopping html2canvas for any Firefox browsers, but that seems drastic. I would prefer to fix the image output for all browsers.

The HTML head is:

<!-- Bootstrap CSS -->
    <link rel="stylesheet" href="style/bootstrap.css">
    <link rel="stylesheet" href="style/styles.css">
    <link rel="stylesheet" href="style/base.css">
    <link rel="stylesheet" href="style/cards.css">
    <link rel="stylesheet" href="style/symbols.css">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
    <!-- ... favicon ... -->
    <link rel="icon" type="image/x-icon" href="images/favicon.ico">
    <link rel="icon" type="image/png" sizes="16x16" href="images/favicon-16x16.png">
    <link rel="icon" type="image/png" sizes="32x32" href="images/favicon-32x32.png">
    <link rel="apple-touch-icon" sizes="180x180" href="images/apple-touch-icon.png">
    <link rel="icon" type="image/png" sizes="192x192" href="images/android-chrome-192x192.png">
    <link rel="icon" type="image/png" sizes="512x512" href="images/android-chrome-512x512.png">

    <script src="scripts/main.js" defer></script>
    <script src="scripts/bootstrap.bundle.js"></script>
    <script src="https://kit.fontawesome.com/18fe617275.js" crossorigin="anonymous"></script>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
    <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
    <script src="scripts/html2canvas.min.js"></script>

Vite imports all .env fields for firebase config file except projectId

I’ve placed all my variables for the firebase config file into a separate env file. Everything is retrieving correctly EXCEPT projectId.

Everything will only work if I paste the projectId string in there directly. If I have it as import.meta.env.VITE_PROJECT_ID it refuses to work and gives me:

@firebase/firestore: Firestore (10.7.2): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=permission-denied]: Permission denied on resource project {{projectname}},.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

If I replace import.meta.env.VITE_PROJECT_ID with the actual projectId string, but leave everything else as import.meta.env.{variable}…. everything works.

Can anyone help?

const firebaseConfig = {
  apiKey: import.meta.env.VITE_FIREBASE_API_KEY,
  authDomain: import.meta.env.VITE_AUTH_DOMAIN,
  projectId: import.meta.env.VITE_PROJECT_ID,
  storageBucket: import.meta.env.VITE_STORAGE_BUCKET,
  messagingSenderId: import.meta.env.VITE_MESSAGE_SENDER_ID,
  appId: import.meta.env.VITE_APP_ID,
};

console.log("this is the", firebaseConfig.projectId)


// Initialize Firebase
export const app = initializeApp(firebaseConfig);
export const db = getFirestore(app);

Storybook issue – Cannot access ‘__WEBPACK_DEFAULT_EXPORT__’

Some Relevant Context (I think)

I’ve worked on many projects that use what I believe are called “barrel dependencies” – a single file that exports a bunch of components for easy importing which looks like this:

// src/components/flexibleBlocks/index.js
export { default as Embed } from './Embed/Embed';
export { default as Image } from './Image/Image';
export { default as Text } from './Text/Text';
export { default as Video } from './Video/Video';

It means instead of writing:

import Embed from 'src/components/flexibleBlocks/Embed/Embed';
import Image from 'src/components/flexibleBlocks/Image/Image';
import Text from 'src/components/flexibleBlocks/Text/Text';
import Video from 'src/components/flexibleBlocks/Video/Video';

I can instead just do:

import { Embed, Image, Text, Video } from 'src/components/flexibleBlocks';

All well and good, works fine, no issues.

My App Structure

My apps and sites are often displaying content generated in a CMS, where the structure of a page is defined by the content editor, and cannot be hard-coded.

I use the following component to loop through the content:

// src/components/resolvers/FlexibleContentLoop.js
import { FlexibleContentResolver } from 'src/components/resolvers';

const FlexibleContentLoop = ({ flexible_content }) => {
  if (flexible_content) {
    return (
      <>
        {flexible_content.map((props, i) => (
          <FlexibleContentResolver
            key={i}
            {...props}
          />
        ))}
      </>
    );
  }
};

export default FlexibleContentLoop;

And the following to render the correct component for each entry in the previous loop:

// src/components/resolvers/FlexibleContentResolver.js
import * as blocks from 'src/components/flexibleBlocks';
import { Missing } from 'src/components/partials';

const FlexibleContentResolver = (props) => {
  const { componentName } = props;
  let Component;
  if (componentName in blocks) {
    Component = blocks[componentName];
    return <Component {...props} />;
  } else {
    return <Missing>Missing block: {componentName}</Missing>;
  }
};

export default FlexibleContentResolver;

It seems like an elegant solution to flexible CMS content, and I’ve used this for years with tools such as Create React App, Next.js, Gatsby, etc. without any issues.

The Problem:

Storybook doesn’t seem to like this. I think it boils down to circular dependencies.

I have my components setup so that you can nest one component loop inside another, which looks like this:

// src/components/flexibleBlocks/DynamicBlock/DynamicBlock.js
import { FlexibleContentLoop } from 'src/components/resolvers';

const DynamicBlock = ({ layouts }) => {
  return (
    <div>{layouts && <FlexibleContentLoop flexible_content={layouts} content_type="layout" />}</div>
  );
};

export default DynamicBlock;

I can see why it would be a circular dependency, but it works, and allowing a component to be nested inside itself is a valid pattern.

In some cases I’m seeing this error:

  ReferenceError: Cannot access '__WEBPACK_DEFAULT_EXPORT__' before initialization
  at Module.default (http://localhost:6006/src_components_resolvers_index_js.iframe.bundle.js:113:42)
  at Module.AgeScreen (http://localhost:6006/src_components_resolvers_index_js.iframe.bundle.js:773:111)
  at registerExportsForReactRefresh (http://localhost:6006/vendors-node_modules_pmmmwh_react-refresh-webpack-plugin_client_ErrorOverlayEntry_js-node_mod-dafa79.iframe.bundle.js:796:36)
  at Object.executeRuntime (http://localhost:6006/vendors-node_modules_pmmmwh_react-refresh-webpack-plugin_client_ErrorOverlayEntry_js-node_mod-dafa79.iframe.bundle.js:828:3)
  at $ReactRefreshModuleRuntime$ (http://localhost:6006/src_components_resolvers_index_js.iframe.bundle.js:806:34)
  at ./src/components/flexibleBlocks/index.js (http://localhost:6006/src_components_resolvers_index_js.iframe.bundle.js:819:2)
  at options.factory (http://localhost:6006/runtime~main.iframe.bundle.js:642:31)
  at __webpack_require__ (http://localhost:6006/runtime~main.iframe.bundle.js:28:33)
  at fn (http://localhost:6006/runtime~main.iframe.bundle.js:299:21)
  at ./src/components/resolvers/FlexibleContentResolver.js (http://localhost:6006/src_components_resolvers_index_js.iframe.bundle.js:2594:87)

And in others this error:

TypeError
Cannot read properties of undefined (reading 'default')
Call Stack
 Module.FlexibleContentResolver
  src_components_resolvers_index_js.iframe.bundle.js:2808:129
 undefined
  src_components_resolvers_index_js.iframe.bundle.js:2519:182
 FlexibleContentLoop
  src_components_resolvers_index_js.iframe.bundle.js:2519:34
 renderWithHooks
  vendors-node_modules_pmmmwh_react-refresh-webpack-plugin_client_ErrorOverlayEntry_js-node_mod-dafa79.iframe.bundle.js:58411:18
 mountIndeterminateComponent
  vendors-node_modules_pmmmwh_react-refresh-webpack-plugin_client_ErrorOverlayEntry_js-node_mod-dafa79.iframe.bundle.js:62175:13
 beginWork
  vendors-node_modules_pmmmwh_react-refresh-webpack-plugin_client_ErrorOverlayEntry_js-node_mod-dafa79.iframe.bundle.js:63688:16
 HTMLUnknownElement.callCallback
  vendors-node_modules_pmmmwh_react-refresh-webpack-plugin_client_ErrorOverlayEntry_js-node_mod-dafa79.iframe.bundle.js:46270:14
 Object.invokeGuardedCallbackDev
  vendors-node_modules_pmmmwh_react-refresh-webpack-plugin_client_ErrorOverlayEntry_js-node_mod-dafa79.iframe.bundle.js:46319:16
 invokeGuardedCallback
  vendors-node_modules_pmmmwh_react-refresh-webpack-plugin_client_ErrorOverlayEntry_js-node_mod-dafa79.iframe.bundle.js:46383:31

Is there a workaround to get storybook working with my flexible block components?

I don’t think there’s an alternative solution for my use case of CMS-driven nested flexible blocks.

Given that every other React tool I’ve used works fine with this pattern, I’m hoping there’s a way to get Storybook working too.

Thanks for any help.

The translation feature in Microsoft Edge does not behave as intended when automatically translating

When a user uses Edge’s built-in translation feature and sets the check to “Always translate (specific language),” translation occurs almost immediately after the page finishes loading. There is a big problem with this automatic translation process.

Current Edge behavior issue: Edge’s built-in translation feature automatically attempts to reference HTML checkbox buttons that contain custom checkbox labels, as shown in the code below. A drawer will automatically open and close immediately in parallel with the automatic translation process.

This behavior is not seen with Google Translate in Chrome or his TWP-Translate Web Pages add-on in Firefox, etc. However, Edge’s unique translation feature performs the above operations at the same time as automatic translation.

Is there anything I can do to resolve this?

// ==UserScript==
// @name         G App Launcher test
// @match        *://*/*
// @exclude      https://jsfiddle.net/*
// @exclude      https://lens.google.com/upload?*
// @run-at       document-start
// @grant        none
// @noframes
// @version      1.0
// @description  2023/12/25
// ==/UserScript==

function Generic_G_app_launcher_html() {

    window.addEventListener('load', () => {
        document.querySelector("body")
            .insertAdjacentHTML('afterbegin', `
<body>
    <!-- ↓ G_APP_Launcher switch-button ↓ -->
    <input id="G_app_launcher-checkbox" type="checkbox">
    <label id="G_app_launcher-icon" for="G_app_launcher-checkbox"><span>
            <svg id="G_App_Launcher_svg-icon" xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="-5.2 -5 26 26">
                <path fill="#EA4335" d="M2 0c1.1 0 2 .9 2 2s-.9 2-2 2-2-.9-2-2 .9-2 2-2zm12 0c1.1 0 2 .9 2 2s-.9 2-2 2-2-.9-2-2 .9-2 2-2zM8 0c1.1 0 2 .9 2 2s-.9 2-2 2-2-.9-2-2 .9-2 2-2z" />
                <path fill="#4285F4" d="M14 12c1.1 0 2 .9 2 2s-.9 2-2 2-2-.9-2-2 .9-2 2-2zM8 6c1.1 0 2 .9 2 2s-.9 2-2 2-2-.9-2-2 .9-2 2-2zm6 0c1.1 0 2 .9 2 2s-.9 2-2 2-2-.9-2-2 .9-2 2-2z" />
                <path fill="#34A853" d="M8 12c1.1 0 2 .9 2 2s-.9 2-2 2-2-.9-2-2 .9-2 2-2zm-6 0c1.1 0 2 .9 2 2s-.9 2-2 2-2-.9-2-2 .9-2 2-2z" />
                <path fill="#FBBC05" d="M2 10c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2z" />
            </svg>
        </span></label>
    <label id="G_app_launcher-close" for="G_app_launcher-checkbox"></label>


    <div id="G_app_launcher-content" style="user-select: none;">
        <!-- ↓ G_APP_Launcher-Drawer Menu ↓ -->

        <!-- Gmail short link -->
        <a id="my_G_app_Gmail_link_area" href="https://mail.google.com/mail/" target="_blank" style="text-decoration:none;">
            <div id="G_app_Gmail_area-content" onclick="G_APP_Launcher_Drawer_close_img()">
                <svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 4 48 48" style="fill:#26e07f;">
                    <path fill="#4caf50" d="M45,16.2l-5,2.75l-5,4.75L35,40h7c1.657,0,3-1.343,3-3V16.2z" />
                    <path fill="#1e88e5" d="M3,16.2l3.614,1.71L13,23.7V40H6c-1.657,0-3-1.343-3-3V16.2z" />
                    <polygon fill="#e53935" points="35,11.2 24,19.45 13,11.2 12,17 13,23.7 24,31.95 35,23.7 36,17" />
                    <path fill="#c62828" d="M3,12.298V16.2l10,7.5V11.2L9.876,8.859C9.132,8.301,8.228,8,7.298,8h0C4.924,8,3,9.924,3,12.298z" />
                    <path fill="#fbc02d" d="M45,12.298V16.2l-10,7.5V11.2l3.124-2.341C38.868,8.301,39.772,8,40.702,8h0 C43.076,8,45,9.924,45,12.298z" />
                </svg>
                <span id="G_app_Gmail_area-content_span"></span>
            </div>
        </a>

        <!-- omission -->

    </div>

</body>

 `);

    });

};
Generic_G_app_launcher_html();



//---------------------- G_APP_Launcher-Drawer opening/closing process ----------------------//
// Close the Drawer by pressing the logo mark <svg>
setTimeout(() => {
    function G_APP_Launcher_Drawer_close_img(g_inp) {
        document.getElementById('G_app_launcher-close')
            .click();
    };
    let _doc = document;
    _doc.getElementById('G_app_Gmail_area-content').addEventListener("click", G_APP_Launcher_Drawer_close_img, false);
}, 1000);


/* ---------- G App Launcher Switch Appearance & G-App Launcher Drawer Contents ---------- */
window.addEventListener('load', () => {
    const CSS = document.head.appendChild(document.createElement("style"));
    CSS.innerHTML = `

#G_app_launcher-checkbox {
 display: none !important;
 top: 50px;
 left: -5.5px;
 height: 0px;
 width: 0px;
}
#G_app_launcher-icon::before,
#G_app_launcher-icon::after{
 display: none !important;
 margin:0;
}

#G_app_launcher-icon{
 position:fixed;
 top:max(50px, 7.5%);
 left: 2.5px;
 height: 23px;
 min-height:1.6vw;
 width: 23px;
 min-width:1.6vw;
 z-index:100000010;
 cursor: pointer;
}

#G_app_launcher-icon svg{
 display:block;
 position:fixed;
 top:max(50px, 7.5%);
 left: 2.8px;
 height: 23px !important;
 min-height:1.6vw !important;
 width: 23px !important;
 min-width:1.6vw;
 border-radius: 50% !important;
 background:#f4f4f4;
 box-shadow: 1px 1px #777777, 1px 1px #777777, 1px 1px #777777, 1px 1px #777777, 1.5px 1.5px #777777;
 user-select: none !important;
 z-index:100000010;
}

#G_app_launcher-icon > span{
 display: inline-block;
 height: 0px;
 width: 0px;
}

#G_app_launcher-checkbox:checked ~ #G_app_launcher-icon span {
 background: rgba(51, 51, 51, 0);
}

#G_app_launcher-checkbox:checked ~ #G_app_launcher-icon span::before,
#G_app_launcher-checkbox:checked ~ #G_app_launcher-icon span::after {
 content: "";
 display: block;
 height: 0%;
 left: 0%;
 margin: -8% 0 0 -42%;
 position: absolute;
 top: 50%;
 width: 100%;
}

#G_app_launcher-checkbox:checked ~ #G_app_launcher-icon span::before {
 -webkit-transform: rotate(-45deg);
 transform: rotate(-45deg);
}

#G_app_launcher-checkbox:checked ~ #G_app_launcher-icon span::after {
 -webkit-transform: rotate(45deg);
 transform: rotate(45deg);
}

/* The entire real content area of G_app_launcher */
#G_app_launcher-content {
 overflow: auto;
 position: fixed !important;
 display:block !important;
 top: 0;
 left: 0;
 z-index:999999999;
 width: 18%;
 height: 65%;
 background: #fff;
 transition: all 0.3s ease-in-out 0s;
 transform: translateX(-100%);
 border-radius: 3% !important;
}


#G_app_launcher-checkbox:checked ~ #G_app_launcher-content {
 transform: translateX(0);
 box-shadow: 6px 0 25px rgba(0, 0, 0, 0.16);
}

#G_app_launcher-close {
 display: none !important;
 position: fixed !important;
 z-index:999999999;
 top: 0;
 left: 0;
 width: 100%;
 height: 100%;
 background: #000;
 opacity: 0;
 transition: all 0.3s ease-in-out 0s;
}

#G_app_launcher-checkbox:checked ~ #G_app_launcher-close {
 display: block !important;
 opacity: 0.3;
}


/*--------------- Location and appearance of each app in G App Launcher ---------------*/

/* Gmail short link */
#G_app_Gmail_area-content:hover{
 background:#EEEEEE !important;
}
#G_app_Gmail_area-content{
 position: absolute;
 top: 1%;
 left: 1.5%;
 height: 9vh;
 width: 4.5vw;
 border-radius:0.8vw;
}
#G_app_Gmail_area-content_span::after{
 content: "G mail";
 position: absolute;
 display: inline-block;
 display: flex;
 top: 70%;
 width: 4.5vw;
 justify-content: center !important;
 font-size: 1.1vw !important;
 color:black !important;
 line-height:1.2vw !important;
 letter-spacing:0 !important;
}
#G_app_Gmail_area-content > svg{
 position: absolute;
 text-align: center;
 top:0.2vw;
 left:0.45vw;;
 height:3.8vw !important;
 width: 3.6vw !important;
 opacity: 1 !important;
}

/* omission */

`;

});

for instagram reels views tracking

I need a special airtable set up.

I want to build an overview about my Instagram Accounts. I have plenty of Instagram Accounts which are posting Reels everyday. I have female clients who are producing reels everyday and my team is posting them (3 reels a day on each account).
And this airtable set up needs to track these accounts. So I need an overview about all my accounts. Right now I have 50 accounts but I will constantly add new accounts. So next week I will have like 60 accounts. So it needs to be possible that I can add accounts easily.
Besides it is not an option if I need to login into each account as this can affect the algorithm badly. So I only need to share the username of the account that needs to be tracked and not the login data.
This airtabel setup should also be fully automated. So the data tracking shouldn’t be done by my team, it should be done by the setup.

I heard that it is possible to use apify.com to track the data of each account or to write a script which is scraping the accounts to get the data. Or do you have any other solutions for it?

i tried but not fetch views on reels.the hardest part is to track views.i want reels views quantities

Globalized component has new focus but when closes does not return to original focus [angular]

I have a dialog component that has the posibily to be invoked on every page. The think it is that has a button that needs to be focused, but when closes the dialog I lose the original focus from the page he appeared.

How dialog component works

As can see the image this is the representation of what is happening.

Dialog.component.html:

<div *ngIf="isVisible">
  <div class="dialog">
    <div class="msgContainer" *ngIf="message" style="color: black;">Message
    </div>
    <ng-container">
      <button #closeDlg class="btnAccept" (click)="closesDlg()" appAutofocus>Close</button>
    </ng-container>
  </div>
</div>

The logic of the component:

export class DialogComponent implements OnDestroy{

isVisible! = boolean;

private _keySubscription!: Subscription;
  private actionSubscription: Subscription;

constructor(
    private keysService: KeysService,
    private actionService: ActionService,
    private router: Router,
    private renderer2: Renderer2,
    private activatedRoute: ActivatedRoute
  ){
  isVisible = true;
  this.closeDialog();
}

closeDialog(): void{

  setTimeOut(() => {
   this.isVisible = false;
  });
}

private initKeyControl(): void {
    this._keySubscription = new Subscription();
    this.keysService.forwardKeysExceptMedia();
    this._keySubscription = this.keysService
      .getKeyEventListener(VK_ENTER)
      .pipe(
        take(1),
        switchMap(() => {
          console.log('Has been clicked');
          this.cerrarDialogoYConfirmar();
          return of(null);
        })
      )
      .subscribe();
  }

ngOnDestroy(): void {

    this.actionSubscription.unsubscribe();
    this._keySubscription.unsubscribe();
    this.renderer2.destroy();
  }

}

Is there something that returns to me where it was his original focus? I was thinking that I can force the reloading of that page but It will not be the best performance for the app

404 error when uploading image (express, mongodb, multer)

exports.postAddProduct = (req, res, next) => {
  const title = req.body.title;
  const image = req.file
  const price = req.body.price;
  const description = req.body.description;
  if (!image) {
    return res.status(422).render('admin/edit-product', {
      pageTitle: 'Add Product',
      path: '/admin/add-product',
      editing: false,
      hasError: true,
      product: {
        title: title,
        price: price,
        description: description
      },
      errorMessage: 'Attached file is not an image.',
      validationErrors: []
    });
  }
  const errors = validationResult(req);

  if (!errors.isEmpty()) {
    console.log(errors.array());
    return res.status(422).render('admin/edit-product', {
      pageTitle: 'Add Product',
      path: '/admin/add-product',
      editing: false,
      hasError: true,
      product: {
        title: title,
        imageUrl: imageUrl,
        price: price,
        description: description
      },
      errorMessage: errors.array()[0].msg,
      validationErrors: errors.array()
    });
  }

  const imageUrl = image.path;
  

  const product = new Product({
    // _id: new mongoose.Types.ObjectId('5badf72403fd8b5be0366e81'),
    title: title,
    price: price,
    description: description,
    imageUrl: imageUrl,
    userId: req.user
  });
  product
    .save()
    .then(result => {
      // console.log(result);
      console.log('Created Product');
      res.redirect('/admin/products');
    })
    .catch(err => {
      // return res.status(500).render('admin/edit-product', {
      //   pageTitle: 'Add Product',
      //   path: '/admin/add-product',
      //   editing: false,
      //   hasError: true,
      //   product: {
      //     title: title,
      //     imageUrl: imageUrl,
      //     price: price,
      //     description: description
      //   },
      //   errorMessage: 'Database operation failed, please try again.',
      //   validationErrors: []
      // });
      // res.redirect('/500');
      const error = new Error(err);
      error.httpStatusCode = 500;
      console.log(imageUrl)
      return next(error);
    });
};`

also, app.js code:

const multer = require('multer')
const fileStorage = multer.diskStorage({
    destination: (req,file, cb)=>{
        cb(null, 'images' )
    },

    //first argument of cb - error
    filename: (req,file,cb)=>{
        cb(null, new Date().toISOString()+ '-'+ file.originalname)
    }
})
const fileFilter = (req,file,cb)=>{
    if(file.mimetype === 'image/png' || file.mimetype === 'image/jpg' || file.mimetype=== 'image/jpeg'){

        cb(null, true)
    }
    cb(null, false)
}

app.set('view engine', 'ejs');
app.set('views', 'views');

const adminRoutes = require('./routes/admin');
const authRoutes = require('./routes/auth');
const shopRoutes = require('./routes/shop');



const errorController = require('./controllers/error');

const User = require('./models/user')

app.use(bodyParser.urlencoded({extended: false}));
app.use(multer({storage: fileStorage, fileFilter: fileFilter }).single('image'))


I have a function, which sends product data to mongodb. It worked well when I had just image url instead of file upload. However, after incorporating file upload logic, it encountered issues, leading to redirection to a 500 error page. I’m seeking guidance on resolving this matter and ensuring the smooth integration of file uploads, preserving the functionality of the function while preventing redirection errors to the error page. How can I rectify this situation and maintain the desired functionality?

Connecting AWS Lambda to Local DynamoDB using AWS SAM and AWS CLI

I’m currently working on setting up a local development environment where I’m attempting to establish a connection between an AWS Lambda function and a locally running DynamoDB instance using AWS SAM and the AWS CLI. When I execute the following command, it correctly displays the mock data in my local DynamoDB instance:

aws dynamodb list-tables --endpoint-url http://localhost:8000

outputs:

{
  "TableNames": [
    "Users"
  ]
}

My local DynamoDB instance is running smoothly, and I’ve confirmed that it’s listening on port 8000 using commands such as lsof -i tcp:8000 and ps aux | grep dynamodb.

However, I’ve run into an issue when trying to connect to the local database from my locally running AWS Lambda function. Here’s the error message I’m encountering in the Lambda function:

2024-01-19T12:07:56.525Z    48624b94-7f68-45b9-a9fc-4f6d163b82c1    ERROR   Error connecting to DynamoDB Local: Error: connect ECONNREFUSED 127.0.0.1:8000
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 8000,
  '$metadata': { attempts: 3, totalRetryDelay: 69 }
}

I’ve also included a minimal code example that still reproduces the error:

import { DynamoDBClient, ListTablesCommand } from "@aws-sdk/client-dynamodb";

const DB_CLIENT = new DynamoDBClient({
  region: "us-east-2",
  endpoint: "http://localhost:8000",
  accessKeyId: "fakeMyKeyId",
  secretAccessKey: "fakeSecretAccessKey"
});

const foo = async () => {
  try {
    // The error is caused on this line, meaning the console.log is not being printed.
    const result = await DB_CLIENT.send(new ListTablesCommand());
    console.log("Tables:", result);
  } catch (error) {
    console.error("Error connecting to DynamoDB Local:", error);
    throw error;
  }
}

I’ve attempted various solutions such as restarting the local DynamoDB instance, changing ports, and using 127.0.0.1:8000 instead of localhost:8000, but nothing seems to work. Unfortunately, there isn’t much documentation available to help identify the root cause of this issue.

I also experimented with wrapping the credentials in a credentials object as shown below, but it didn’t resolve the problem:

const DB_CLIENT = new DynamoDBClient({
  region: "us-east-2",
  endpoint: "http://localhost:8000",
  credentials: {
    accessKeyId: "fakeMyKeyId",
    secretAccessKey: "fakeSecretAccessKey"
  }
});

I’d appreciate any guidance or insights on what values are required to establish this connection successfully. Thank you for your assistance.