Why does audioContext muted the sound

I’m trying to do a visualiser like this: Visualiser Audio js

But with the file that is on my pc not one that the customer can choose.
Like here the file is on my pc.

<audio src="a.mp3" id="audioHTML" controls></audio>

I found this man doing it but it’s the customer who choose the file they want, so how can I do it ?

I tried this but the sound is muted and that’s my problem.
(when I delete ‘var context = new AudioContext();’ the sound is back but obviously there is not the visualiser)

'use strict'

var audio = document.getElementById("audioHTML");
  

function playAudio() {
    audio.play();

    var context = new AudioContext();
    var src = context.createMediaElementSource(audio);
    var analyser = context.createAnalyser();

    var canvas = document.getElementById("canvas");
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;
    var ctx = canvas.getContext("2d");

    src.connect(analyser);
    analyser.connect(context.destination);

   
    analyser.fftSize = 256;
    
    var bufferLength = analyser.frequencyBinCount;
    console.log(bufferLength);
    
   
    var dataArray = new Uint8Array(bufferLength);

    var WIDTH = canvas.width;
    var HEIGHT = canvas.height;

    var barWidth = (WIDTH / bufferLength) * 2.5;
    var barHeight;
    var x = 0;

    function renderFrame() {
      requestAnimationFrame(renderFrame);

      x = 0;

      analyser.getByteFrequencyData(dataArray);

      ctx.fillStyle = "#000";
      ctx.fillRect(0, 0, WIDTH, HEIGHT);

      for (var i = 0; i < bufferLength; i++) {
        barHeight = dataArray[i];
        
        var r = barHeight + (25 * (i/bufferLength));
        var g = 250 * (i/bufferLength);
        var b = 50;

        ctx.fillStyle = "rgb(" + r + "," + g + "," + b + ")";
        ctx.fillRect(x, HEIGHT - barHeight, barWidth, barHeight);

        x += barWidth + 1;
      }
    }

    audio.play();
    renderFrame();
   }
#thefile {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 100;
}

#canvas {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

audio {
  position: fixed;
  left: 10px;
  bottom: 10px;
  width: calc(100% - 20px);
}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <link rel="stylesheet" href="style.css" />
</head>
    <body>

        <div id="content">
            <canvas id="canvas"></canvas>
            <button onclick="playAudio()">click</button>
            <audio src="https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3" id="audioHTML" controls></audio>
        </div>

        <script src="audioVisualiser.js"></script>
    </body>
</html>

Issues with multiple sticky / fixed headers/divs? (Jittering and positioning on scroll)

I’m trying to make a site with multiple sections. There are logos, that should take up the full screen. Then, as the user scrolls down, the logos should get smaller and shrink to the top of the screen, staying fixed to the top. They should push the section contents down so that they are fully visible.

The user can continue scrolling down to the next section. It should once again be the full page height, taking up the user’s entire screen. It should push the previous logo header up out of the way, and repeat the same process, as the user scrolls down, it should get smaller, moving to the top of the screen, leaving space for the contents of the section.

However, unfortunately, the headers seem to be very jittery when I try to scroll down. The scrolling can even get stuck without moving the scrollbar with the mouse.

I have also found that after I scroll down past the second section, the first header pops up again.

Here is my site, with the minimal code to reproduce this problem:
The Site

The code is mainly copied from two w3schools tutorials, I have been trying to combine the two:
https://www.w3schools.com/howto/howto_js_sticky_header.asp
https://www.w3schools.com/howto/howto_js_shrink_header_scroll.asp

Any help would be greatly appreciated, and if anyone has any ideas on how this could be fixed, please, let me know!

Thanks!

Chrome Extension Is not saving the value in local storage

I’m trying to build my own custom made dark mode theme in Javascript, it is a chrome extension. It is almost finished, the click handler is working just fine, it makes the website darker and vice versa. However, I want it to save the value so if I turn the webpage darker, I want it to be dark even after I refresh the page, or, open the same page again so it’s still dark (I hope I make sense). At this point once I refresh the page it loses the value, so if dark mode is applied – it becomes white again (and if I open the same page it is white on the second tab). I’m attaching the screenshots, could anyone let me know what’s wrong or what’s causing the issue so I can finally finish the extension.

 **chrome.storage.sync.set({ key: "dark" }, function () {
    console.log("Value is set to " + "dark");
  });
  chrome.storage.sync.get(["key"], function (result) {
    console.log("Value currently is " + result.key);
  });
  //   localStorage.setItem("darkMode", 1);
})();


The manifest.json code:
{
  "name": "chrome extension",
  "description": "Go to dark mode from Light mode and vice versa",
  "version": "1.0.0",
  "manifest_version": 2,
  "background": {
    "scripts": ["popup.js"],
    "persistent": true
  },
  "browser_action": {
    "default_title": "PYL",
    "default_popup": "popup.html"
  },
  "permissions": ["https://*/*", "http://*/*", "tabs", "storage", "activeTab"]
}**

I cant use command INSERT INTO

I download appserv two days ago and started writing php code but ı couldn’t use INSERT INTO command. I thought the error was in the program and download xampp but i faced the same problem again. I writed a register page but ı can’t using INSERT INTO command. Not given error but not writing data to database. I dont think a problem be my connect. Here are the codes.
As I said, ı dont taken error code or notification.

<?php

require_once 'connection.php';
require_once 'register-back-end.php';


?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>Kayıt Ol</title>
</head>
<body>
    
    <div class="container">

        <form method="POST" action="register-back-end.php">
        <div class="input-group">
      <label>Username</label>
      <input type="text" name="username">
    </div>
    <div class="input-group">
      <label>Email</label>
      <input type="email" name="email">
    </div>
    <div class="input-group">
      <label>Password</label>
      <input type="password" name="pass">
    </div>
    <div class="input-group">
      <input type="submit" class="btn" value="POST" name="register" >
    </div>
        </form>

    </div>

</body>


</html>

connection.php

<?php

$connection = mysqli_connect("localhost","root","","account");
$db = mysqli_select_db($connection,'account')

?>

register-back-end.php

<?php

if(isset($_POST['register'])){
$isle = 'INSERT INTO users (id,username,email,pass) VALUES 
(2,"'.$_POST['username'].'","'.$_POST['email'].'","'.$_POST['pass'].'")';
}

?>

This too phpmyadmin picture

Am I getting serverless function timeouts (error 504) on vercel because I set up next-auth wrong?

Background

I’ve been working on a next.js project that is meant to handle scheduling events. I’ve been using next-auth for authentication with mongodb, because I need a database to store information about scheduled events anyway.

While testing locally, I didn’t have any issues at all, but ever since deploying on vercel AND mongo Atlas, I’ve been getting 504 “serverless function timeouts” up the wazoo on page load. A lot of people have mentioned that this is likely due to not making a connection with the db, but I’m not sure how to fix this. The only function that I am calling inside of getServerSideProps is getSession() as it is called in the docs.

Steps I’ve tried

  • I’ve followed the next-auth configuration steps located here for mongodb
  • I’ve followed the mongodb guide for vercel best practices here
  • I’ve tried connecting to the atlas from the mongosh shell, and it’s always quick as can be.

Conclusion

I’ve seen some stuff around mentioning that other people have been getting some pretty wicked cold start times on their serverless function, so I’ve created a snippet that pings the home page of my app 10 times every 2 minutes. This works okay as far as I can personally test, but 4-5 of any 10 requests hang for 10+ seconds while the rest finish up in roughly 200ms or so.

What am I doing wrong? / What can I do better?

My code

home page:

export const Home = function (props) { ... } // this never gets ran

export async function getServerSideProps(context) {
  const session = await getSession(context);
  const props = { session };
  const redirect = {
    destination: '/login',
    permanent: false,
  };

  return (!session)
    ? { redirect }
    : { props };
}

export default Home;

The login page:

export async function getServerSideProps(context) {
  const session = await getSession(context);

  if (session) {
    return {
      redirect: {
        destination: '/home',
      },
    };
  }

  return {
    props: {
      providers: await getProviders(),
      session,
    },
  };
}

nextAuth config:

import NextAuth from 'next-auth';
import GoogleProvider from 'next-auth/providers/google';
import { MongoDBAdapter } from '@next-auth/mongodb-adapter';
import clientPromise from 'lib/database/mongodb';

export default NextAuth({
  adapter: MongoDBAdapter(clientPromise),
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_ID,
      clientSecret: process.env.GOOGLE_SECRET,
    }),
  ],
  secret: "pshhhh, it's a secret" 
});

What is “Signature Verification Failed” in Solana?

I’m trying to call a Solana Program, and when I run sendAndConfirmTransaction, it gives me Signature Verification Failed, and I’m not sure why.

const {sendAndConfirmTransaction, clusterApiUrl, Connection} = require("@solana/web3.js");

let signer = Keypair.generate();
let anotherKeypair = Keypair.generate();

let transaction = someInstruction(signer, anotherKeypair); 
let connection = new Connection(clusterApiUrl('testnet'));

sendAndConfirmTransaction(
  connection,
  transaction,
  [signer]
);

Debug multiple javascript files in VSCode

I have a javascript project containing multiple files that reference each other.
In a browser context, all of those files would be loaded via a script tag.
I want to debug my project in VSCode, because I only need the terminal and it is more convenient.
How can I get VSCode to also have the other files in it’s scope while debugging? Like you would debug Python for example (which ofc always has all programs running in scope). Is there something like import? Or has it to do with the launch.json file?
Thank you for your help.

Добрый день, я загружаю картинки с пк стараюсь зделать так чтобы при перезагрузке страницы картинки оставлялись через localStorage [closed]

enter image description here‘но у меня при перезагрузке очищаетса хранилище как зделать чтобы картинки при перезагрузке оставлялисьenter code here
вот код’enter image description here

Find ID of next instance of a specific class

I’m trying to find the ID (test1, test2, test3 etc..) of the next instance of a specific class (findMe).

Here is my code:
HTML:

    <div class="container">
  <table>
    <tr id="test1" class="findMe">
      <td>
      <button class="next">Next</button>
      </td>
    </tr>
    <tr id="test2" class="findMe">
      <td>
      <button class="next">Next</button>
      </td>
    </tr>
  </table>
    <div id="test3" class="findMe">
    </div>
  </container>

JS:

$(".next").click(function() {
console.log($(this).parent().closest(".findMe").next().attr('id'));
})

I can find the ID “test2” but not “test3”. Why?

How to create a document with a subcollection within Firestore cloud function?

Hi I’d like to create the following document with the private subcollection, via a cloud function trigger:

enter image description here

This is what I have so far, but have no idea how to actually set a subcollection as well.

"use strict";
Object.defineProperty(exports, "__esModule", {value: true});

// Cloud Functions for Firebase SDK to create Cloud Functions + set up triggers.
const functions = require("firebase-functions");

// The Firebase Admin SDK to access Firestore.
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);

// Listen to .onCreate trigger
exports.createProfile = functions.auth.user().onCreate((user) => {
  return admin.firestore().doc(`/users/${user.uid}`).set({
    firstName: null,
    lastName: null,
    preferredName: null,
  });
});

Dropdown in modal is stuck even when modal is closed

I have a modal that has multiple things in it including dropdown. When I open modal and dropdown and click inside modal the dropdown and modal close properly. I also have cancel button and when I open dropdown and press cancel the modal and dropdown close properly. When I open modal and dropdown and click outside of modal, the modal closes but dropdown is stuck like this
enter image description here

My code for cancel button is

this.cancel = () => {
$uibModalInstance.dismiss('cancel'); };

How can I listen to outside click and call this method on event?

GDPR/RGPD and anonymous Google Analytics collect

I’m trying to avoid the annoying “consent to cookies” thing on my website. There’s no cookies at all except the one when you’re logged in.

I know that GDPR is not only about cookies but more widely about storing and sharing user data.

Currently what I’m about to do is to not insert GA javascript on my website but instead make a post request on the GA API collect endpoint. In this post request I set the aip argument (anonymize IP) and I’m using a totally random and anonymous client-side generated GUID as cid argument.

In order to not create a new GUID each time the same user come to my site, I store their GUID in the browser (localstorage).

I know that localstorage is also under GDPR laws, but since I’m using a totally random GUID and sending the pageview event directly without inserting any JS and using IP anonymization, I wonder if it’s mandatory to ask consent or even alert the user when they come on my website.

I mean actually there is no way for GA to know who’s the user and track them outside of my website, and I have no way to connect GUIDs with my user ids to know which of my users appear in GA reports. Users are totally anonymized.

Am I right or should I put at least a message to warn my users?

Thanks!