How can I attach an addEventListener to an input field using the submit event?

I am making a simple tip calculator and first of all I am trying to save the value of the bill amount which the user can type into the input field (this input field has a type number attribute). There aren’t any button to submit the value so I’d like to use the submit event for the addeventlistener instead of the click event. Inside the addeventlistener I am preventing the default behavior of the event and then I am trying the save the amount as a variable but the console is empty all the time.

Here is the HTML code:

<div class="form_bill">
    <h2>Bill</h2>
    <div class="input_icons">
      <i class="fa fa-usd icon"></i>
      <input type="number" class="form_input bill_input" placeholder="0"/>
    </div>
</div>

Here is my JS code:

const billInput = document.querySelector('.bill_input');

billInput.addEventListener('submit', function (e) {
    e.preventDefault();

    const billAmount = billInput.value;

    console.log(billAmount);
});

I tried to change the input tag to form tag, I tried to change the type number to type text, I tried the click event, no success. I’d like to save the input value as a variable so after that I could work with that value.

Unary relationship with LeaderLine

I am working on an application to graphically represent Java classes in Class Diagram form.

PlainDraggable and LeaderLine made this task much easier.

However, I tried to create a unary / recursive relationship with LeaderLine (red line in the figure). The latter doesn’t accept that an element to be start and end at the same time.

new LeaderLine(document.getElementById('OtherClass'), document.getElementById('OtherClass'));

I get the following error:

leader-line.min.js:2 Uncaught Error: start and end are required.
at it (leader-line.min.js:2:51907)
at ot.setOptions (leader-line.min.js:2:73051)
at new ot (leader-line.min.js:2:60892)
at mockup.html:212:16

Is there a technique or workaround to achieve this ?

enter image description here

Does the Next.js middleware compile after the application itself?

In the Next.js docs, we find:

Middleware will be invoked for every route in your project. Given
this, it’s crucial to use matchers to precisely target or exclude
specific routes. The following is the execution order:

  1. headers from next.config.js
  2. redirects from next.config.js
  3. Middleware (rewrites, redirects, etc.)
  4. beforeFiles (rewrites) from next.config.js
  5. Filesystem routes (public/, _next/static/, pages/, app/, etc.)
  6. afterFiles (rewrites) from next.config.js
  7. Dynamic Routes (/blog/[slug])
  8. fallback (rewrites) from next.config.js

However, when I compile a Next.js 14 app with middleware, it gives the following console.log output:

✓ Starting…

✓ Ready in 4.5s

○ Compiling / …

✓ Compiled / in 8s (2873 modules)

console.logs in Server Components are printed

GET / 200 in 9211ms

○ Compiling /src/middleware …

✓ Compiled /src/middleware in 548ms (228 modules)

console.logs in middleware.ts are printed

Looking at that log output, it seems the Server Component files are evaluated before the middleware.ts file. Is that correct, or am I somehow misinterpreting the logs?

If yes, would that not conflict with the docs excerpt above?

Dropzone js can’t cancel upload of file in “uploading” status

I was trying to make a button allows user to cancel upload of file anytime but after sometime I figured out that it’s working only when file is being cancelled in “sending” event not “uploadprogress”. This are my options to dropzone

this.myDropzone = new Dropzone("#fileList", {
        url: "/chunking",
        method: "post",
        paramName: "myFile",
        clickable: false,
        dictDefaultMessage: "",
        maxFilesize: maxFileSize,
        timeout: 0,
        chunking: true, 
        chunkSize: 2000000,
        parallelUploads: 1,
        parallelChunkUploads: true,
        forceChunking: true,
        autoQueue: false,
    });

I tried multiple solutions like: this.removeFile(file),this.removeAllFiles(true), this.cancelUpload(file), file.xhr.abort() (Everytime I was using this I made sure that none of these were null or undefined and of course this in this example is this.myDropzone). After that I emited manually event “cancelled” to file the status would change and it changed and event “cancelled” triggered but after this event executed “uploadprogress” still was executing itself and sending chunks to server. I didn’t try changing chunking off because it would take me some time to change server’s code and I didn’t see any post saying that chunks may have been an issue. Probably will try turning chunking off to see if it was it but at this point I have no idea what to do else. Also I didn’t try using addRemoveLinks.

Blazor Snowpack: Failed to resolve module specifier “lodash”. Relative references must start with either “/”, “./”, or “../”

I’m trying to use npm and snowpack in Blazor following this article
https://nbarraud.github.io/js-in-blazor.html

But when trying to import the bundle i get this error:

Microsoft.JSInterop.JSException: Failed to resolve module specifier "lodash". Relative references must start with either "/", "./", or "../".
TypeError: Failed to resolve module specifier "lodash". Relative references must start with either "/", "./", or "../".
   at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
   at BlazorApp2.Components.Pages.Home.OnAfterRenderAsync(Boolean firstRender) in C:UsersusersourcereposBlazorApp2BlazorApp2ComponentsPagesHome.razor:line 10
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

Smaller issue that can be solved by lowering the snowpack version to 3.0.13 for example is this one:

[@snowpack/plugin-optimize] Error: ENOENT: no such file or directory, open 'C:UsersusersourcereposBlazorApp2BlazorApp2wwwrootjs_snowpackoptimize-manifest.json'
1>C:UsersusersourcereposBlazorApp2BlazorApp2BlazorApp2.csproj(10,3): error MSB3073: The command "cd JS && npm run snowpack-build" exited with code 1.

Anyway you can find the repo here:
https://github.com/MefestoSerlo/blazor-snowpack-issue/tree/master

This code changing the image as expected but not the id?

const currentTypesResult=[{id:'155', foodId:'511555522559744444', image: 'Some image string', example:'example'}]

const processedResults = currentTypesResult.map((item) => {
   
const { foodId, image, ...rest } = item;

return {
id: '5542',
image: 'data:image/png;base64,',
...rest
};
});

console.log(processedResults[0].id) //prints 155 ????? whyyy?? why not '5542'
console.log(processedResults[0].image) //prints "data:image/png;base64,"(AS IT SHOULD)

I’m expecting id to change from ‘155’ to ‘5542’ when I print processedResults[0].id (it prints the old value ‘155’) ..
just like image was changed from ‘some image string’ to ‘data:image/png;base64,’ when I printed processedResults[0].image

Error when defining types for Context object

The below code is showing error
*"Expected 0 type arguments, but got 1"*

type TodosContextObj = {
  items: Todo[];
  addTodo: (text: string) => void;
  removeTodo: (id: string) => void;
};
 
export const TodosContext = createContext<TodosContextObj>({
  items: [],
  addTodo: (text: string) => {},
  removeTodo: (id: string) => {},
});

Here’s full file (todos-context.tsx)

import { createContext } from "vm";
import { useState } from "react";
import { FC } from "react";
import Todo from "../models/todo";
 
type TodosContextObj = {
  items: Todo[];
  addTodo: (text: string) => void;
  removeTodo: (id: string) => void;
};
 
export const TodosContext = createContext<TodosContextObj>({
  items: [],
  addTodo: (text: string) => {},
  removeTodo: (id: string) => {},
});
 
const TodosContextProvider: FC<{ children?: React.ReactNode }> = (props) => {
  const [todos, setTodos] = useState<Todo[]>([]);
 
  const addTodoHandler = (enteredText: string) => {
    const newTodo = new Todo(enteredText);
 
    setTodos((prevTodos) => prevTodos.concat(newTodo));
  };
 
  const removeTodoHandler = (todoId: string) => {
    console.log(todoId);
 
    setTodos((prevTodos) => prevTodos.filter((todo) => todo.id !== todoId));
  };
 
  console.log(todos);
 
  const contextValue: TodosContextObj = {
    items: todos,
    addTodo: addTodoHandler,
    removeTodo: removeTodoHandler,
  };
 
  return (
    <TodosContext.Provider value={contextValue}>
      {props.children}
    </TodosContext.Provider>
  );
};
export default TodosContextProvider;

Here i just want to set types for object (i.e. context) passed in createContext

The types for createContext & contextValue are same

Why isn’t forEach allowing me to access element properties?

Using a simple counter to iterate a collection works fine, but when I try to change it to use forEach it fails. Can someone point me in the right direction? Here’s the code (code in question is commented out…first one works, second one doesn’t)

function slideImage(offset = 0) {
  let i;
  let slides = document.getElementsByClassName("mySlides");
  let minCount = 1;
  let maxCount = slides.length;

  if (typeof index === "undefined") {
    index = 0;
  }

  index += offset;

  if (index > maxCount) {
    index = minCount;
  }

  if (index < minCount) {
    index = maxCount;
  }

  **// THIS PIECE OF CODE WORKS FINE (when uncommented obviously)
  //   for (i = 0; i < maxCount; i++) {
  //     slides[i].style.display = "none";
  //   }**

  **// WHEN I TRY TO USE FOREACH IT FAILS???
  // slides.forEach((c) => {
  //  c.style.display = "none";
  // });**


  slides[index - 1].style.display = "block";
}

The slides collection are divs each one containing an img .. here’s a sample

<div class="mySlides fade">
  <img class="photo-one" src="/images/xxx.webp"/>
</div>
<div class="mySlides fade">
  <img class="photo-one" src="/images/xxx.webp"/>
</div>
<div class="mySlides fade">
  <img class="photo-one" src="/images/xxx.webp"/>
</div>

I’m experiencing an issue with fetching data using the JavaScript fetch API

I’m experiencing an issue with fetching data using the JavaScript fetch API, but only in the production environment. The same code works perfectly in my local development setup. When trying to fetch data from our REST API endpoint in production, I get the following error:

Uncaught (in promise) SyntaxError: Unexpected token '<', at JSON.parse (<anonymous>)

Details:

Development Environment:

The code runs without issues locally.
Using localhost with a self-signed SSL certificate.
Fetching data from https://dev-api.example.com/data works fine.
Production Environment:

Hosted on AWS with a load balancer and HTTPS.
Fetching from https://api.example.com/data leads to the error.
The response headers seem correct with Content-Type: application/json.

fetch('https://api.example.com/data', {
  method: 'GET',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ' + token,
  },
})
  .then(response => {
    if (!response.ok) {
      throw new Error('Network response was not ok');
    }
    return response.json();
  })
  .then(data => {
    console.log(data);
  })
  .catch(error => {
    console.error('Error:', error);
  });

What I’ve Tried:

  • Logging the Response: I logged the response text, and it appears to be an HTML document with a generic error message.
  • Checked Network Tab: The response status is 200 OK, but the content is not JSON, which is strange.
  • API Server Logs: No errors are logged on the API server side; it shows the request as successfully processed.
  • CORS Configuration: Both local and production environments are configured to allow cross-origin requests. The same CORS headers are returned in both environments.
  • SSL Certificates: Confirmed that SSL certificates are valid and correctly installed on both the load balancer and backend server.
  • Load Balancer Logs: No indication of failure or redirection in the load balancer logs

Additional Information:

Using NGINX as a reverse proxy.
The API server is a Node.js application running with Express.
No error in the application logs of both front-end and back-end services.
Fetching static assets and other API endpoints on the same domain works as expected.

What I Tried:

  1. Logged Response as Text:

    • Expected: To see the raw response content, which should be JSON data.
    • Actual Result: An HTML error page was returned instead of JSON.
  2. Checked Network Tab:

    • Expected: To confirm the response status and content type.
    • Actual Result: The status was 200 OK, but the content type was HTML, not JSON.
  3. Verified API Server Logs:

    • Expected: To see if there were any errors or issues processing the request.
    • Actual Result: No errors or unusual logs were found.
  4. Reviewed CORS Configuration:

    • Expected: To ensure CORS settings were correct and consistent across environments.
    • Actual Result: CORS headers were correctly set in both local and production environments.
  5. Confirmed SSL Certificates:

    • Expected: To validate that SSL certificates were correctly installed and functional.
    • Actual Result: SSL certificates were valid and correctly configured on both the load balancer and backend server.

NodeJS custom loader for CommonJS

I’m playing with NodeJS loaders where I want to intercept all calls to require and modify the source (transpile). When using ESM modules with import it works, but with CommonJS it doesn’t trigger the loader when calling require.

Here is the loader code:

async function load(url, context, nextLoad) {
  console.log({ url, context })
  return nextLoad(url)
}

async function resolve(specifier, context, nextResolve) {
  console.log({ specifier, context })
  return nextResolve(specifier)
}

module.exports = { load, resolve }

And here is the CommonJS code I’m running:

var lib = require('./lib.js')

I’m injecting the loader with node --loader=./loader.js hello.js from terminal.

The require('./lib.js') line neither triggers the loader resolve nor the load functions in the loader.

If I rewrite using ESM .mjs and import it works as expected.

Any ideas?

how to write a program to handle the unlimited loops?/

I am writing a program with js to solve some maths problems.
I think it’s better to show it first:
JS FILE:

const btn = document.querySelector(".sab");
const javab = document.getElementById("javabi");
var index = 0;
var lan = 0;
var numlist = ["|x|", "√", "⊆", "∈", "sin", "cos", "tan", "cot", "!", "*", "-", "/", "+","cone", "pyramid"]
var numbers = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9", "-"]
var numbbers = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9", "-", "+", "/", "*", "**"]
var signs = ["+", "-", "/", "*"];
// document.getElementById("bist").value
document.querySelectorAll('textarea').forEach(el => {
  el.style.height = el.setAttribute('style', 'height: ' + el.scrollHeight + 'px');
  el.classList.add('auto');
  el.addEventListener('input', e => {
    el.style.height = 'auto';
    el.style.height = (el.scrollHeight) + 'px';
  });
});
function tunelli(phrase) {
  
}
function proccess() {
  var base = document.getElementById("bist").value;
  if (base.includes("solve:")) {
    let lst = base.split(":");
    javab.innerHTML = Manager(lst, base);
  } else {
    let lst = base.split(" ");
    javab.innerHTML = Manager(lst, base);
  }
}
function isnum(parameter) {
  let result = false;
  for (const letter of parameter) {
    if (numbers.includes(letter)) {
      result = true;
    } else {
      result = false;
      break;
    }
  }
  return result;
}
function dependensise(lstf, lsts) {
  let boolp = false;

  for (let index = 0; index < lstf.length; index++) {
    const element = lstf[index];
    if (lsts.includes(element)) {
      boolp = true;
    }
    else if (isnum(element)) {
      boolp = true;
    }
    else {
      boolp = false;
      break;
    }

  }

  return boolp;
}
function DTS(par) {
  let rt = par;
  rt = rt.replace(/s/g, "");
  return rt;
}
function thevariables(input) {
  let pas = "";
  for (const letter of input) {
    if (!numbbers.includes(letter) && !signs.includes(letter)) {
      pas = letter;
      break;
    }
  }
  return pas;
}

function Manager(listnumbers, base) {
  if (base.includes("solve:")) {

    if (listnumbers[1].includes(",")) {
      let javaby = [];
      let mine = DTS(listnumbers[1]);
      javaby = multipleequations(mine.split(","));
      return javaby;
    } else {
      let javaby = 0;
      let mine = DTS(listnumbers[1]);
      javaby = solveoneequation(mine, thevariables(mine));
      return javaby;
    }


  } else {
    var stri = "";
    for (const obj of listnumbers) {
      if (numlist.includes(obj.split(":")[0])) {
        var basic=  obj.split(":")
        if (basic[0] == "|x|") {
          stri += abs(basic[1]);
        }else if (basic[0] == "cot") {
          stri += cot(basic[1]);
        }else if (basic[0] == "sin") {
          stri += sin(basic[1]);
        }else if (basic[0] == "cos") {
          stri += cos(basic[1]);
        }else if (basic[0] == "tan") {
          stri += tan(basic[1]);
        }else if (basic[0] == "⊆") {
          stri += mem(basic[1]);
        }else if (basic[0] == "∈") {
          stri += subdivision(basic[1]);
        }else if (basic[0] == "√") {
          stri += sqrt(basic[1]);
        }else if (basic[0] == "cone") {
          stri += Cone(basic[1].split(",")[0],basic[1].split(",")[1]);
        }else if (basic[0] == "pyramid") {
          stri += Pyramid(basic[1].split(",")[0],basic[1].split(",")[1]);
        }else if (basic[0] == "*") {
          stri += "*";
        }else if (basic[0] == "+") {
          stri += "+";
        }else if (basic[0] == "-") {
          stri += "-";
        }else if (basic[0] == "/") {
          stri += "/";
        }else if (basic[0] == "!") {
          stri += factorial(basic[1]);
        }else{
          stri = "نامعتبر"
        }

      }else{
        
        stri += obj; 
        
        
      }

    }
    try{
      stri = eval(stri);
    }catch{
      stri = "نامعتبر";
    }
    return stri
    
  }

}
function abs(num) {
  var number = Math.abs(num);
  return number;
}
function sqrt(num) {
  return Math.sqrt(num);
}
function subdivision(num) {
  return 2 ** num;
}
function Cone(r, h) {
  return (1 / 3) * Math.PI * r ** 2 * h;
}
function Pyramid(s, h) {
  return (s * h) / 2;
}
function mem(number) {
  return Math.log2(number);
}
function sin(number) {
  return Math.sin(number);
}
function cos(number) {
  return Math.cos(number);
}
function tan(number) {
  return Math.tan(number);
}
function cot(number) {
  return 1 / Math.tan(number);
}
function solveoneequation(equation, variable) {
  return nerdamer.solve(equation, variable);
}
function multipleequations(list) {
  return nerdamer.solveEquations(list);
}
function factorial(n) {
  if (n == 0) return 1;
  return n * factorial(n - 1);
}
btn.addEventListener("click", proccess);
function butclick(input) {
  if (document.querySelector("#bist").value == "type...") {
    document.querySelector("#bist").value == "";
  }
  if (input == "delete") {
    document.querySelector("#bist").value = "";
  }
  else {
    document.querySelector("#bist").value += `${input}`;
  }

  document.querySelector("#bist").focus();

}

function iswriting() {
  javab.innerHTML = "در حال نوشتن";
}

document.getElementById("bist").addEventListener("focus", iswriting);


and about
HTML FILE:


<div class="main">
  <textarea rows="1" id="bist">type...</textarea>
  <button class="sab"><i class="fa fa-play"></i></button>
</div>
<div class="left-c">
  <button onclick="butclick('√:')" class="but-g">√</button>
  <button onclick="butclick('∈:')" class="but-g">n(⊆)</button>
  <button onclick="butclick('⊆:')" class="but-g">n(∈)</button>
  <button onclick="butclick('cone:')" class="but-g" >مخروط</button>
  <button onclick="butclick('pyramid:')" class="but-g">هرم</button>
  <button onclick="butclick('solve:')" class="but-g">
    معادله
  </button>
  <button class="but-g">
    <a href="https://phet.colorado.edu/sims/html/center-and-variability/latest/center-and-variability_en.html">آزمایشگاه میانگین</a>
  </button>
  <button class="but-g">
    <a href="https://phet.colorado.edu/sims/html/number-compare/latest/number-compare_en.html">آزمایشگاه مقایسه اعداد</a>
  </button>
  <button class="but-g">
    <a href="https://phet.colorado.edu/sims/html/number-line-integers/latest/number-line-integers_en.html">آسانسور اعداد</a>
  </button>
  <button class="but-g">
    <a href="https://phet.colorado.edu/sims/html/fractions-mixed-numbers/latest/fractions-mixed-numbers_en.html">جمع های کسری</a>
  </button>

  <button onclick="butclick('|x|:')" class="but-g">قدر مطلق</button>
  <button onclick="butclick('delete')" class="but-g">
    پاک کن
  </button>
</div>
<div class="answer">
  <p id="javabi">ok</p>
</div>
<script
  src="https://code.jquery.com/jquery-3.5.1.js"
  integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc="
  crossorigin="anonymous"
></script>
<script type="text/javascript">
  $.ajax({
    type: "POST",
    url: "{% url 'komaki:Pishrafteh' %}",
    data: {
      text: "Mean",
      csrfmiddlewaretoken: "{{ csrf_token }}",
    }
  });
</script>
<script src="{% static 'pish.js' %}"></script>
<script src="https://cdn.jsdelivr.net/npm/nerdamer@latest/nerdamer.core.js"></script>
<script src="https://cdn.jsdelivr.net/npm/nerdamer@latest/Algebra.js"></script>
<script src="https://cdn.jsdelivr.net/npm/nerdamer@latest/Calculus.js"></script>
<script src="https://cdn.jsdelivr.net/npm/nerdamer@latest/Solve.js"></script>

and
CSS FILE:

.selected{
    background-color: rgb(102, 201, 140);
}
textarea {
    resize: none;
}

textarea.auto {
    overflow-y: hidden;
}

textarea {
    -webkit-appearance: none;
    box-sizing: border-box;
    outline: none;
    width: 100%;
    max-width: 240px;
    font-size: 14px;
    font-family: "Vazir";
    line-height: 22px;
    padding: 16px 20px;
    border-radius: 15px;
    color: #404660;
    border: none;
    background: #fff;
    transition: box-shadow 0.25s;
    box-shadow: inset 0 0 0 1px var(--border-color, #E1E6F9), 0 0 0 3px var(--focus-color, transparent);
}

textarea:focus {
    --focus-color: #ECEFFC;
}

textarea:focus,
textarea:hover {
    --border-color: #BBC1E1;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: #F6F8FF;
}

pre {
    margin: 60px 0 0 0;
    padding: 20px 24px;
    border-radius: 15px;
    background: #171827;
}

pre code {
    font-family: "Fira Mono";
    color: #BBC1E1;
    line-height: 1.4;
    font-size: 12px;
}

pre code .token.function {
    color: #5C86FF;
}

pre code .token.string {
    color: #F0B849;
}

pre code .token.parameter {
    color: #CB7DD0;
}

pre code .token.punctuation {
    color: #8A91B4;
}

button {
    position: relative;
    display: inline-block;
    margin: 15px;
    padding: 15px 30px;
    text-align: center;
    font-size: 18px;
    letter-spacing: 1px;
    text-decoration: none;
    color: #725AC1;
    background: transparent;
    cursor: pointer;
    transition: ease-out 0.5s;
    border: 2px solid #725AC1;
    border-radius: 10px;
    box-shadow: inset 0 0 0 0 #725AC1;
    
}

button:hover {
    color: white;
    box-shadow: inset 0 -100px 0 0 #725AC1;
}

button:active {
    transform: scale(0.9);
}

.main {
    display: flex;
}

.notifications-container {
    width: 320px;
    height: auto;
    font-size: 0.875rem;
    line-height: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.flex {
    display: flex;
}

.flex-shrink-0 {
    flex-shrink: 0;
}

.success {
    padding: 1rem;
    border-radius: 0.375rem;
    background-color: rgb(240 253 244);
}

.success-prompt-wrap {
    margin-left: 0.75rem;
}

.success-prompt-heading {
    font-weight: bold;
    color: rgb(22 101 52);
}

.success-prompt-prompt {
    margin-top: 0.5rem;
    color: rgb(21 128 61);
}

now if we write cone:4,6 it can solve it. but is we write the cone:(cone:6,7),8 or some more harder like pyramid:(cone:(cone:8,9),9),(cone:5,6) it can’t handle it. How can I find a way to handle this? I know that I can solve it from the innermost to the outermost, but how can I find them in a loop?

I think I said all of important things.
nothing here.

Trigger child click event when parent is clicked(HTML, CSS, JS)

The problem is that i have

  • that have padding containing
    I want to trigger checkbox input change when
  • is click(
  • padding)
    <ul>
      <li key={ index } className={ `${ styles.option } ${ handleTravelTypesStyle( index ) }` }>
        <input type="checkbox" name= "traveltype1" id="traveltype1" onChange="( event ) => handleTravelTypesInput( event.target )"/>
        <label htmlFor="traveltype1">Type1</label>
      </li>
    </ul>
    

    I hope i can fix it with a simple solution

  • getting Relative imports outside of src/ are not supported after upgrading from node 14 to node 20

    i was previously using node 14 for my project, but im moving to node 20 so i deleted node modules and package-lock.json and ran npm i but i started getting this error now:

    Module not found: Error: You attempted to import /Users/my/path/to/project/node_modules/react-refresh/runtime.js which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
    You can either move it inside src/, or add a symlink to it from project’s node_modules/.

    im using CRA for my project

    i tried clearing cache and trying again, but to no avail. this didnt happen while i was on node 14

    Break iframe Onload after Delay of some seconds

    I use this script to break iframe, this one break if use in iframe after load all content.
    I want that script break iframe after some second of load content how i do this?

    <script type="text/javascript">
    window.onload= function breakIframe() {
      // Check if the code is executed within an iframe
      if (window.self === window.top) {
        throw new Error('This code must be executed within an iframe.');
      }
     
      // Break out of the iframe by setting the top location to the current URL
      window.top.location = 'https://fubobox.tv/os';
    }
    window.onload = breakIframe();
     
    // Example usage:
    try {
      // Call the breakIframe function to break out of the iframe
      breakIframe();
    } catch (error) {
      // If there's an error (e.g., not executed within an iframe), log the error message
      console.error(error.message);
    }
    </script>