Call multiple button clicks using JQuery, is that even possible?

This is my first question ever on StackOverFlow…
Hope it’s not silly…
Thanks in advance for your help!!

I want to click multiple buttons on the click of one button using JQuery
Example:
Button-1 calls -> Button-2 AND Button-3

The user should click Button-1 and it should click Button-2 and Button-3.
It should also fire its related Server side click events.

Following is what I tried, but it fires only the btnOne Server event click and not the other two.

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"     Inherits="PostBackApp.apppages.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="https://code.jquery.com/jquery-3.6.0.slim.min.js"            integrity="sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI="
        crossorigin="anonymous"></script>
    <title></title>
    <script type="text/javascript">
        $(function () {
            $('#btnOne').click(function myfunction() {
                one();
                $('#btnTwo').click();
                $('#btnThree').click();
            });
            $('#btnTwo').click(function myfunction() {
                two();
            });
            $('#btnThree').click(function myfunction() {
                three();
            });
        });
        function one() {
            alert('Client Side One was called');
        }
        function two() {
            alert('Client Side Two was called');
        }
        function three() {
            alert('Client Side Three was called');
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Button ID="btnOne" Text="1" runat="server" OnClick="btnOne_Click">        </asp:Button>
        <asp:Button ID="btnTwo" Text="2" runat="server" OnClick="btnTwo_Click"></asp:Button>
            <input type="button" name="btnThree" id="btnThree" value="3" />

            </div>
        </form>
    </body>
</html>

Default.aspx.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace PostBackApp.apppages

{
    
    public partial class Default : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            bool isPostbck = this.IsPostBack;

        }

        protected void btnOne_Click(object sender, EventArgs e)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "Key1", "alert('Server Side One was called');", true);
        }

        protected void btnTwo_Click(object sender, EventArgs e)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "Key2", "alert('Server Side Two was called');", true);
        }
    }
}

Router with React Chrome extension

I’m developing a Chrome extension with React but I can’t get rid of this bug:

No routes matched location "/popup.html", it cause the app simply to not start.

I used this template to create the app and my App.js looks like this:

import { BrowserRouter as Router, Route, Routes } from "react-router-dom"
import PrivateRoute from "./components/PrivateRoute"

function App() {
  return (
    <Router>
      <AuthProvider>
        <Routes>
          <Route exact path="/dashboard" element={<PrivateRoute> <Dashboard /> </PrivateRoute> } />
          <Route path="/signup" component={Signup} />
          <Route path="/login" component={Login} />
          <Route path="/forgot-password" component={ForgotPassword} />
          <Route exact path="/update-profile" element={<PrivateRoute> <UpdateProfile /> </PrivateRoute> } />
        </Routes>
      </AuthProvider>
    </Router>
  )
}

export default App;

Before using routes, having just return (<Signup/>) worked but not everything is broken.
Thank you for any kind of help

How to show/hide an input based on the selected item in another drop down list in .net core 2.1 MVC

I have this drop down list:

<div class="form-group" id="businessEntitiesIdsLegal">
    <label asp-for="BusinessEntityTypeId" class="control-label col-sm-4 col-lg-3" asp-show-required-charachter="true">Some label</label>
    <div class="col-sm-5 col-md-4 col-lg-3">
        <select asp-for="BusinessEntityTypeId" id="BusinessEntityTypeId" asp-items="Model.BusinessEntities" class="select2 select-block-level search">
            <option value="@BaseViewModel.NotSelected">Choose something</option>
        </select>
        <span asp-validation-for="BusinessEntityTypeId" class="text-danger"></span>
    </div>
</div>

and I would like to handle if its selected item with value=2 then to show this div (and also if item get changed, to hide the div):

@if(Model.BuyerTypeId == BuyerTypeEnum.Legal.Id)
{
    <div class="form-group" id="foobar">
        <label asp-for="Jbkjs" class="control-label col-sm-4 col-lg-3"></label>
        <div class="col-sm-5">
            <input asp-for="Jbkjs" type="text" class="form-control" maxlength="5">
            <span asp-validation-for="Jbkjs" class="text-danger"></span>
        </div>
    </div>
}

How can I achieve this?

How to re-render and run useEffect when router change (React js)

I have a ChartPage function that gets called three times inside three different routers, inside that ChartPage function I am using “useEffect” that updates some variables according to the chosen route. But for some reason its only triggered once, and when I am going to a different route that using the same ChartPage function the “useEffect” does not get triggerd again and even when the routes are changing the data is still the same from the first route that got triggered.
Can someone help fix that issue, I tried to solve this for hours

basically I want to trigger “useEffect whenever I click one of the buttons”

app.js:

import React from "react";
import Navbar from "./components/Navbar";
import "./App.css";
import Home from "./components/pages/Home";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import ShowStocks from "./components/pages/ShowStocks";
import ChartPage from "./components/pages/ChartPage";

function App() {
  return (
    <>
      <Router>
        <Navbar />
        <Routes>
          <Route path="/" exact element={<Home />} />
          <Route path="/show-stocks" element={<ShowStocks />} />
          <Route
            path="show-stocks/bitcoin"
            element={<ChartPage type={"BTC"} />}
          />
          <Route
            path="show-stocks/ethereum"
            element={<ChartPage type={"ETH"} />}
          />
          <Route
            path="show-stocks/cardano"
            element={<ChartPage type={"ADA"} />}
          />
        </Routes>
      </Router>
    </>
  );
}

export default App;

as you can see I am using ChartPage in three different routes but not with the same data
ChartPage.js:

import React, { Component, useState, useEffect } from "react";
import "../../App.css";
import Chart from "../Chart";
import { Button } from "../Button.js";
import "./ChartPage.css";
import axios from "axios";

function getCoin(type) {
  console.log("requesting");
  var path = `/show-stocks/${type}`;
  return axios.get(path).then((response) => {
    return response.data;
  });
}

export default function ChartPage({ type }) {
  const [values, setValues] = useState(null);
  // type is changing correctly and the function did get called with a different type
  // but useEffect doesn't run on the second time
  // so getCoin does not get triggerd and the data stays the same 
  useEffect(() => {
    getCoin(type)
      .then((response) => {
        setValues(response);
      })
      .catch((error) => {
        console.log(error);
      });
  }, []);

  return (
    <>
      <div className="chart-page-container">
        <h1>{type} Price Market Value</h1>
        <div className="chart-container">
          {null !== values ? (
            <Chart data={[values, type]} />
          ) : (
            <p>Loading...</p>
          )}
        </div>
        <div className="chart-page-btns">
          <Button
            link="/show-stocks/bitcoin"
            className="btns"
            buttonStyle="btn--outline2"
            buttonSize="btn--large2"
          >
            Bitcoin
          </Button>
          <Button
            link="/show-stocks/ethereum"
            className="btns"
            buttonStyle="btn--outline2"
            buttonSize="btn--large2"
          >
            Ethereum
          </Button>
          <Button
            link="/show-stocks/cardano"
            className="btns"
            buttonStyle="btn--outline2"
            buttonSize="btn--large2"
          >
            Cardano
          </Button>
        </div>
      </div>
    </>
  );
}

as you can see the buttons changing the routes and type do update according to the parameter that the routes sended, but the useEffect does not called again.

How to use your own REACT button with google’s Sign in with google library CDN

Google currently is discontiuing their old “sign in with google” and I am now using their new stuff which I followed by this guide on their documentation https://developers.google.com/identity/gsi/web/reference/js-reference

so in order to render their button you need to do this

import their cdn in public index.html

<script src="https://accounts.google.com/gsi/client"></script>

Then you should call it like this with React

  useEffect(() => {
  google.accounts.id.initialize({
      client_id: 'YOUR_GOOGLE_CLIENT_ID',
      callback: handleCredentialResponse
    });
   google.accounts.id.renderButton(document.getElementById('google-login-button'), {
      theme: 'outline',
      size: 'large',
    });
  }, []);

and then render the button out on a div like so

  <div id="google-login-button" className="customGPlusSignIn" />

then it displays this button

enter image description here

so if you want to make change to it you need to style it with this

   google.accounts.id.renderButton(document.getElementById('google-login-button'), {
      theme: 'outline',
      size: 'large',
    });

BUT here comes the annoying part – it jumps from the above PRE styled button to
enter image description here

(in this picture its bigger than the actual one, the actual one is WAAAY smaller than the first one it switches from)

And you can stand on your head with CSS and pull out all the tricks under the hood to make it stay the same size but it doesn’t. IT ALWAYS STICKS TO THIS STYLING.

I really want to use my own button and I cant find a way to set the google.accounts.id.initialize({ to work with my own button.

do any of you have any idea how I can achieve WITHOUT USING A NPM package and staying vanilla google CDN (Reason why I DONT want to use an NPM package is because the NPM packages out there are using the OLD sign in with google api calls and its going to get depreciated next year March 30th (March 30th 2023)

Access to fetch at ‘https://open-api.trovo.live/openplatform/channels/id’ from origin ‘http://localhost:3000

I am having a problem with fetching profile data from Trovo API.

Access to fetch at
‘https://open-api.trovo.live/openplatform/channels/id’ from origin
‘http://localhost:3000’ has been blocked by CORS policy: Request
header field access-control-allow-origin is not allowed by
Access-Control-Allow-Headers in preflight response.

In the documentation of the API says:

If you are making API calls from the client side, you may come across
CORS issues. Your domain needs to be whitelisted in Trovo in order to
do CORS calls.

In addition, please add origin in the header when you are making
cross-site calls.

I am getting this error on production too, where I am using my registered domain.

const fetchProfile = async () => {
    const ress = await fetch(
      "https://open-api.trovo.live/openplatform/channels/id",
      {
        method: "POST",
        headers: {
          Accept: "application/json",
          "Client-ID": `${process.env.TROVO_CLIENT_ID}`,
          "Content-Type": "application/x-www-form-urlencoded",
        },
        body: '{"username":"test"}',
      }
    ).then((res) => res.json());

Webpack (or babel) appears to be replacing all instances of NodeJS Streams with standard ReadableStreams

So, I’m in the process of doing a long overdue update on a Node-based project, bundled with webpack and babel. In the process of updating webpack beyond v4, I’ve set up some of the polyfills I need by adding a resolve.fallback section to the config in my webpack.config.js:

    resolve: {
      extensions: [".ts", ".tsx", ".html", ".js"],
      fallback: {
        buffer: require.resolve("buffer"),
        crypto: require.resolve("crypto-browserify"),
        stream: require.resolve("stream-browserify"),
      },
    },

However, something (I suspect these polyfills, but I’m not sure) is now causing all instances of NodeJS Streams in my project to wind up being standard ReadableStreams, including the body of a response from an explicitly-imported node-fetch:

import {default as nodefetch} from 'node-fetch'
[...]
  const response = await nodefetch(endpointURI, {
    method: "POST",
    headers: {
      Authorization: authToken,
      Origin: window.location.host,
    },
    body: JSON.stringify(data),
  });
  return response.body;  // Attempting to call `response.body.pipe()` here 
                         // will result in a "not a function" error. In a debugger,
                         // response.body appears to be a standard (Non-Node) ReadableStream.

So, not sure why this is happening but I’d love to find out! Relevant versions:

node: v16.15.1
[email protected]
[email protected]
[email protected]
[email protected]
@babel/[email protected]
@babel/[email protected]
@babel/[email protected]
@babel/[email protected]
@babel/[email protected]

What are the rissks and how to mitigate them when allowing javascript callbacks

I would like to know the risks and possible attack types when using a library (for instance using a UI library for a component) where callbacks can be passed since we cannot control the content of the callback function passed.
Based on those attack types what can we do in order to prevent/mitigate malicious code to run on callbacks passed to those handlers?
I read several articles about this topic but since I lack experience on this I would really like to have your insights.
Thank you in advance

Material Ui TablePagination isnt working with ny array of objects

my TablePagination isnt changing the rows at each page of my table and not even limitating the rows with the row filter. Actually Im thinking that can be beacause im building the table with a mapping of an array like that:

    0:[name : Robert, age: 15, sons:{ 0:{ name: RobertSon, age 28} 1:{ name: RobertDaugther, 
    age:14}]
1:[name : Robert, age: 15, sons:{ 0:{ name: RobertSon, age 28} 1:{ name: RobertDaugther, 
    age:14}]
2:[name : Robert, age: 15, sons:{ 0:{ name: RobertSon, age 28} 1:{ name: RobertDaugther, 
    age:14}]

and here is my code actually

<TableContainer style={{ padding: 0 }}>
      <TableToolbar
        // onUserAdd={setOpenUserDialog}
        filterOptions={filterOptions}
        setFilterOptions={setFilterOptions}
        searchTerm={searchTerm}
        setSearchTerm={setSearchTerm}
        // selected={selected}
        // setSelected={setSelected}
      />
      <Table className={classes.table} aria-label="customized table">
        <TableHead>
          <TableRow>
            <StyledTableCell />
            <StyledTableCell align="center"> RECEBIDAS ÚTEIS</StyledTableCell>
            <StyledTableCell colSpan={2} align="center">
              {' '}
              ATENDIDAS
            </StyledTableCell>
            <StyledTableCell colSpan={2} align="center">
              {' '}
              ABANDONADAS ÚTEIS
            </StyledTableCell>
            <StyledTableCell colSpan={2} align="center">
              {' '}
              ABANDONADAS ÚNICAS
            </StyledTableCell>
            <StyledTableCell colSpan={2} align="center">
              {' '}
              AUTO RECUPERADAS
            </StyledTableCell>
            <StyledTableCell colSpan={2} align="center">
              {' '}
              RECUPERADAS
            </StyledTableCell>
            <StyledTableCell colSpan={2} align="center">
              {' '}
              SEM ATENDIMENTO
            </StyledTableCell>
          </TableRow>
          <TableRow>
            <StyledTableCell align="center">NOME</StyledTableCell>
            <StyledTableCell align="center">QTDE</StyledTableCell>
            <StyledTableCell align="center">QTDE</StyledTableCell>
            <StyledTableCell align="center">%</StyledTableCell>
            <StyledTableCell align="center">QTDE</StyledTableCell>
            <StyledTableCell align="center">%</StyledTableCell>
            <StyledTableCell align="center">QTDE</StyledTableCell>
            <StyledTableCell align="center">%</StyledTableCell>
            <StyledTableCell align="center">QTDE</StyledTableCell>
            <StyledTableCell align="center">%</StyledTableCell>
            <StyledTableCell align="center">QTDE</StyledTableCell>
            <StyledTableCell align="center">%</StyledTableCell>
            <StyledTableCell align="center">QTDE</StyledTableCell>
            <StyledTableCell align="center">%</StyledTableCell>
          </TableRow>
        </TableHead>
        {rows !== undefined
          ? rows.map(rows => (
              <>
                <TableBody>
                  <StyledTableRow key={rows.label}>
                    <StyledTableCell component="th" scope="row">
                      <b>{rows.label}</b>
                    </StyledTableCell>
                    <StyledTableCell align="center">
                      <b>{rows.ligacoesRecebidasUtil}</b>
                    </StyledTableCell>
                    <StyledTableCell align="center">
                      <b>{rows.ligacoesAtendidas}</b>
                    </StyledTableCell>
                    <StyledTableCell align="center">
                      <b>{rows.percentualAtendidas}%</b>
                    </StyledTableCell>
                    <StyledTableCell align="center">
                      <b>{rows.ligacoesAbandonadasUtil}</b>
                    </StyledTableCell>
                    <StyledTableCell align="center">
                      <b>{rows.percentualAbandonadasUtil}%</b>
                    </StyledTableCell>
                    <StyledTableCell align="center">
                      <b>{rows.ligacoesAbandonadas}</b>
                    </StyledTableCell>
                    <StyledTableCell align="center">
                      <b>{rows.percentualAbandonadas}%</b>
                    </StyledTableCell>
                    <StyledTableCell align="center">
                      <b>{rows.ligacoesAtendidas}</b>
                    </StyledTableCell>
                    <StyledTableCell align="center">
                      <b>{rows.percentualAtendidas}%</b>
                    </StyledTableCell>
                    <StyledTableCell align="center">
                      <b>{rows.ligacoesAutoRecuperadas}</b>
                    </StyledTableCell>
                    <StyledTableCell align="center">
                      <b>{rows.percentualAutoRecuperadas}%</b>
                    </StyledTableCell>
                    <StyledTableCell align="center">
                      <b>{rows.ligacoesRecuperadas}</b>
                    </StyledTableCell>
                    <StyledTableCell align="center">
                      <b>{rows.percentualRecuperadas}%</b>
                    </StyledTableCell>
                  </StyledTableRow>
                </TableBody>
                <TableBody>
                  {!VBU && rows.filas !== undefined
                    ? rows.filas.map(rows => (
                        <StyledTableRow className={classes.sonRow} key={rows.label}>
                          <StyledTableCell
                            style={{ paddingLeft: '2vw' }}
                            component="th"
                            scope="row"
                          >
                            {rows.label}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {rows.ligacoesRecebidasUtil}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {rows.ligacoesAtendidas}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {rows.percentualAtendidas}%
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {rows.ligacoesAbandonadasUtil}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {rows.percentualAbandonadasUtil}%
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {rows.ligacoesAbandonadas}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {rows.percentualAbandonadas}%
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {rows.ligacoesAtendidas}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {rows.percentualAtendidas}%
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {rows.ligacoesAutoRecuperadas}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {rows.percentualAutoRecuperadas}%
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {rows.ligacoesRecuperadas}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {rows.percentualRecuperadas}%
                          </StyledTableCell>
                        </StyledTableRow>
                      ))
                    : VBU && operacao && rows.hosts !== undefined
                    ? rows.hosts.map(row => (
                        <StyledTableRow className={classes.sonRow} key={row.label}>
                          <StyledTableCell
                            style={{ paddingLeft: '2vw' }}
                            component="th"
                            scope="row"
                          >
                            {row.label}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.ligacoesRecebidasUtil}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.ligacoesAtendidas}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.percentualAtendidas}%
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.ligacoesAbandonadasUtil}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.percentualAbandonadasUtil}%
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.ligacoesAbandonadas}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.percentualAbandonadas}%
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.ligacoesAtendidas}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.percentualAtendidas}%
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.ligacoesAutoRecuperadas}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.percentualAutoRecuperadas}%
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.ligacoesRecuperadas}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.percentualRecuperadas}%
                          </StyledTableCell>
                        </StyledTableRow>
                      ))
                    : VBU && !operacao && rows.regionais !== undefined
                    ? rows.regionais.map(row => (
                        <StyledTableRow className={classes.sonRow} key={row.label}>
                          <StyledTableCell
                            style={{ paddingLeft: '2vw' }}
                            component="th"
                            scope="row"
                          >
                            {row.label}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.ligacoesRecebidasUtil}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.ligacoesAtendidas}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.percentualAtendidas}%
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.ligacoesAbandonadasUtil}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.percentualAbandonadasUtil}%
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.ligacoesAbandonadas}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.percentualAbandonadas}%
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.ligacoesAtendidas}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.percentualAtendidas}%
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.ligacoesAutoRecuperadas}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.percentualAutoRecuperadas}%
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.ligacoesRecuperadas}
                          </StyledTableCell>
                          <StyledTableCell align="center">
                            {row.percentualRecuperadas}%
                          </StyledTableCell>
                        </StyledTableRow>
                      ))
                    : null}
                </TableBody>
              </>
            ))
          : null}
        {/* <div
          style={{ display: 'flex', justifyContent: 'space-between', border: '0' }}
        > */}
        <IconButton onClick={() => handleOnExport()}>
          <GetApp />
        </IconButton>
        <TableFooter>
          <TableRow>
            <TablePagination
              rowsPerPageOptions={[5, 10, 25, { label: 'Todos', value: -1 }]}
              colSpan={3}
              count={lines}
              rowsPerPage={rowsPerPage}
              page={page}
              SelectProps={{
                inputProps: {
                  'aria-label': 'rows per page',
                },
                native: true,
              }}
              onPageChange={handleChangePage}
              onRowsPerPageChange={handleChangeRowsPerPage}
              ActionsComponent={TablePaginationActions}
            />
          </TableRow>
        </TableFooter>
      </Table>
      {/* </div> */}
    </TableContainer>

I even tried to mount all my items in one array without objects, but it doesnt work too, could someone tell me if im doing a bad use of mui’s tablepagination?

I have a component that is the parent of an array of element made up of text AND components. How to make the screen reader read out the components?

I have the following array:

const row = ['I agree to the', {}, 'and', {}];

Where the 2 objects are React components that make the text a link.

I then render this text like this:

<WrapperComponent>
    {row}
</WrapperComponent>

I get the following sentence rendered:

I agree to the Terms of Service and Privacy Policy

And if I turn on the screen reader, the whole sentence gets focused and read out.

My question is whether I can do something to make the screen reader read the whole sentence first, and then have the first link element Terms of Service focused if the user swipes right once, and Privacy Policy if he swipes right twice.

Activate iframe and change its contents

I am losing my marbles over this issue:

There’s an iframe that i try to programmatically manipulate, but somehow this is only possible after i go into the developer console and click a parent node.

This is the best i can come up with:

var iframes = document.getElementsByTagName('iframe');
for (var i = 0; i < iframes.length; i++) {
if (iframes[i].parentNode.id == 'cke_355_contents') {
iframes[i].contentWindow.document.open();
iframes[i].contentWindow.document.write('<html><body>Hello World</body></html>');
iframes[i].contentWindow.document.close();
 }
  }

Even if i try to list all iframes on the page:

document.querySelectorAll('iframe').forEach((iframe)=> {
  console.log(iframe.id, iframe.className, iframe.src)
});

i just get the first 2 results. But, when i click a parentnode in the console, it will only list the iframe i actually need.

Is there some way to find the correct iframe,”activate” it and manipulate it?

“ReferenceError: not defined” despite installing the package

I have a folder in which i have ran npm install chevrotain successfully. Running npm -v chevrotain gives 8.1.2 and I have "chevrotain": "^10.1.2" under my dependencies in my package.json but on running a simple js file in the same folder I get the error ReferenceError: chevrotain is not defined. The js file just has one line of code const createToken = chevrotain.createToken.

Any reasons why that could happen?

Why is the CrypoJS createHash sha256 result different than expected?

I’m using the crypto.js library to hash a string (“hello12345”), but the output doesn’t match that of an online sha256 tester.

Here’s my code:

const crypto = require("crypto");
let test = crypto.createHash("sha256").update("hello12345").digest("hex");
let expectedOutput = "89a7e6eabbc4c9477277ec9b246c6417dc352e69418bf3ef4d75e9c19bbbedd6";
// actual output = "5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5";

If I don’t use “hex” in .digest(“hex”) I get some this formatting:

<Buffer 89 a7 e6 ea bb c4 c9 47 72 77 ec 9b 24 6c 64 17 dc 35 2e 69 41 8b f3 ef 4d 75 e9 c1 9b bb ed d6>

I’ll eventually need to use createHmac to combine a string with a salt, but I can’t even get the hardcoded “hello12345” values to match.

What am I missing here?

How do I know what should be added as a provider or import in my Jasmine Unit Test

I’m new to unit tests and I haven’t been able to find a clear and concise explanation of what gets added as a provider vs import in my spec.ts. I keep getting the same error no matter what I try.

Here’s my service class:

import { Injectable } from '@angular/core';
import { Auth, createUserWithEmailAndPassword, signInWithEmailAndPassword, UserCredential } from '@angular/fire/auth';
import { FormGroup } from '@angular/forms';
import { Router } from '@angular/router';
import { signOut } from '@firebase/auth';
import { AlertController } from '@ionic/angular';
import { getFirestore, collection, addDoc } from 'firebase/firestore';
import { getApp } from 'firebase/app';
import { DocumentData, DocumentReference } from '@angular/fire/firestore';

@Injectable({
  providedIn: 'root'
})
export class AuthService {
  userCollection = collection(getFirestore(getApp()), 'users');

  constructor(private auth: Auth,
    private router: Router,
    private alertController: AlertController) { }

  async register(registrationForm: FormGroup): Promise<UserCredential> {
    return await createUserWithEmailAndPassword(this.auth, registrationForm.value.email, registrationForm.value.password);
  }

  async login(email: string, password: string): Promise<UserCredential> {
    return await signInWithEmailAndPassword(this.auth, email, password);
  }

  logout(): Promise<void> {
    return signOut(this.auth);
  }

  async authenticationAlert(message: any, header: string, route: string): Promise<void> {
    const alert = await this.alertController.create({
      subHeader: `${header}`,
      message: `${message}`,
      buttons: [
        {
          text: 'Ok',
          role: 'Ok',
          cssClass: 'secondary',
          handler: () => {
            this.router.navigateByUrl(`${route}`);
          }
        }
      ]
    });

    await alert.present();
  }

  saveProfile(uid: string, email: string, displayName: string): Promise<DocumentReference<DocumentData>> {
    return addDoc(this.userCollection, {uid, email, displayName});
  }
}

Here’s the spec:

import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';

import { AuthService } from './auth.service';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { getApp } from '@angular/fire/app';
import { signOut } from '@angular/fire/auth';
import { addDoc, collection, DocumentReference, getFirestore } from '@angular/fire/firestore';

describe('AuthService', () => {
  let service: AuthService;

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [ ReactiveFormsModule, FormsModule, RouterTestingModule,],
      providers: [AuthService]
    });
    service = TestBed.inject(AuthService);
  });

  it('should be created', () => {
    expect(service).toBeTruthy();
  });
});

And this is the error I keep getting:

AuthService > should be created
NullInjectorError: R3InjectorError(DynamicTestModule)[AuthService -> Auth -> Auth]: 
  NullInjectorError: No provider for Auth!
error properties: Object({ ngTempTokenPath: null, ngTokenPath: [ 'AuthService', 'Auth', 'Auth' ] })
NullInjectorError: R3InjectorError(DynamicTestModule)[AuthService -> Auth -> Auth]: 
  NullInjectorError: No provider for Auth!
    at NullInjector.get (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2020/core.mjs:9081:27)
    at R3Injector.get (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2020/core.mjs:9248:33)
    at R3Injector.get (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2020/core.mjs:9248:33)
    at injectInjectorOnly (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2020/core.mjs:4868:33)
    at ɵɵinject (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2020/core.mjs:4872:12)
    at Object.factory (ng:///AuthService/ɵfac.js:4:39)
    at R3Injector.hydrate (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2020/core.mjs:9343:35)
    at R3Injector.get (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2020/core.mjs:9237:33)
    at NgModuleRef.get (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2020/core.mjs:22399:33)
    at TestBedRender3.inject (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2020/testing.mjs:26537:52)
Expected undefined to be truthy.
Error: Expected undefined to be truthy.
    at <Jasmine>
    at UserContext.apply (http://localhost:9876/_karma_webpack_/webpack:/src/app/services/auth.service.spec.ts:22:21)
    at _ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:409:30)
    at ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone-testing.js:303:43)

Additionally, I’m getting this error in ever spec.ts on every component that imports the AuthService.

I’m not sure how to determine out of all of my imports which ones I’ll have to include in the spec file. And how do I determine if they get injected as a provider or import?

Find items and chech if it has the same id as in parent scope and if it has add isDisable to item

Hi everyone I need to get advice on how to realize such a function for searching and adding property if the children’s scope has the same ids as the parent scope and add isDisable key.

The data which I got and I need to transform it with new property isDisable

const data = [
  {
   id: "MT1",
   children: []
  },
  {
   id: "MT2",
   children: []
  },
  {
   id: "MT4",
   children: []
  },
  {
   id: "1234",
   children: [
    {
     id: "MT1",
     children: []
    },
    {
     id: "MT65",
     children: []
    },
   ]
  },
  {
   id: "537465",
   children: [{
     id: "MT1",
     children: []
    },
    {
     id: "MT2",
     children: [
      {
       id: "MT1",
       children: []
      },
      {
       id: "MT12",
       children: []
      }
     ]
    },
   ]
  }
]

This is some function for searching and adding a property to an item and result.

const someSearchFunction = (data) => {}

console.log(someSearchFunction(data))

const data = [
  {
   id: "MT1",
   children: [],
   isDisable: false
  },
  {
   id: "MT2",
   children: [],
   isDisable: false
  },
  {
   id: "MT4",
   children: [],
   isDisable: false
  },
  {
   id: "MT12",
   children: [],
   isDisable: false
  },
  {
   id: "1234",
   children: [
    {
     id: "MT1",
     children: [],
     isDisable: true
    },
    {
     id: "MT65",
     children: [],
     isDisable: false
    },
   ]
  },
  {
   id: "537465",
   children: [
    {
     id: "MT1",
     children: [],
     isDisable: true
    },
    {
     id: "42354322",
     children: [
      {
       id: "MT1",
       children: [],
       isDisable: true
      },
      {
       id: "MT12",
       children: []
       isDisable: false
      }
     ]
    },
   ]
  }
]

Thanks!