Div height different between chrome/edge and firefo

I’m designing a simple website with a navbar at the top, and an image that extends exactly from the bottom of the navbar to the bottom of the window (at the window’s maximized size), such that the image fills up the rest of the screen, without a scrollbar. I’m putting the image in a wrapper div and I’ll cut off any overflow, so it’s the div sizing I’m worried about. My issue is that the sizing appears correct in Chrome and Edge, but in Firefox, the div does not extend to the bottom of the page. Here are the images for the three browsers… I removed the image, and gave the wrapper div a brown background so you can see it easily.

Appearance on Chrome
Appearance on Chrome

Appearance on Edge
Appearance on Edge

Appearance on Firefox
Appearance on Firefox

Here’s my JS that sets the div height:

document.addEventListener('DOMContentLoaded', function() {
  setInterval(function() {
    var homepageTopImageWrapper = document.getElementById("homePageTopImageWrapper");
    var browserBarsHeight = window.outerHeight - window.innerHeight;
    var height = window.screen.availHeight - browserBarsHeight - 58;
    height += "px";
    homePageTopImageWrapper.style.height = height;
    console.log(window.screen.availHeight);
  }, 100);
}, false);

I added an event listener using JS to wait for all the DOM content to load, and then I calculated the correct height for my div by taking the availHeight and subtracting off 58px (the height of the navbar) and then subtracting the height of the toolbar at the top of the browser. The setInterval is so that the wrapper will resize right away if the user presses Ctrl+Shift+B.

Here’s the relevant HTML:

<!--__________________________NAVIGATION BAR__________________________-->
    <div id = "navbarWrapper">

      <!--________Navigation Buttons________-->
      <div id = "leftNavbarButtonWrapper">
        <div class="leftNavbarButtons" onclick="location.href='./ourMission_desktop.html'">Our Mission</div>
        <div class="leftNavbarButtons" onclick="location.href='./team_desktop.html'">Team</div>
        <div class="leftNavbarButtons" onclick="location.href='./services_desktop.html'">Services</div>
        <div class="leftNavbarButtons" onclick="location.href='./contactUs_desktop.html'">Contact Us</div>
      </div>

      <!--________Social Media Buttons________-->
      <div id="navbarSocialMediaImageWrapper">
        <img class = "navbarSocialMediaImage" src="../images/facebook_logo_white.png" alt="Facebook logo/link" onclick="window.open('<link path>', '_blank')">
        <img class = "navbarSocialMediaImage" src="../images/twitter_logo_white.png" alt="Twitter logo/link" onclick="window.open('<link path>', '_blank')">
        <img class = "navbarSocialMediaImage" src="../images/instagram_logo_white.png" alt="Instagram logo/link" onclick="window.open('<link path>', '_blank')">
      </div>

      <!--________Donate Button________-->
      <button id = "donateButton" onclick="window.open('<link path>', '_blank')">Donate Now</button>
    </div>


    <!--__________________________HOMEPAGE CONTENT__________________________-->

    <!--________Top Homepage Image________-->
    <div id = "homePageTopImageWrapper">
      <img src = "<img src>">
    </div>

Finally, here’s the CSS:

/*--------------------------------GLOBAL CONDITIONS--------------------------------*/
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Exo+2:wght@500;700&family=Poppins:wght@300&display=swap');

* {
  margin: 0;
  padding: 0;
  font-family: Poppins;
}

html, body{
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

/*--------------------------------NAVIGATION BAR--------------------------------*/
#navbarWrapper {
  /*border: 1px solid black;*/
  width: 100%;
  height: 58px;
  background: black;
  display: inline-flex;
}

#leftNavbarButtonWrapper {
  /*border: 1px solid red;*/
  border-spacing: 1cm 0;
}

.leftNavbarButtons {
  /*border: 1px solid green;*/
  display: inline-flex;
  color: white;
  height: 100%;
  justify-content: center;
  align-items: center;
  margin: 0 0.25cm 0 0.25cm;
  padding: 0 0.25cm 0 0.25cm;
}

.leftNavbarButtons:hover {
  color: #c2c2c2;
  cursor: pointer;
}

#donateButton {
  position: absolute;
  right: 2mm;
  top: 2mm;
  height: 1.1cm;
  width: 5cm;
  background: red;
  border: none;
  outline: none;
  color: white;
  font-size: 0.5cm;
  border-radius: 5px;
}

#donateButton:hover {
  cursor: pointer;
}

.navbarSocialMediaImage {
  /*border: 1px solid green;*/
  width: 0.6cm;
  height: 0.6cm;
  margin: 0 0.25cm 0 0.25cm;
}

#navbarSocialMediaImageWrapper {
  /*border: 1px solid red;*/
  height: 58px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  right: 6cm;
  top: 0mm;
}

.navbarSocialMediaImage:hover {
  cursor: pointer;
}

/*--------------------------------HOMEPAGE--------------------------------*/
#homePageTopImageWrapper {
  /*border: 3px solid green;*/
  background: brown;
  position: absolute;
  display: flex;
  top: 58px;
  width: 100%;
  /*height: calc(100% - 1.5cm);*/
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

Any ideas on why this is working in Chrome/Edge but not in Firefox?

Thank you very much.

Why isn’t Puppeteer page.click waiting (maybe Browserless?)

Goal:
I have a page that I need to get html from after first clicking something on the page.

Issue:
The html that comes back is not waiting for that element click.

Here’s one way that I’ve tried to do it.

await page.waitForSelector('.specs .accent', {visible: true, timeout: 80000});

const html = await page.evaluate(() => {
      const moreButton = document.querySelector('.specs .accent');
      moreButton.click('.specs .accent');
      return document.body.innerHTML;
});

console.log(html);

Here’s another way I’ve tried:

await page.waitForSelector('.specs .accent', {timeout: 80000});
await page.click('.specs .accent');
const html = await page.evaluate(() => document.body.innerHTML);
console.log(html);

The html that comes back is the html prior to the click happening. Leading me to believe that the click is broken, but not erroring out.

Notes:

  • I’ve screenshot after the page.click. The element is there, but not clicked.
  • There are no errors with page.click that I can find, but I might be debugging wrong.
  • I recently implemented Browserless. The code above used to work, but sometime between then and when I implemented Browserless (https://www.browserless.io/docs/docker-quickstart), it stopped working. Maybe there’s something wrong with their page.click or version of Puppeteer?
  • There’s also a proxy. So the flow is app -> browserless (puppeteer) -> proxy -> page.
  • The thing I’m trying to click is an <a href="javascript:void(0)" class="accent">More</a> When clicked, it populates some with preloaded data.

Finally:
I’m really not sure how to debug this further. Any clues?

finnhub not sending data

Finnhubs own Sample code:

news.js

const finnhub = require('finnhub');

const api_key = finnhub.ApiClient.instance.authentications['api_key'];
api_key.apiKey = "c28q5o2ad3if6b4c2e4g"
const finnhubClient = new finnhub.DefaultApi()

finnhubClient.companyNews("SOPA", "2022-05-09", "2022-05-09", (error, data, response) => {
    console.log(response)
});

When I run news.js in the terminal the output is:

[]

But I should be receiving:

[{"category":"company","datetime":1652122994,"headline":"Are These 3 Penny Stocks Worth Buying This Week?","id":110652332,"image":"https://pennystocks.com/wp-content/uploads/2022/05/Penny_Stocks_to_Watch_Exela-Technologies-XELA-Stock-Chart.jpg","related":"SOPA","source":"PennyStocks","summary":"Check these 3 penny stocks out for your watchlist this week","url":"https://finnhub.io/api/news?id=b6bea9683c2a814582c08f5b6a54361ea25617f80daa2e78bdf8d03ef2d736c4"},{"category":"company","datetime":1652101200,"headline":"Society Pass Inc (Nasdaq: SOPA) Reports 1Q 2022 Financial Results, Sees 4,582% Year on Year Revenue Growth and Cash on Hand Growth of 33% from Year 2021","id":110650937,"image":"https://s.yimg.com/uu/api/res/1.2/ksPh0oKfHlWxtfs6ki3zAA--~B/aD04ODt3PTg5O2FwcGlkPXl0YWNoeW9u/https://media.zenfs.com/en/globenewswire.com/9c76d98dd04393663867ffe6e7025cc3","related":"SOPA","source":"Yahoo","summary":"First quarter 2022 revenues grew 4,582% year on year (from $9,506 for first quarter ended 31 March 2021 to $445,090 for first quarter ended 31 March 2022). Cash on hand grew over 33% from $23.3 million on 31 December 2021 to $31.0 million on 31 March 2022. With the closed acquisitions of the Pushkart and Handycart business units, SoPa has now amassed over 1.6 million registered consumers and 5,500 registered merchants/brands onto its ever expanding ecosystem. SoPa is well capitalized for planned","url":"https://finnhub.io/api/news?id=b94178a985aadd11b1315b6d07921f5e091dd8bdabe4d108782dbb1a9dcd7f9f"},{"category":"company","datetime":1652091856,"headline":"Cable companies to offer effectively free internet to low-income homes","id":110646402,"image":"https://image.cnbcfm.com/api/v1/image/106892096-1622757348136-gettyimages-1233255609-785667_NA-POL-0603-VP-HIGH-SPEED-INTERNET_KKN_18088JPG.jpg?v=1652106378u0026w=1920u0026h=1080","related":"SOPA","source":"CNBC","summary":"The news means that tens of millions of households could receive high-speed internet at no cost, according to the White House.","url":"https://finnhub.io/api/news?id=5714a7e435dec0253a2e323023d739b038a921542317c0b1b6d4c274bd5cc3c0"}]

Why comparison of array values only matches most recently entered object value?

In the snippet below, if I enter a value in the textbox, it’s supposed to return something. i.e.; entering ‘PA’ returns ‘Pennsylvania’. But if I enter ‘AZ’, it returns my else statement.

How do I change this so that it checks the value against any value entered and displays the result properly?

const states = [
  {
    abbreviated: 'AZ',
    state: 'Arizona'
  }, {
    abbreviated: 'PA',
    state: 'Pennsylvania'
  }
];

function searchState() {
  let txt = searchTxt.value;
  for (var i = 0; i < states.length; i++) {
    var abbreviatedState = states[i];
    if (txt == abbreviatedState.abbreviated) {
      output.textContent = abbreviatedState.state;
    } else {
      output.textContent = 'Uh, oh! We don't know that one!';
    }
  }
}

document.querySelector('.search').addEventListener("click", ()=>searchState());
<input name="searchTxt" type="text" id="searchTxt" class="searchField" placeholder="State Abbreviation?"/>

<button class="search">Search</button>

<h4>State Of: <span id="output"></span></h4>

How do I recursively render nested components?

So I’m trying to implement a Comment System with React. (Non-interactive, just to render data). I’m having trouble with how to display the replies of each comment in the view.

comments.js (exports all the comment data)

const comments = [
    {
        ....metadata, // this is where all the metadata for the comment goes, such as the content
        replies: [
            {
                ...metadata,
                replies: [
                    // ...zero or more replies, of the same shape as comments[0]
                ]
            }
        ]
    },
    // ...other comments, of the same shape as comments[0]

export default comments

comment.jsx (the functional component that each element of the comments array above (and the replies of each element) is passed into):

const Comment = props => (
    <div>
        <div>
            {/* this is where all the comment's metadata will be rendered into */}
        </div>

        <div>{props.replies}</div>
    </div>
)

export default comment

App.jsx (what is going to end up being rendered into the DOM)

import comments from "./comments.js"
import Comment from "./comment.jsx"

const App = () => (
    {comments.map(comment => (
        <Comment 
            {...comment.metadata,
            replies:{comment.replies.map(reply => (
                <Comment {...reply.metadata} />
            ))}
            }
        />
    ))
    }
)

The problem with my approach is that replies that are buried more than 1 level deep from the topmost comment (ie replies of replies), won’t be rendered into the DOM.

Can anyone please provide a way of rendering all the replies, down to the innermost reply?

Thank you!

Promise.allSettled where promises list is varied incrementally

This code print a, b, d, c.

const promises = []
console.log('a')
someFunc(promises)
Promise.allSettled(promises).then(() => console.log('d'))

function someFunc(promises) {
    const promise = new Promise(resolve => setTimeout(() => {
        console.log('b')
        const promise2 = new Promise(resolve2 => setTimeout(() => {
            console.log('c')
            resolve2()
        }, 3000))
        promises.push(promise2)
        resolve()
    }, 3000))
    promises.push(promise)
    return promise
}

How can I achieve it to print a, b, c, d?

Action returns Status Code 204 but, AJAX success function doesn’t execute

My controller is correctly returning new HttpStatusCodeResult(204)(checked using debugging), but the success function is not triggered. I just want to reset a text field after I’ve submitted something.

Ajax:

$(document).ready(function () {
        $("#offersubmit").click(function (e) {
            $.validator.unobtrusive.parse($('offerForm'));
            if ($(this).valid()) {
                var valdata = $("#offerForm").serialize();
                $.ajax({
                    url: "/Product/MakeOffer",
                    type: "POST",
                    dataType: 'json',
                    contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
                    data: valdata,
                    success: $(document).ready(function () {
                        alert("AAA");
                        $('#offerText').val('');
                    })
                })
            }
        });
    });

Also tried with alert() and it didn’t show anything. Any help would be appreciated

Can’t get form to submit

I am trying to get this form to submit but it won’t return anything in the console.. is it because my entire html file is in a return statement from a js function? I assumed it would work because I imported a .css file and it translated just fine, but how do I get the submit button to return something in the console? I’ve attempted both querySelector and getElementbyID but when I press submit, it won’t output anything.

import React from "react";
import './css/Contact.css';

function Contact(){
    return (
        <div className="contact-container">
          <div className="top">
            <form action="Contact" className="contactForm" id="contactForm">
            <div><input type="text" className="name" id="name" placeholder="Enter your name"></input></div>
            <div><input type="text" className="email" id="email" placeholder="Enter your email"></input></div>
            <div><input type="text" className="message" id="message" placeholder="Enter your message"></input></div>
            <button type="submit" id = "submit">Submit</button>
            </form>
          </div>
          <div className="bottom">
            <h1>Get in touch!</h1>
            <h2>Hi there! We look forward to connecting with you!</h2>
            <h3>If you would like to get in touch please contact us at [email protected] or fill out the contact form displayed on your screen. </h3>
           </div>
   
          <script src="./contactDB.js"></script>   
          </div>   
          
      );
}

export default Contact;

Firebase File

import { initializeApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";

const firebaseConfig = {
    ...
  };

  // Initialize Firebase
  const app = initializeApp(firebaseConfig);
  const analytics = getAnalytics(app);
  
  // Refernece contactInfo collections
  let contactInfo = firebase.database().ref("infos");
  
  // Listen for a submit
  document.querySelector("contactForm").addEventListener("submit", submitForm);
  
  function submitForm(e) {
    e.preventDefault();
  
    //   Get input Values
    let name = document.querySelector("name").value;
    let email = document.querySelector("email").value;
    let message = document.querySelector("message").value;
    console.log(name, email, message);
  
    saveContactInfo(name, email, message);
    document.querySelector("contactForm").reset();
  }
  
  // Save infos to Firebase
  function saveContactInfo(name, email, message) {
    let newContactInfo = contactInfo.push();
  
    newContactInfo.set({
      name: name,
      email: email,
      message: message
    });
  }

How do I add an event listener to every element and check when any element has activated it? Vanilla JS [duplicate]

How do I add an event listener to every html element without adding it to each individual element by itself? And how can I tell when any element activates it to run it on that specific element.
Here is some sample thing that should describe what I mean.

for (i = elements in document) {
    i.addEventListener("click", function(i){
        //the code i want to run
    });
}

Anyone know how I can achieve this?

Soundcloud API – Is it still possible to build an app?

I’m trying to build something like heardle using the soundcloud api. I want to stream songs from soundcloud onto a web javascript application.

I’ve gone through the documentation and tried a bunch of example tutorials around the web and they all seem to not work. It seems that Soundcloud removed the ability to register new apps a couple years ago. It also seems that you can build a more basic app without app registration (I think?).

Every time I do the basic tutorials I’ve found around the web I get a 403 error (yes I am replacing the client ID with my own). Here are a couple examples:

https://jasonoda.com/temp2022/heardle/aa/

https://jasonoda.com/temp2022/heardle/

I’ve searched around, but I’m not getting any good answers to what exactly the problem is. It seems Soundcloud has changed it’s rules and apis enough that I’m not the only one confused. Is this still possible or am I just having some basic 403 issue?

Any help is deeply appreciated.

Uncaught ReferenceError: require is not defined (Finnhub) [duplicate]

Finnhub gave some sample code:

const finnhub = require('finnhub');

const api_key = finnhub.ApiClient.instance.authentications['api_key'];
api_key.apiKey = "c28q5o2ad3if6b4c2e4g"
const finnhubClient = new finnhub.DefaultApi()

finnhubClient.companyNews("AAPL", "2020-01-01", "2020-05-01", (error, data, response) => {
    console.log(data)
});

HTML:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <title>Hi</title>
    <body>
        <h1> hi </h1>

        <script>
            const finnhub = require('finnhub');

            const api_key = finnhub.ApiClient.instance.authentications['api_key'];
            api_key.apiKey = "c28q5o2ad3if6b4c2e4g"
            const finnhubClient = new finnhub.DefaultApi()

            finnhubClient.companyNews("AAPL", "2020-01-01", "2020-05-01", (error, data, response) => {
                console.log(data)
            });

        </script>
    </body>
  </head>
</html>

I want to see what the API is giving me but I’m running into this error (Uncaught ReferenceError: require is not defined)

Chart js error in angular: Canvas is already in use. Chart with ID ‘0’ must be destroyed before the canvas can be reused. Fix?

So basically, on div click (jquery), I have a bootstrap modal popup that has a chart. The chart works fine, and the rendering is perfect, the problem comes when I click another div.

Here’s my HTML

        <div class="modal fade" id="myModal" tabindex="-1" role="dialog">
            <div class="modal-dialog">
                <div class="card">
                    <div class="text-right cross"> hello<i class="fa fa-times"></i> </div>
                    <div id="chartDiv" *ngIf="chart"><canvas #chart>{{  chart  }}</canvas></div>   
                </div>
            </div>
        </div>

On a separate note, I’m using Chart.register(…registerables) in my constructor. Here goes my TS (just the relevant code):

import { Chart, registerables } from 'chart.js';
export class HomeComponent implements OnInit{
  @ViewChild('chart') canvas: ElementRef;

  chart: any = [];

ngOnInit(): void {   
    $('#myModal').on('hide.bs.modal', function () {
    $(".canvas").remove(); 
    })
    $('#myModal').on('show.bs.modal', function () {
      $("div.chart").append('<canvas #chart>{{chart}}</canvas>');
      $('#chart').trigger('focus')
    })
}

  divClick()
{
 $('#myModal').modal('show'); 
this.chart = this.getChartData()
}

getChartData(): Chart {
this.chart = new Chart(this.canvas.nativeElement.getContext('2d'), {data})
//please don't worry about data its coming from api and it works fine
return this.chart
}

}

This is all just very high level, but I’m happy to include any other code needed. I researched so many articles and ways to fix this error but couldn’t find any. If you can point me to a resource where Chart js is implemented using Angular, it’d be helpful.
Also, I tried the “destroy” function on this.chart but that doesn’t work either. Is there any other way to use this rather than exposing canvas. Just don’t know what I’m doing wrong. I even tried removing and re-adding canvas classs through jquery (in onInit) but that doesn’t work either. (Chartjs v3.7.0)

JavaScript json miss [closed]

I am new to the field and I took a course in HTML and CSS and learning JavaScript but I find some problems understanding Json should I skip it and try it later or there is something I am missing in this part?