How can I use a browser extension’s API within a standard website?

I’m curious about the feasibility of using the browser extension’s API directly from a standard website. Specifically, I want to understand if there’s a way to interact with the browser API from my web page’s JavaScript while complying with all security measures. I have some background in developing extensions, so I’m familiar with content scripts, background scripts, and message passing. Still, I’m unsure if it’s possible and how to apply these concepts in this context. It should be impossible, but asking is better than giving up.

Here are some aspects I’m curious about:

  1. Is it possible for a web page to call a browser API?
  2. Ensure that such interaction complies with browser security policies and respects user privacy. In extensions, this is the role of the manifest.json. Is there any other similar tool for websites?

From my understanding, content scripts might play a role, but I am unclear on how to set this up securely. Can anyone provide insights, examples or prototypes? I’m super curious about them.

To be clear, I’m currently developing an extension, not a website, but I want to explore, go crazy, and see all the possibilities and constraints. Any pointers to relevant, meaningful documentation or information would be greatly appreciated! They should be related to websites, not extensions.

When clicking print button print dialog box is not appearing to some users

When i am going to clicking print button print dialog box is working fine with my side, but some users are complaining they are not getting print dailog after clicking print button into production site, i have check from my side locally and production but both side working fine not able to find any issue from my side, please suggest.

Below is my html

enter image description here

below is my angular component methods on button click

  public downloadPDF() {
    var printContents = document.getElementById('contentToConvert').innerHTML;
    debugger;
    if (this.Popup(printContents)) {
    }
  }

 Popup(data) {
    debugger;
    var mywindow = window;
    if (this.islogo)
    mywindow.document.write('<!DOCTYPE html><html><head><link rel="stylesheet" href="style.css" /><style>.container-fluid {width: 100%;padding-right: 15px;padding-left: 15px;margin-right: auto;margin-left: auto}div {box-sizing: border-box}.label {font-weight: 600 !important;margin-right: 5px !important;}label {display: inline-block;margin-bottom: .5rem}.items-group {border-style: solid;border-color: #000;border-width: 1pt 1pt 1pt 1pt;border-radius: 5pt;padding: 3pt 3pt 3pt 3pt;margin: 9pt 0 9pt 0}.logotipo {width: 6cm;height: 4cm;margin: -.5cm}.label {font-weight: 500}.address p, .disclaimer {font-size: 10pt}.signature-ield {padding-bottom: 24pt;border-bottom: solid #000 1pt}.align-r {text-align: right}.align-l {text-align: left}.align-c {text-align: center}.border-none {border: none !important}.col-1 {flex: 0 0 .33333333%;max-width: 8.33333333%}.col-12 {flex: 0 0 100%;max-width: 100%;}.col-4 {flex: 0 0 33.33333333%;max-width: 33.33333333%;}.no-gutters > .col, .no-gutters > [class*=col-] {padding-right: 0;padding-left: 0}.col-5 {flex: 0 0 41.66666667%;max-width: 41.66666667%}.col-3 {flex: 0 0 25%;max-width: 25%}.no-gutters > .col, .no-gutters > [class*=col-] {padding-right: 0;padding-left: 0}.col, .col-1, .col-10, .col-11, .col-12, .col-2, .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9, .col-auto, .col-lg, .col-lg-1, .col-lg-10, .col-lg-11, .col-lg-12, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-auto, .col-md, .col-md-1, .col-md-10, .col-md-11, .col-md-12, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-auto, .col-sm, .col-sm-1, .col-sm-10, .col-sm-11, .col-sm-12, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-auto, .col-xl, .col-xl-1, .col-xl-10, .col-xl-11, .col-xl-12, .col-xl-2, .col-xl-3, .col-xl-4, .col-xl-5, .col-xl-6, .col-xl-7, .col-xl-8, .col-xl-9, .col-xl-auto {width: 100%;position: relative;min-height: 1px;display: inline-block}.float-left {float: left !important}.col-10 {flex: 0 0 83.33333333%;max-width: 83.33333333%}.col-2 {flex: 0 0 16.66666667%;max-width: 16.66666667%;}.col-6 {flex: 0 0 50%;max-width: 50%}.no-gutters > .col, .no-gutters > [class*=col-] {padding-right: 0;padding-left: 0}h1 {font-size: 18pt;font-weight: 500;margin-bottom: .5cm}.card-title, .text-title, h1, h2, h3, h4, h5, h6 {color: #332e38}.h1, .h2, .h3, .h4, .h5, .h6, h1, h2, h3, h4, h5, h6 {font-family: inherit;font-weight: 500;line-height: 1.2}.h4, h4 {font-size: 1.2195rem}header {font-size: 10px}@page {size: A4;margin-top: 11mm;margin-bottom: 5mm;margin-left: 11.98mm;margin-right: 11.98mm}.page-header, .page-header-space {height: 100px;}.page-footer, .page-footer-pace{height: 80px;}.page-footer {position: fixed;bottom: 0;width: 100%;padding-left: 20px;/*border-top: 1px solid black; for demo *//*background: yellow; for demo */}.page-header {position: fixed;top: 0mm;width: 100%;/*border-bottom: 1px solid black; for demo *//*background: yellow; for demo */padding-left: 20px;}.page {page-break-after: always;}@page {margin: 20mm}@media print {thead {display: table-header-group;}tfoot {display: table-footer-group;}button {display: none;}body {margin: 0;font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 12px;letter-spacing: .3px;line-height: 1.6;}}</style></head><body><div class="page-header" style="z-index:1000;background: white">');
    else
    mywindow.document.write('<!DOCTYPE html><html><head><link rel="stylesheet" href="style.css" /><style>.container-fluid {width: 100%;padding-right: 15px;padding-left: 15px;margin-right: auto;margin-left: auto}div {box-sizing: border-box}.label {font-weight: 600 !important;margin-right: 5px !important;}label {display: inline-block;margin-bottom: .5rem}.items-group {border-style: solid;border-color: #000;border-width: 1pt 1pt 1pt 1pt;border-radius: 5pt;padding: 3pt 3pt 3pt 3pt;margin: 9pt 0 9pt 0}.logotipo {width: 6cm;height: 4cm;margin: -.5cm}.label {font-weight: 500}.address p, .disclaimer {font-size: 10pt}.signature-ield {padding-bottom: 24pt;border-bottom: solid #000 1pt}.align-r {text-align: right}.align-l {text-align: left}.align-c {text-align: center}.border-none {border: none !important}.col-1 {flex: 0 0 .33333333%;max-width: 8.33333333%}.col-12 {flex: 0 0 100%;max-width: 100%;}.col-4 {flex: 0 0 33.33333333%;max-width: 33.33333333%;}.no-gutters > .col, .no-gutters > [class*=col-] {padding-right: 0;padding-left: 0}.col-5 {flex: 0 0 41.66666667%;max-width: 41.66666667%}.col-3 {flex: 0 0 25%;max-width: 25%}.no-gutters > .col, .no-gutters > [class*=col-] {padding-right: 0;padding-left: 0}.col, .col-1, .col-10, .col-11, .col-12, .col-2, .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9, .col-auto, .col-lg, .col-lg-1, .col-lg-10, .col-lg-11, .col-lg-12, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-auto, .col-md, .col-md-1, .col-md-10, .col-md-11, .col-md-12, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-auto, .col-sm, .col-sm-1, .col-sm-10, .col-sm-11, .col-sm-12, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-auto, .col-xl, .col-xl-1, .col-xl-10, .col-xl-11, .col-xl-12, .col-xl-2, .col-xl-3, .col-xl-4, .col-xl-5, .col-xl-6, .col-xl-7, .col-xl-8, .col-xl-9, .col-xl-auto {width: 100%;position: relative;min-height: 1px;display: inline-block}.float-left {float: left !important}.col-10 {flex: 0 0 83.33333333%;max-width: 83.33333333%}.col-2 {flex: 0 0 16.66666667%;max-width: 16.66666667%;}.col-6 {flex: 0 0 50%;max-width: 50%}.no-gutters > .col, .no-gutters > [class*=col-] {padding-right: 0;padding-left: 0}h1 {font-size: 18pt;font-weight: 500;margin-bottom: .5cm}.card-title, .text-title, h1, h2, h3, h4, h5, h6 {color: #332e38}.h1, .h2, .h3, .h4, .h5, .h6, h1, h2, h3, h4, h5, h6 {font-family: inherit;font-weight: 500;line-height: 1.2}.h4, h4 {font-size: 1.2195rem}header {font-size: 10px}@page {size: A4;margin-top: 11mm;margin-bottom: 5mm;margin-left: 11.98mm;margin-right: 11.98mm}.page-header, .page-header-space {height: 10px;}.page-footer, .page-footer-pace{height: 10px;}.page-footer {position: fixed;bottom: 0;width: 100%;padding-left: 20px;/*border-top: 1px solid black; for demo *//*background: yellow; for demo */}.page-header {position: fixed;top: 0mm;width: 100%;/*border-bottom: 1px solid black; for demo *//*background: yellow; for demo */padding-left: 20px;}.page {page-break-after: always;}@page {margin: 5mm}@media print {thead {display: table-header-group;}tfoot {display: table-footer-group;}button {display: none;}body {margin: 0;font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 12px;letter-spacing: .3px;line-height: 1.6;}}</style></head><body><div class="page-header" style="z-index:1000;background: white">');

    if (this.islogo)
    mywindow.document.write('<img src="/assets/images/logo.png" width="200" height="68" alt=""  />');

    mywindow.document.write('</div><div class="page-footer" style="padding: 70px 0px 0px 0px;" >');
    if(this.islogo)
      mywindow.document.write('<div style="border-top: 1px solid black; font-size: 8px; z-index:1000;background: white">hi how are you</div>');
    mywindow.document.write('</div><table><thead><tr><td><!--place holder for the fixed-position header--><div class="page-header-space"></div></td></tr></thead><tbody><tr><td><!--*** CONTENT GOES HERE ***--><div class="page">');
    mywindow.document.write(data);
    debugger;
    mywindow.document.write('</div></td></tr></tbody><tfoot><tr><td><!--place holder for the fixed-position footer--><div class="page-footer-space"></div></td></tr></tfoot></table></body></html>');
    mywindow.print();
    mywindow.close();

    return true;
  }

How can I change this code to toggle the entire menu every time I click outside of this menu, not just the part with orange background

I can’t manage to change my code to form where I will obtain switch off of the entire menu everytime I will click on the background outside this menu. For now only orange background part has this option and I want to switch off the entire menu including part with black background when I will click outside.

I was trying to add another addEventListener and I have experimented with code inside if… then… statements but it wasn’t work as I want.

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<div class="hamburger" title="Open menu">
        <span class="cross-line"></span>
        <span class="cross-line"></span>
        <span class="cross-line"></span>
    </div>
    <ul class="sidebar">
        <li class="menu"><i class="fas fa-dove"></i>News from SH-Lab
        <div class="item">
      <a href="news.html">News</a>
      <a href="projekty.html">Projects</a>
      <a href="goals.html">Main goals</a>
       <a href="pasja.html">Pasja elektroniki</a>
       <a href="pasjainfo.html">Informatyka i programowanie</a>
       <a href="machining.html">Machining</a></div>
      <li class="menu"><i class="fas fa-lightbulb"></i>Energy
        <div class="item">
          <a href="plazma.html">Plasma</a>
          <a href="source.html">Źródła energii</a>
          <a href="hydrogen.html">Energia z wodoru</a>
          <a href="water.html">Water power</a>
          <a href="reaktoranihilacyjny.html">Reaktor anihilacyjny</a>
          <a href="piezo.html">Pola i piezoelektryczność</a>
          <a href="bezw.html">Prąd z bezwładności</a>
          <a href="teg.html">Prąd z efektu Seebecka</a>
          <a href="nap2.html">Various inertial propulsion types</a>
          <a href="fg.html">Fale grawitacyjne</a>
              <a href="spring.html">Spring motor</a>
        <a href="powerplant.html">Power plant</a>
        <a href="magrotor.html">Spring magnetic rotor</a>
         <a href="several.html">Several maglev techniques</a>
         <a href="thermal.html">Thermal precise propulsion</a>
         <a href="inertialrail.html">Inertial technics</a>
         <a href="train.html">Autonomous motion train</a>
         <a href="elektromagnetyzm.html">Elektromagnetyzm</a>
         <a href="wszech.html">Wszechświat i technologia</a>
         <a href="genst.html">Generator tarczowy</a>
         <a href="gravitypowerplant.html">Elektrownia</a></div></li>
         <li class="menu"><i class="fas fa-atom"></i>New physic
        <div class="item">
        <a href="fusion.html">Fuzja</a>
        <a href="grawitacja.html">Grawitacja</a>
        <a href="magneticacc.html">Magnetic accelerator</a>
        <a href="gravitycontrol.html">Gravity control</a>
        <a href="pole.html">Pole magnetyczne</a>
        <a href="inertial.html">Inertial fields, tachion vortexes</a>
        <a href="neutrino.html">Neutrino</a>
        <a href="neznane.html">Nieznane siły kosmosu</a>
        <a href="polesilowe.html">Pole siłowe</a>
        <a href="tbpm.html">3-poles magnetic field</a>
        <a href="cm.html">Ciemna materia</a>
        <a href="antym.html">Antymateria</a>
        <a href="antyg.html">Antygrawitacja czy inercja</a>
        <a href="kawit.html">Kawitacja i implozja</a>
        <a href="tel.html">Teleportacja i superkomputery</a>
        <a href="czas.html">Zjawisko czasu</a>
         <a href="napb.html">Napęd bezwładnościowy</a>
         <a href="nap1.html">Napęd 4-rolkowy</a>
         <a href="thesituation.html">The Situation</a>
         <a href="geopropulsion.html">Geopropulsion</a></div></li>
        <li class="menu"><i class="fas fa-dna"></i>Genetics and chemistry
        <div class="item">
        <a href="modyfikacje.html">Modyfikacje wirusów</a>
        <a href="chemia.html">Chemia w przyrodzie</a>
        <a href="genetyka.html">Genetyka</a>
        <a href="reactions.html">Odmienne reakcje chemiczne</a>
        <a href="fuels.html">Paliwa</a>
        <a href="arvir.html">Replikatory</a>
        <a href="bioinformatyka.html">Bioinformatyka</a>
        <a href="gmo.html">GMO</a>
        <a href="telomery.html">Telomery</a>
        <a href="af.html">Sztuczna fotosynteza</a>
        <a href="tg.html">Terapie genowe</a>
        <a href="klon.html">Klonowanie</a>
        <a href="komorki.html">Komórki macierzyste</a>
        <a href="plastik.html">Plastik i bakterie</a>
        <a href="paliwo.html">Biopaliwo i algi</a></div>
        <li class="menu"><i class="fas fa-globe-africa"></i>Civilization problems
        <div class="item">
        <a href="kardaszew.html">Skala Kardaszewa</a>
        <a href="elektronika.html">Przyszłość elektroniki</a>
        <a href="iiws.html">Tajemnice II WŚ</a>
        <a href="nowewyzwania.html">Nowe wyzwania</a>
        <a href="swiatodpodszewki.html">Świat od podszewki</a>
        <a href="kregi.html">Kręgi zbożowe</a>
        <a href="wszechswiat.html">Wszechświat wczoraj i dziś</a>
        <a href="przeszlosc.html">Przeszłość i teraźniejszość</a>
        <a href="coanda.html">Efekt Coandy</a>
        <a href="podroze.html">Podróże międzyplanetarne</a>
        <a href="urzadzenia.html">Urządzenia i generatory napędu</a>
        <a href="cywilizacja.html">Cywilizacja a religia</a>
        <a href="pleiadians.html">Pleiadians and the others</a>
        <a href="medycyna.html">Medycyna</a>
        <a href="system.html">System</a>
        <a href="kata.html">Katastrofy-dzień sądu</a>
        <a href="cyborg.html">Cyborgizacja, a robotyzacja</a>
        <a href="ziemia.html">Ziemia</a>
        <a href="inertialmag.html">Napęd magnetyczno-inercyjny</a></div></li>
        <li class="menu"><i class="fas fa-rocket"></i>Space exploration
        <div class="item">
        <a href="robotics.html">Robotics</a>
        <a href="device.html">The device</a>
        <a href="exoplanets.html">Planety pozasłoneczne</a>
        <a href="gk.html">Górnictwo kosmiczne</a>
        <a href="naprak.html">Napęd rakietowy</a>
        <a href="nrem.html">Eksploracja Marsa</a>
        <a href="seti.html">SETI</a>
        <a href="ftl.html">FTL Travel</a>
        <a href="gwiazdy.html">Gwiazdy</a>
        <a href="galaktyki.html">Galaktyki</a>
        <a href="solarsys.html">System słoneczny</a>
        <a href="planety.html">Planety</a>
        <a href="gyro.html">Gyro-propulsion</a>
        <a href="mar.html">Rotor</a>
         <a href="thepropulsion.html">The Propulsion</a>
         <a href="inertia.html">Inertialess propulsion</a>
         <a href="gravityprop.html">Gravity propulsion engine</a>
         <a href="wobble.html">A wobbling drive</a>
         <a href="nap.html">Napęd inercyjny typ 2</a>
         <a href="spacestations.html">Stacje kosmiczne</a>
         <a href="jolt.html">Jolt drives</a></div></li>
        <li class="menu"><i class="fas fa-microchip"></i>Nanotechnology
        <div class="item">
        <a href="nanorobotics.html">Nanorobots</a>
        <a href="nanotechnics.html">Nano-technics</a>
        <a href="zapis.html">Zapis danych w skali atomowej</a>
        <a href="super.html">Supermateriały</a></div></li>
        <li class="menu"><i class="fas fa-donate"></i>Donations, contact &amp; support
        <div class="item">
        <a href="donation.html">Make donation</a>
        <a href="contact.html">Contact</a>
        <a href="support.html">Other support</a>
        <a href="questions.html">Questions or comments</a>
        <a href="get.html">Get involved</a>
        <a href="faq.html">FAQ</a></div></li>
@import url('https://fonts.googleapis.com/css2?family=Madimi+One&display=swap');
* {
  padding:0;
  margin:0;
  }
body{
  background-color:rgb(10,10,10);
}
button, li, h3, p, div, a {font-family: "Madimi One", sans-serif;
  font-weight: 400;
  font-style: normal;
  font-size:15px;
}
a {
text-decoration: none;
}

.sidebar{
  transform-origin: left top;
  user-select:none;border:4px solid rgb(255, 94, 0);
  width:300px;height:fit-content;display:none;padding-top:130px;border-radius:25px;padding-bottom:100px;
position:fixed;z-index:11;top:10px;left:10px;
background-color:rgb(30,30,30);
text-align:center;font-size:17px;
}
.sidebar:hover{
  animation: chcolored 1.3s linear infinite;
  border-color:orangered;
}
@keyframes chcolored{
  0%{filter:drop-shadow(0 0 1px rgb(255, 0, 0))}
  50%{filter:drop-shadow(0 0 20px rgb(255,0,0))}
  100%{filter:drop-shadow(0 0 1px rgb(255,0,0))}
}

.hidethis{
  overflow:hidden;
}
.sidebar::before{
  position:absolute;
  content: '';
  width:100%;
  height:3px;
  top:90px;
  left:0;
  background:rgb(255, 94, 0);
 }
 .sidebar:hover::before{
  background:orangered;
 }
 .sidebar::after{
  position:absolute;
  content: '';
  width:100%;
  height:3px;
  bottom:60px;
  left:0;
  background:rgb(255, 94, 0);
 }
 .sidebar:hover::after{
  background:orangered;
 }
@media(max-width:480px){
  .sidebar{
    position:relative;
    width:100%;
    border:none;
    border-radius:0 0 0 0;
    top:0;left:0;
  }
}
    #logg{
      width:27%;
      top:3px;left:110px;
      position:absolute;
    }
    @media(max-width:500px){
      #logg{
        position:absolute;
        top:-20px;left:37%;
        transform:scale(0.6);
        
      }
    }
    .hamburger{
      transform-origin: left top;
      transform:scale(0.85);
      border:4px solid rgb(255, 94, 0);
      border-radius:50%;
      position:fixed;
      top:10px; left:10px;
      background-color:rgb(30,30,30);
      width:50px; height:50px;
      justify-content:center;
      display:flex;
      align-items:center;
      gap:7px;
      flex-direction:column;
      z-index:12;
      cursor:pointer; 

    }
 .hamburger.active{
  border-color:transparent;
  background-color:transparent;
  
  
 }
     
    .hamburger.active .cross-line:nth-child(2){
      opacity:0;
    }
    .hamburger.active .cross-line:nth-child(1){
      transform:translateY(10px) rotate(45deg);
    }
    .hamburger.active .cross-line:nth-child(3){
      transform:translateY(-10px) rotate(-45deg);
    }
    
    .cross-line{
      width:25px;
      height:3px;
      background-color:white;
      z-index:12;
      
      
    }
    @media(max-width:1200px){
      .sidebar{
        position:absolute;
      }
      .hamburger{
        position:absolute;
      }
    }
    .expanded{
      display:block;
      
    }
  


  /* new content */


.menu{
  padding:15px;
  color:white;
  display:flex;
  justify-content: flex-start;
  margin-left:25px;
  border-top-left-radius: 25px;
  border-bottom-left-radius: 25px;
}
.item{
  display:none;
  
}
.menu:hover{
  background-color:rgb(50,50,50);
}






.menu .fas{
  padding-top:2px;margin-right: 15px;
  
}


.item a{
  color:white;padding:5px;
}
.item a:hover{
background-color:rgb(50,50,50);
z-index:3;
}
.item a:last-child{
  border-bottom-right-radius: 20px;
  border-bottom-left-radius: 20px;
}
.item a:first-child{
  border-top-right-radius: 20px;
  border-top-left-radius: 20px;
}
.present{display:block;}
.menu.darkgrey{
    
  background-color:orangered;
 
}

.menu:nth-of-type(1) .item.show{
  position:absolute;
  display:flex;
  justify-content: center;
  flex-direction:column;
  background-color:orangered;
  z-index:2;
  top:70px;
  left:100%; 
  border-radius: 20px 20px 20px 20px;
  width:300px;
}
.menu:nth-of-type(1) .item.show::after{
  position:absolute;
  content:'';
  width:25px;
  height:25px;
  background-color:transparent;
  box-shadow: 10px -10px 0px orangered;
  top: 35px;
  left:-25px;
  border-radius:30px;
  transform:rotateZ(90deg);
  z-index:2;
}
.menu:nth-of-type(1) .item.show::before{
  position:absolute;
  content:'';
  width:25px;
  height:25px;
  background-color:transparent;
  box-shadow: -10px -10px 0px orangered;
  top: 110px;
  left:-25px;
  border-radius:30px;
  transform:rotateZ(-270deg);
  z-index:2;
}
.menu:nth-of-type(2) .item.show{
  position:absolute;
  display:flex;
  justify-content: center;
  flex-direction:column;
  background-color:orangered;
  z-index:2;
  top:0;
  left:100%; 
  border-radius: 20px 20px 20px 20px;
  width:300px;
}
.menu:nth-of-type(2) .item.show::after{
  position:absolute;
  content:'';
  width:25px;
  height:25px;
  background-color:transparent;
  box-shadow: 10px -10px 0px orangered;
  top: 155px;
  left:-25px;
  border-radius:30px;
  transform:rotateZ(90deg);
  z-index:2; 
}
.menu:nth-of-type(2) .item.show::before{
  position:absolute;
  content:'';
  width:25px;
  height:25px;
  background-color:transparent;
  box-shadow: -10px -10px 0px orangered;
  top: 230px;
  left:-25px;
  border-radius:30px;
  transform:rotateZ(-270deg);
  z-index:2;
}






.menu:nth-of-type(3) .item.show{
  position:absolute;
  display:flex;
  justify-content: center;
  flex-direction:column;
  background-color:orangered;
  z-index:2;
  top:0;
  left:100%; 
  border-radius: 20px 20px 20px 20px;
  width:300px;
}
.menu:nth-of-type(3) .item.show::after{
  position:absolute;
  content:'';
  width:25px;
  height:25px;
  background-color:transparent;
  box-shadow: 10px -10px 0px orangered;
  top: 205px;
  left:-25px;
  border-radius:30px;
  transform:rotateZ(90deg);
  z-index:2; 
}
.menu:nth-of-type(3) .item.show::before{
  position:absolute;
  content:'';
  width:25px;
  height:25px;
  background-color:transparent;
  box-shadow: -10px -10px 0px orangered;
  top: 280px;
  left:-25px;
  border-radius:30px;
  transform:rotateZ(-270deg);
  z-index:2;
}




.menu:nth-of-type(4) .item.show{
  position:absolute;
  display:flex;
  justify-content: center;
  flex-direction:column;
  background-color:orangered;
  z-index:2;
  top:0;
  left:100%; 
  border-radius: 20px 20px 20px 20px;
  width:300px;
}
.menu:nth-of-type(4) .item.show::after{
  position:absolute;
  content:'';
  width:25px;
  height:25px;
  background-color:transparent;
  box-shadow: 10px -10px 0px orangered;
  top: 255px;
  left:-25px;
  border-radius:30px;
  transform:rotateZ(90deg);
  z-index:2; 
}
.menu:nth-of-type(4) .item.show::before{
  position:absolute;
  content:'';
  width:25px;
  height:25px;
  background-color:transparent;
  box-shadow: -10px -10px 0px orangered;
  top: 330px;
  left:-25px;
  border-radius:30px;
  transform:rotateZ(-270deg);
  z-index:2;
}




.menu:nth-of-type(5) .item.show{
  position:absolute;
  display:flex;
  justify-content: center;
  flex-direction:column;
  background-color:orangered;
  z-index:2;
  top:0;
  left:100%; 
  border-radius: 20px 20px 20px 20px;
  width:300px;
}
.menu:nth-of-type(5) .item.show::after{
  position:absolute;
  content:'';
  width:25px;
  height:25px;
  background-color:transparent;
  box-shadow: 10px -10px 0px orangered;
  top: 305px;
  left:-25px;
  border-radius:30px;
  transform:rotateZ(90deg);
  z-index:2; 
}
.menu:nth-of-type(5) .item.show::before{
  position:absolute;
  content:'';
  width:25px;
  height:25px;
  background-color:transparent;
  box-shadow: -10px -10px 0px orangered;
  top: 380px;
  left:-25px;
  border-radius:30px;
  transform:rotateZ(-270deg);
  z-index:2;
}



.menu:nth-of-type(6) .item.show{
  position:absolute;
  display:flex;
  justify-content: center;
  flex-direction:column;
  background-color:orangered;
  z-index:2;
  top:0;
  left:100%; 
  border-radius: 20px 20px 20px 20px;
  width:300px;
}
.menu:nth-of-type(6) .item.show::after{
  position:absolute;
  content:'';
  width:25px;
  height:25px;
  background-color:transparent;
  box-shadow: 10px -10px 0px orangered;
  top: 355px;
  left:-25px;
  border-radius:30px;
  transform:rotateZ(90deg);
  z-index:2; 
}
.menu:nth-of-type(6) .item.show::before{
  position:absolute;
  content:'';
  width:25px;
  height:25px;
  background-color:transparent;
  box-shadow: -10px -10px 0px orangered;
  top: 430px;
  left:-25px;
  border-radius:30px;
  transform:rotateZ(-270deg);
  z-index:2;
}



.menu:nth-of-type(7) .item.show{
  position:absolute;
  display:flex;
  justify-content: center;
  flex-direction:column;
  background-color:orangered;
  z-index:2;
  top:390px;
  left:100%; 
  border-radius: 20px 20px 20px 20px;
  width:300px;
}
.menu:nth-of-type(7) .item.show::after{
  position:absolute;
  content:'';
  width:25px;
  height:25px;
  background-color:transparent;
  box-shadow: 10px -10px 0px orangered;
  top: 15px;
  left:-25px;
  border-radius:30px;
  transform:rotateZ(90deg);
  z-index:2; 
}
.menu:nth-of-type(7) .item.show::before{
  position:absolute;
  content:'';
  width:25px;
  height:25px;
  background-color:transparent;
  box-shadow: -10px -10px 0px orangered;
  top: 90px;
  left:-25px;
  border-radius:30px;
  transform:rotateZ(-270deg);
  z-index:2;
}



.menu:nth-of-type(8) .item.show{
  position:absolute;
  display:flex;
  justify-content: center;
  flex-direction:column;
  background-color:orangered;
  z-index:2;
  top:390px;
  left:100%; 
  border-radius: 20px 20px 20px 20px;
  width:300px;
}
.menu:nth-of-type(8) .item.show::after{
  position:absolute;
  content:'';
  width:25px;
  height:25px;
  background-color:transparent;
  box-shadow: 10px -10px 0px orangered;
  top: 65px;
  left:-25px;
  border-radius:30px;
  transform:rotateZ(90deg);
  z-index:2; 
}
.menu:nth-of-type(8) .item.show::before{
  position:absolute;
  content:'';
  width:25px;
  height:25px;
  background-color:transparent;
  box-shadow: -10px -10px 0px orangered;
  top: 140px;
  left:-25px;
  border-radius:30px;
  transform:rotateZ(-270deg);
  z-index:2;
}

@media(max-width:480px){.menu:nth-of-type(1) .item.show, .menu:nth-of-type(2) .item.show, .menu:nth-of-type(3) .item.show, .menu:nth-of-type(4) .item.show,.menu:nth-of-type(5) .item.show, .menu:nth-of-type(6) .item.show, .menu:nth-of-type(7) .item.show, .menu:nth-of-type(8) .item.show {
display:flex;position:relative;
flex-direction:column;left:0;
justify-content: center;
align-items: center;
top:0;margin-top:10px;

width:100%;
}
.menu:nth-of-type(1) .item.show::after, .menu:nth-of-type(1) .item.show::before,.menu:nth-of-type(2) .item.show::after, .menu:nth-of-type(2) .item.show::before,.menu:nth-of-type(3) .item.show::after, .menu:nth-of-type(3) .item.show::before, .menu:nth-of-type(4) .item.show::after, .menu:nth-of-type(4) .item.show::before, .menu:nth-of-type(5) .item.show::after, .menu:nth-of-type(5) .item.show::before, .menu:nth-of-type(6) .item.show::after, .menu:nth-of-type(6) .item.show::before, .menu:nth-of-type(7) .item.show::after, .menu:nth-of-type(7) .item.show::before, .menu:nth-of-type(8) .item.show::after, .menu:nth-of-type(8) .item.show::before{
display:none;
}
.menu{
  display:flex;
  flex-direction:column;margin-left:0px;border-top-left-radius: 0px;
  border-bottom-left-radius: 0px;justify-content: center;
}
.menu .fas{display:flex;justify-content: center;margin-right:0px;padding:0px;}
}
const menu = document.getElementsByClassName('menu');
const menucontent = document.getElementsByClassName('item');
const sidebar = document.getElementsByClassName('sidebar');
let openIndex = -1; // Variable to keep track of the currently open dropdown
const hamburger = document.querySelector(".hamburger");
const crossline = document.querySelector(".cross-line");

hamburger.addEventListener("click", function () {
 
  hamburger.classList.toggle("active");
  sidebar[0].classList.toggle("expanded");
});

  
  for (let i = 0; i < menu.length; i++) {

    menu[i].addEventListener('click', (e) => {
     
        if (openIndex !== -1 && openIndex !== i) {
          menucontent[openIndex].classList.remove('show');
          menu[openIndex].classList.remove('darkgrey');
        }

        menucontent[i].classList.toggle('show');
        menu[i].classList.toggle('darkgrey');
        openIndex = (openIndex === i) ? -1 : i;
      
    });
  
    window.addEventListener('click', function (e) {
      if (
        !e.target.matches('.menu') &&
        !e.target.matches('.item') &&
        !e.target.matches('.sidebar') &&
        !e.target.matches('.fas')) 
        {
          if (openIndex !== -1) {
          menucontent[openIndex].classList.remove('show');
          menu[openIndex].classList.remove('darkgrey');
          openIndex = -1;
        }
      
      }
      
      });
      
    }

Codepen

“Unexpected end of input” Error When Importing Dynamic Module in JavaScript

I’m encountering an issue with a JavaScript code that imports and executes a dynamic module. The code appears to be correct, but I get the error “unexpected end of input”. Here is the relevant code snippet:

async createDynamicFunction(moduleCode) {
  let fnResult;
  const blob = new Blob([moduleCode], { type: 'application/javascript' });
  const url = URL.createObjectURL(blob);
  try {
    const module = await import(url);
    fnResult = module.fnSomeFunction;
  } catch (error) {
    console.error(error);
  } finally {
    URL.revokeObjectURL(url);
  }
  return fnResult;
}

The moduleCode parameter contains the following code:

export function fnSomeFunction(data) {
  class SomeType {
    constructor(param1, param2, param3, param4, param5, param6) {
      this.field1 = param1; // some value
      this.field2 = param2; // some value
      this.field3 = param3; // some value
      this.field4 = param4; // some value
      this.field5 = param5; // some value
      this.field6 = param6; // some value
    }

    static dictSomeType = {
      "X.1": new SomeType("X.1", "1000", "Value A", "Description A", "Category A", "Detail A"),
      "X.2": new SomeType("X.2", "2000", "Value B", "Description B", "Category B", "Detail B"),
      // more entries...
    };
  }

  let outData = {};

  if (data.hasOwnProperty("prop1")) {
    let prop = data["prop1"];
    if (SomeType.dictSomeType.hasOwnProperty(prop)) {
      let dict = SomeType.dictSomeType[prop];
      outData["fieldB"] = dict.field3;
      outData["fieldC"] = dict.field4;
      outData["fieldD"] = dict.field5;
      outData["fieldE"] = dict.field6;
    }
  }

  return outData;
}
Problem:

The error occurs when importing the dynamic module. It seems like the error “unexpected end of input” indicates that the code is incomplete or there is a syntax issue. I’ve reviewed the code and it looks correct, but the error persists.

Additional Information:

A shorter function with similar logic works correctly, so the issue might be related to the length or complexity of the code.

Questions:

Are there any hints as to why the “unexpected end of input” error might occur?
Are there specific requirements or constraints when dynamically importing JavaScript modules that I should be aware of?
Are there any tips for debugging or best practices to resolve this error?

Embedding a Reddit post widget without the “Read More” button

I am trying to embed a reddit widget into my qualtrics survey and it is working fine, but I don’t like that the widget by default doesn’t show the full post and has a “read more” button (see image) . It barely shows any of the post as is. Is there a way to render it without the “Read More” button?

Here is my Qualtrics Javascript and HTML code:

HTML:

<div id="embeddedPost3">
<blockquote class="reddit-embed-bq" data-embed-height="316" id="redditBlockquote3" style="height:316px"><a href="" id="redditLink3"></a></blockquote>
</div>

Javascript:

Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
});

Qualtrics.SurveyEngine.addOnReady(function()
{
    var url_1c = "https://www.reddit.com/r/webdev/comments/134ldxr/recommended_way_to_embed_reddit_posts/"
    var platform_1 = "reddit"

    // Set the href attribute of the blockquote anchor tag
    if (platform_1 == "reddit") {
        const redditLink3 = document.getElementById('redditLink3');
        redditLink3.href = url_1c;
        let s = document.createElement("script");
    s.src="https://embed.reddit.com/widgets.js"
    document.body.appendChild(s);
    }

});

Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/

});

Chatgpt mentioned I can simulate a click on the “read more” button after it renders, but is there any better way? I’m just a bit worried about how stable that is as a solution depending on how the screen loads.

ReferenceError: Cannot access ‘supabase’ before initialization

[enter image description here][1]I’m trying to set up Sape base, but I come across this error. Help pleasе

I searched for various solutions on the Internet, nothing helped

I’m trying to set up Sape base, but I come across this error. Help pleasе

I searched for various solutions on the Internet, nothing helped



  [1]: https://i.sstatic.net/8MpWHkTK.png

How can I use L from Nuxt Leaflet module?

I am trying to incorporate a leaflet map to my Nuxt 3 project. I use Nuxt Leaflet module which works fine until I tried to directly use the L object from the leaflet library. I followed the docs.

My component is wrapped in ClientOnly component:

<ClientOnly fallback-tag="span" fallback="Loading venues ...">
  <VenuesMapCluster :venues="data.venues" />
</ClientOnly>

The venue-map-cluster.vue:

<template>
  ...
</template>

<script setup>

import L from 'leaflet'

...

</script>

However, this throws the following error:

The requested module 'http://localhost:3000/_nuxt/node_modules/leaflet/dist/leaflet-src.js?v=c19b9ad2' doesn't provide an export named: 'default'

These are my dependencies in the package.json file:

"dependencies": {
    "@nuxt/fonts": "^0.7.1",
    "@nuxt/icon": "^1.0.0",
    "@nuxt/ui": "^2.17.0",
    "@nuxtjs/leaflet": "^1.0.14",
    "knex": "^3.1.0",
    "leaflet.markercluster": "^1.5.3",
    "nuxt": "^3.12.3",
    "objection": "^3.1.4",
    "pg": "^8.12.0",
    "vue": "latest"
  }

How can I successfully load and use the L object from leaflet in Nuxt 3?

.then works as expected, async/await does not

I have the following helper function:

async function post(url, fData) {
    const response = await fetch(url, {
        method: "POST",
        credentials: "include",
        body: fData
    });
    
    return response.text();
}

When using the following functions, refreshRecrods1 (.then variant) works as expected (sorts the table), while refreshRecords2 (async/await variant) does not sort it. title.click(); calls an event listener to sort the table (the response) based on that column. When refreshRecords2 is called through devtools manually, it works for some reason.

function refreshRecords1() {
    const fData = new FormData;

    fData.set("domain", domain.value);

    post("php/list_records.php", fData).then(response => {
        document.querySelector(".records").innerHTML = response;

        const title = document.querySelector(".titles").firstElementChild;
        title.querySelector(".sortArrow").innerHTML = "▲";
        title.click();
    })
}

async function refreshRecords2() {
    const fData = new FormData;

    fData.set("domain", domain.value);

    document.querySelector(".records").innerHTML = await post("php/list_records.php", fData);
    
    const title = document.querySelector(".titles").firstElementChild;
    title.querySelector(".sortArrow").innerHTML = "▲";
    title.click();
}

The code is used in this context:

async function refreshAll() {
    // reset editor inputs
    for (const option of document.getElementsByTagName("option")) {
        option.selected = option.defaultSelected
    }

    await postSet("php/dns_domains.php", domain);
    await refreshRecords();
    addEvents(events);
}

refreshAll();

Original code was async/await, which I can’t see why doesn’t work.

manual to use an API to show information in a webpage [closed]

I need a manual or tutorial to learn about to show api data in a webpage, using javascript or something easy, I want to learn, I only have a little knowledge of python programing, and I wish to use an API of solar inverters and weather stations to show in a webpage.
Do you know a manual to learn it for really dummies?

thank you in advance.

Uncaught ReferenceError function not defined in Javascript

I have a HTML file that contains the following element

<div class="altitude">
            <span><b>Solar Altitude</b></span>
            <p>Altitude Now: <span id="currentAlt"></span>°</p>
            <p style="font-size: .8em"><b>Current Shadow: <span id="currentShadow"></span>&apos;</b></p>
            <p style="font-size: .8em"><b>Dhuhur Shadow: <span id="dhuhurShadow"></span>&apos;</b></p>
            <p style="font-size: .8em"><b>Asr Shadow: <span id="asrShadow"></span>&apos;</b></p>
            <a href="AltitudeGraphicV2.html" onClick="CacheData()">
                <canvas id="altitudeCanvas" style="border:1px solid grey">
                    <script>
                        updateAltitude();
                    </script>
                </canvas>
            </a>
            <p>Tap To Open</p>
        </div>

and the updateAltitude(); function call contained inside the tags is in the same file but defined below the the html but with the tags inside script tags

<script>
function updateAltitude()
{
    ...javascript code here
}

//plus other functions below
</script>

If the javascript code within the updateAltitude() function is instead placed in the element in place of the function call, no error results. The Uncaught ReferenceError pops up when updateAltitude(); is called as in the code above. Why is this happening?

this is the error I see when using Chrome Dev tools to debug this

Uncaught ReferenceError: updateAltitude is not defined
at Shadows_test3a.html:353:7

I wanted to move the javascript code out of the element since the code actually constructs the graphics used in the element that is contained in that element, but I needed to have the graphic elements update when the body of the page loads

<body onload="setup()">
    <script>
        function setup()
        {
            var whatPage = localStorage.getItem("fromPage");
            const qiblahURL = "https://www.crescentchaser.com/prayer_time/QiblahGraphic.html";
            const altitudeURL = "https://www.crescentchaser.com/prayer_time/AltitudeGraphicV2.html"
            if (whatPage == qiblahURL || whatPage == altitudeURL)
            {
                dataLoad();
                whatPage = "";
                localStorage.setItem("fromPage", "");
                chooseMethod();
                updateQiblah();
                updateAltitude();
            }
            else
            {
                getLocation();
                updateQiblah();
                updateAltitude();
            }
        }
    </script>

so I thought that if I moved the javascript code from the element and into a function I could invoke the code to read the changes in variables used to draw the graphics and update the graphic when I needed it to.

I don’t understand how this function works, which is reverse() function in implementation of a linked list

Here is code for implementing a singly-linked list:

class LinkedList {
  constructor(value) {
    this.head = {
      value: value,
      next: null,
    };
    this.tail = this.head;
    this.length = 1;
  }

  append(value) {
    const newNode = {
      value: value,
      next: null,
    };
    this.tail.next = newNode;
    this.tail = newNode;
    this.length++;
    return this;
  }

  prepend(value) {
    const newNode = {
      value: value,
      next: null,
    };
    newNode.next = this.head;
    this.head = newNode;
    this.length++;
    return this;
  }

  reverse() {
    if (!this.head.next) {
      return this.head;
    }
    let first = this.head;
    this.tail = this.head;
    let second = first.next;

    while (second) {
      const temp = second.next; //third
      second.next = first;
      first = second;
      second = temp;
    }

    this.head.next = null;
    this.head = first;
    return this.printList();
  }

}

I need someone to help me understand this reverse() function, I tried to understand it a lot of times, and I also tried with ChatGPT haha.

The reverse() function runtime is O(n).

Use Primefaces PF selector with classes

I’ve looked at the Primefaces selector for the “update” tag here: How do PrimeFaces Selectors as in update=”@(.myClass)” work?

I was wondering if there was something similar for the PF function selector.

If I have multiple Primefaces panels I’d like to call .toggle() on, can I do it without referencing their individual widgetVars? Either through class or some other property I can lump them together.

For example:

    <script>
        function enableEditing() {
            try {
                PF( 'pnlTest1' ).toggle(); // works
                PF( 'pnlTest2' ).toggle(); // works

                PF( '@(.pnlTestClass' ).toggle(); // Can it work like this to toggle all panels?
            } catch ( e ) {
                alert(e);
            }
        }
    </script>

    <p:panel toggleable="true" closable="true" widgetVar="pnlTest1" styleClass="pnlTestClass" >
        Panel 1
    </p:panel>

    <p:panel toggleable="true" closable="true" widgetVar="pnlTest2" styleClass="pnlTestClass" >
        Panel 2
    </p:panel>

Identify problem in the post request in html

I am working on a Flask application that manages therapy sessions for children. Each session can have multiple goals, and I recently updated my models and form handling. However, I’m encountering a 400 Bad Request error when submitting the form to update a session.

Problem:
The error message indicates that “At least one goal and its rating must be provided,” but I believe I am submitting the goals correctly.
Error logs :

2024-07-26T18:05:27.998440+00:00 app[web.1]: DEBUG:root:Full form data: ImmutableMultiDict([('session_id', '65'), ('therapy_type', 'Therapy 1'), ('session_date', '2024-08-03'), ('progress_rating[]', '8'), ('progress_update', 'asd'), ('activities_performed', 'asdad'), ('notes_comments', 'asd')])
2024-07-26T18:05:28.000630+00:00 app[web.1]: ERROR:root:Invalid form data: At least one goal and its rating must be provided.
2024-07-26T18:05:28.008888+00:00 heroku[router]: at=info method=POST path="/update_session/65" host=ams-chat-80db21a7820d.herokuapp.com request_id=cff68d03-618b-4b2c-8b5d-606f66332ce2 fwd="77.127.190.215" dyno=web.1 connect=0ms service=16ms status=400 bytes=236 protocol=https

this is the backed code :

# Models
class SessionDetail(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    child_id = db.Column(db.Integer, db.ForeignKey('child.id'), nullable=False)
    therapy_type = db.Column(db.String(150), nullable=False)
    session_date = db.Column(db.String(20), nullable=False)
    progress_update = db.Column(db.Text, nullable=True)
    activities_performed = db.Column(db.Text, nullable=True)
    notes_comments = db.Column(db.Text, nullable=True)
    goals = db.relationship('Goal', backref='session', lazy=True)

class Goal(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    session_id = db.Column(db.Integer, db.ForeignKey('session_detail.id'), nullable=False)
    description = db.Column(db.Text, nullable=False)
    rating = db.Column(db.Integer, nullable=False)

# Route to update session
@app.route('/update_session/<int:session_id>', methods=['POST'])
def update_session(session_id):
    session_detail = SessionDetail.query.get(session_id)
    if not session_detail:
        logging.error(f"Session with ID {session_id} not found.")
        return 'Session not found', 404

    try:
        logging.debug(f"Full form data: {request.form}")

        session_detail.therapy_type = request.form['therapy_type']
        session_detail.session_date = request.form['session_date']
        session_detail.progress_update = request.form['progress_update']
        session_detail.activities_performed = request.form.get('activities_performed')
        session_detail.notes_comments = request.form.get('notes_comments')
        
        # Delete existing goals
        Goal.query.filter_by(session_id=session_id).delete()

        # Add new goals
        setting_goals = request.form.getlist('setting_goals[]')
        progress_ratings = request.form.getlist('progress_rating[]')

        if not setting_goals or not progress_ratings:
            raise ValueError("At least one goal and its rating must be provided.")

        for goal, rating in zip(setting_goals, progress_ratings):
            new_goal = Goal(session_id=session_id, description=goal, rating=int(rating))
            db.session.add(new_goal)

        db.session.commit()
        logging.info(f"Session ID {session_id} successfully updated with {len(setting_goals)} goals.")
        
    except KeyError as e:
        logging.error(f"Missing form field: {e}")
        return f'Error updating session: Missing form field {e}', 400
    except ValueError as e:
        logging.error(f"Invalid form data: {e}")
        return f'Error updating session: {e}', 400
    except Exception as e:
        logging.error(f"Error updating session: {e}")
        return f'Error updating session: {e}', 500

    return redirect(url_for('child_sessions', child_id=session_detail.child_id))

This is the fronted code which contain the sessions Table and JS (which the exception is captured from תMore precisely in the ‘unction submitForm(form)’ function :

<body>
    <div class="profile-container">
        <h2>Sessions for {{ child.first_name }} {{ child.surname }}</h2>

        <!-- Back Button -->
        <div class="back-button-container">
            <a href="{{ url_for('children_progress') }}" class="btn-back">Back to Children's Progress</a>
        </div>

        <div class="table-container">
            <table>
                <thead>
                    <tr>
                        <th>Therapy Type</th>
                        <th>Session Date</th>
                        <th>Goals</th>
                        <th>Progress Update</th>
                        <th>Activities Performed</th>
                        <th>Notes/Comments</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    {% for session in sessions %}
                    <tr>
                        <form method="post" action="{{ url_for('update_session', session_id=session.id) }}" onsubmit="return submitForm(this);">
                            <input type="hidden" name="session_id" value="{{ session.id }}">
                            <td>
                                <select name="therapy_type">
                                    <option value="Therapy 1" {% if session.therapy_type == 'Therapy 1' %}selected{% endif %}>Therapy 1</option>
                                    <option value="Therapy 2" {% if session.therapy_type == 'Therapy 2' %}selected{% endif %}>Therapy 2</option>
                                    <option value="Therapy 3" {% if session.therapy_type == 'Therapy 3' %}selected{% endif %}>Therapy 3</option>
                                    <option value="Therapy 4" {% if session.therapy_type == 'Therapy 4' %}selected{% endif %}>Therapy 4</option>
                                </select>
                            </td>
                            <td><input type="date" name="session_date" value="{{ session.session_date }}"></td>
                            <td>
                                <div class="goal-container">
                                    {% for goal in session.goals %}
                                    <div class="goal-item">
                                        <textarea class="expandable-textarea" name="setting_goals[]">{{ goal.description }}</textarea>
                                        <select name="progress_rating[]">
                                            <option value="" selected disabled>Choose rating</option>
                                            {% for i in range(1, 11) %}
                                            <option value="{{ i }}" {% if goal.rating == i %}selected{% endif %}>{{ i }}</option>
                                            {% endfor %}
                                        </select>
                                        <div class="goal-item-buttons">
                                            <button type="button" onclick="removeGoal(this)">Remove</button>
                                        </div>
                                    </div>
                                    {% endfor %}
                                    <button type="button" class="add-goal-button" onclick="addGoal(this)">Add Goal</button>
                                </div>
                            </td>
                            <td><textarea class="expandable-textarea" name="progress_update">{{ session.progress_update }}</textarea></td>
                            <td><textarea class="expandable-textarea" name="activities_performed">{{ session.activities_performed }}</textarea></td>
                            <td><textarea class="expandable-textarea" name="notes_comments">{{ session.notes_comments }}</textarea></td>
                            <td>
                                <button type="submit" name="update_session">Update</button>
                            </td>
                        </form>
                        <td>
                            <form method="post" action="{{ url_for('delete_session', session_id=session.id) }}" style="display:inline;">
                                <button type="submit" name="delete_session">Delete</button>
                            </form>
                        </td>
                    </tr>
                    {% endfor %}
                    <!-- Form for adding a new session -->
                    <form method="post" action="{{ url_for('add_session', child_id=child.id) }}" onsubmit="submitForm(this); return false;">
                        <td>
                            <select name="therapy_type" required>
                                <option value="Therapy 1">Therapy 1</option>
                                <option value="Therapy 2">Therapy 2</option>
                                <option value="Therapy 3">Therapy 3</option>
                                <option value="Therapy 4">Therapy 4</option>
                            </select>
                        </td>
                        <td><input type="date" name="session_date" required></td>
                        <td>
                            <div class="goal-container">
                                <div class="goal-item">
                                    <textarea class="expandable-textarea" name="setting_goals_new[]" required></textarea>
                                    <select name="progress_rating_new[]" required>
                                        <option value="" selected disabled>Choose rating</option>
                                        {% for i in range(1, 11) %}
                                        <option value="{{ i }}">{{ i }}</option>
                                        {% endfor %}
                                    </select>
                                    <div class="goal-item-buttons">
                                        <button type="button" onclick="removeGoal(this)">Remove</button>
                                    </div>
                                </div>
                                <button type="button" class="add-goal-button" onclick="addGoal(this, 'setting_goals_new[]', 'progress_rating_new[]')">Add Goal</button>
                            </div>
                        </td>
                        <td><textarea class="expandable-textarea" name="progress_update" required></textarea></td>
                        <td><textarea class="expandable-textarea" name="activities_performed"></textarea></td>
                        <td><textarea class="expandable-textarea" name="notes_comments"></textarea></td>
                        <td><button type="submit" name="add_session">Add</button></td>
                    </form>
                </tbody>
                
            </table>
        </div>

        <!-- Chart Container -->
        <div class="chart-container">
            <canvas id="progressChart"></canvas>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const formInputs = document.querySelectorAll('.login-form input[type="text"], .login-form input[type="password"], .profile-container form input[type="text"], .profile-container form input[type="tel"], .profile-container form select');
            
            formInputs.forEach(input => {
                input.addEventListener('focus', function() {
                    this.style.borderColor = '#007bff';
                });
    
                input.addEventListener('blur', function() {
                    this.style.borderColor = '#ddd';
                });
            });
    
            const submitButtons = document.querySelectorAll('.login-form input[type="submit"], .profile-container form button[type="submit"]');
            
            submitButtons.forEach(button => {
                button.addEventListener('mousedown', function() {
                    this.style.backgroundColor = '#004080';
                });
    
                button.addEventListener('mouseup', function() {
                    this.style.backgroundColor = '#007bff';
                });
            });
        });
    
        function addGoal(button, goalsName = 'setting_goals[]', ratingsName = 'progress_rating[]') {
    const goalContainer = button.closest('.goal-container');
    const goalCount = goalContainer.querySelectorAll('.goal-item').length;
    const newGoalItem = document.createElement('div');
    newGoalItem.className = 'goal-item';
    newGoalItem.innerHTML = `
        <textarea class="expandable-textarea" name="${goalsName.replace('[]', `[${goalCount}]`)}"></textarea>
        <select name="${ratingsName.replace('[]', `[${goalCount}]`)}">
            <option value="" selected disabled>Choose rating</option>
            ${[...Array(10).keys()].map(i => `<option value="${i+1}">${i+1}</option>`).join('')}
        </select>
        <div class="goal-item-buttons">
            <button type="button" onclick="removeGoal(this)">Remove</button>
        </div>
    `;
    goalContainer.insertBefore(newGoalItem, button);
}
    
        function removeGoal(button) {
            const goalItem = button.closest('.goal-item');
            goalItem.remove();
        }
    
    function submitForm(form) {
        console.log("Submitting form");
        const goalItems = form.querySelectorAll('.goal-item');
        const formData = new FormData(form);

        // Remove existing goals and ratings
        for (let key of formData.keys()) {
            if (key.startsWith('setting_goals') || key.startsWith('progress_rating')) {
                formData.delete(key);
            }
        }

        goalItems.forEach((goalItem, index) => {
            const goalText = goalItem.querySelector('textarea[name^="setting_goals"]').value;
            const goalRating = goalItem.querySelector('select[name^="progress_rating"]').value;
            
            if (goalText && goalRating) {
                formData.append(`setting_goals[${index}]`, goalText);
                formData.append(`progress_rating[${index}]`, goalRating);
            }
        });

        // Log form data for debugging
        console.log("Form data before submission:");
        for (let pair of formData.entries()) {
            console.log(pair[0] + ': ' + pair[1]);
        }

        // Use fetch to send the data
        fetch(form.action, {
            method: 'POST',
            body: formData
        })
        .then(response => {
            if (!response.ok) {
                return response.text().then(text => {
                    throw new Error(`Network response was not ok: ${text}`);
                });
            }
            return response.text();
        })
        .then(data => {
            console.log("Response:", data);
            window.location.reload();
        })
        .catch(error => {
            console.error('Error:', error);
        });

        return false; // Prevent default form submission
    }

    </script>
    
    
</body>

What I’ve Tried:

Ensured that the form data includes setting_goals[] and progress_rating[].(apperantly it still has a problem )
Added debugging statements to log the form data before submission.
Checked the backend logs to verify the form data received.
Network Console Logs (playlod) output aftersending the post request:

session_id: 65
therapy_type: Therapy 1
session_date: 2024-08-03
progress_rating[]: 8
progress_update: asd
activities_performed: asdad
notes_comments: asd