Application pop-up not appearing when browser launched via playwright


<!-- SELECTED FORM START -->
<br style="font-size:1px;line-height:0;">
<div id="hiddenFilterValues">
   <input type="hidden" name="fdsIdOpFilter" value="IN">
   <input type="hidden" name="fdsIdsFilter" value="">
   <input type="hidden" name="fdsDescriptionFilter" value="">
   <input type="hidden" name="fieldDelimiter" value=";">
   <input type="hidden" name="orderByFilter" value="">
   <input type="hidden" name="orderBy" value="">
   <input type="hidden" name="orderByDirection" value="desc">
</div>
<!-- This will receive a copy of the content of the selectedTable -->
<div id="selectedTableCopyDiv" style="display:none;"></div>
<!-- SELECTED FORM END -->
<!-- BUTTONS START -->
<br>
&nbsp;
<input type="button" id="rules" name="rules" value="Rules" class="button-raised-primary" onclick="execute(this.form, 'rules');" accesskey="" style="">
&nbsp;
<input type="button" id="marketReport" name="marketReport" value="Launch market report" class="button-raised-primary" onclick="execute(this.form, 'marketReport');" accesskey="" style="">
&nbsp;
<input type="button" id="factReport" name="factReport" value="Launch fact report" class="button-raised-primary" onclick="execute(this.form, 'factReport');" accesskey="" style="">
</tr>
</tbody></table>
</div>
<!-- BUTTONS END -->
<iframe id="dummyIframe" name="dummyIframe" class="objecthidden" height="0"></iframe>
<input type="text" name="dummyInput" size="1" class="objecthidden" readonly="" disabled="">
</form> 

This is my HTML
When i click to marketReport button the alert pop-up should appear but through playwright browser nothing is happening.Also in console execute function is not searchable which if i search through manually launched browser it works fine.How i can handle the button clicks which should open the alert pop-up in playwright
Button clicks should throw alert pop-up every time.

How to add images in embedded code on Webflow?

I am trying to add a carousel to my website on webflow and I have used to embed code feature. I have added the HTML, CSS and JavaScript all together because I’m not sure how to do that on seperate files in Webflow. I have also added 3 images to the carousel but when i publish the website and view it, the functionality of the carousel works but does not show the images. I have put down the path as: images/image1.jpg as that is what is used for other images.

<head>
    <meta charset="UTF-8">
    <title>Simple Image Carousel</title>
    <style>
        .carousel {
            position: relative;
            width: 600px;
            margin: auto;
            overflow: hidden;
            border: 1px solid #ddd;
        }

        .carousel-inner {
            display: flex;
            transition: transform 0.5s ease-in-out;
        }

        .carousel-item {
            min-width: 100%;
            box-sizing: border-box;
        }

        .carousel-item img {
            width: 100%;
            display: block;
        }

        .carousel-control {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            background-color: rgba(0,0,0,0.5);
            border: none;
            color: white;
            font-size: 2em;
            padding: 5px 10px;
            cursor: pointer;
            user-select: none;
        }

        .carousel-control.prev {
            left: 10px;
        }

        .carousel-control.next {
            right: 10px;
        }
    </style>
</head>
<body>

<div class="carousel">
    <div class="carousel-inner">
        <div class="carousel-item active">
            <img src="images/image1.jpg" alt="Slide 1">
        </div>
        <div class="carousel-item">
            <img src="images/image2.jpg" alt="Slide 2">
        </div>
        <div class="carousel-item">
            <img src="images/image3.jpg" alt="Slide 3">
        </div>
    </div>
    <button class="carousel-control prev" onclick="prevSlide()">&#10094;</button>
    <button class="carousel-control next" onclick="nextSlide()">&#10095;</button>
</div>

<script>
    let currentIndex = 0;
    const items = document.querySelectorAll('.carousel-item');
    const totalItems = items.length;

    function updateCarousel() {
        items.forEach((item, index) => {
            item.classList.remove('active');
            if (index === currentIndex) {
                item.classList.add('active');
            }
        });
        const carouselInner = document.querySelector('.carousel-inner');
        carouselInner.style.transform = 'translateX(-' + (currentIndex * 100) + '%)';
    }

    function nextSlide() {
        currentIndex = (currentIndex + 1) % totalItems;
        updateCarousel();
    }

    function prevSlide() {
        currentIndex = (currentIndex - 1 + totalItems) % totalItems;
        updateCarousel();
    }
</script>
</body>

I have put down the path as: images/image1.jpg as that is what is used for other images.

Find index in map object using JavaScript

If we want to find index in array of objects, it’s pretty simple. Example below

let a = [
  {prop1:"abc",prop2:"qwe"},
  {prop1:"bnmb",prop2:"yutu"},
  {prop1:"zxvz",prop2:"qwrq"}];
    
let index = a.findIndex(x => x.prop2 ==="yutu");

console.log(index);

I have a map object as shown below

let input = new Map([
    [ 
      "gfg4343434333r",
      { "group": 1, "groupId": "ae027a9e56a2" }
    ],
    [ 
       "5ae027a9e56a2",
        { "group": 2, "groupId": "434346456454" }
    ],
    [ 
        "de027a9e56a2",
        { "group": 3, "groupId": "43343vvfbrrt4445" }
    ],
])

As you can see this map object has a key value pair. suppose I have a input2 as 5ae027a9e56a2 I need to find out which key matches with this input2 and get its position in input. In this case 5ae027a9e56a2 matches with the 2nd element. Once it matches, I want to know the index so that I can go one level above and gets its previous element value.

How do I find the index in map object and how to get to index-1 in such cases? Can someone please shed some light here.?

Tracking down the root cause of unexpected reactivity in Vue 3 components

I am currently working on a fairly simple Vue-3 app, but experiencing an issue I’m not sure how to find the root cause of. In my app I have a view which is being rendered via the router. This view has some simple state (an object ref for storing the values of some text fields, and a boolean ref for toggling a modal on and off), and also makes use of a single state object from a pinia store.

The very first time I load the view I can edit the text fields which are bound to the object ref with ease, but the very first time I attempt to open the modal by clicking a button two things happen: The text fields are cleared, and the modal fails to open. After the button has been clicked the very first time, everything works the way I expect, and I can open and close the modal without disrupting the state of the view.

I have attempted adding watchers to all of the internal state refs so I can see if the values are changing, but I am not seeing those watchers triggered when the text fields are cleared after the first button click, and I’m at a loss for figuring out what might be causing this reactivity to occur.

For context, here is the code of the view (TemplateEditorView.vue):

<script setup>

import TemplateSelectorComponent from '../components/TemplateSelectorComponent.vue'
import useTemplate from '../composables/useTemplate'
import { computed, ref, watch } from 'vue'
import AddSectionModal from '../components/AddSectionModal.vue'
import { useTemplateStore } from '../stores/template'
import { storeToRefs } from 'pinia'

const templateStore = useTemplateStore()
const { templates } = storeToRefs(templateStore)
const { selectedTemplate, selectedTemplateKey, updateSelectedTemplateKey } = useTemplate()

const newTemplate = ref({
    id: '',
    name: '',
    templateText: '',
    sections: []
})
const showModal = ref(false)

const handleModalSubmit = function (section) {
    newTemplate.value.sections.push(section)
    showModal.value = false
}

const handleSave = function () {
    if (saveEnabled.value) {
        templates.value[newTemplate.value.id] = newTemplate.value
        clearForm()
    }
}

function clearForm() {
    newTemplate.value = {
        id: '',
        name: '',
        templateText: '',
        sections: []
    }
}

const handleDelete = function () {
    if (deleteEnabled.value) {
        delete templates.value[selectedTemplateKey.value]
        clearForm()
    }
}

const deleteEnabled = computed(() => {
    return Object.hasOwn(templates.value, selectedTemplateKey.value)
})

const saveEnabled = computed(() => {
    return newTemplate.value.id && newTemplate.value.name && newTemplate.value.templateText
})

watch(selectedTemplate, async () => {
    newTemplate.value = selectedTemplate.value
})
</script>

<template>
    <div id="template-editor-view-content" class="row p-1 pt-4">
        <div class="col">
            <div class="row">
                <div class="col"><h1>Template Editor</h1></div>
            </div>
            <div class="row">
                <div id="options-column" class="col-4 primary-bordered vh-85">
                    <div class="row pt-3">
                        <div class="col"><h2 class="text-center">Template Options</h2></div>
                    </div>
                    <TemplateSelectorComponent @selected-template-changed="updateSelectedTemplateKey" />
                    <div class="row">
                        <div class="col">
                            <h3 class="text-center">Global Variables</h3>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col">
                            <div id="globalVarsAccordion" class="accordion">
                                <div class="accordion-item">
                                    <h2 id="companyNameAccordionHeader" class="accordion-header">
                                        <button
                                            class="accordion-button"
                                            type="button"
                                            data-bs-toggle="collapse"
                                            data-bs-target="#companyNameAccordionBody"
                                            aria-expanded="false"
                                            aria-controls="companyNameAccordionBody"
                                        >
                                            Company Name
                                        </button>
                                    </h2>
                                    <div
                                        id="companyNameAccordionBody"
                                        class="accordion-collapse collapse"
                                        aria-labelledby="companyNameAccordionHeader"
                                        data-bs-parent="#globalVarsAccordion"
                                    >
                                        <div class="accordion-body">
                                            <ul class="list-group list-group-horizontal">
                                                <li class="list-group-item">isSelected</li>
                                                <li v-pre class="list-group-item">{{ companyName.isSelected }}</li>
                                            </ul>
                                            <ul class="pt-2 list-group list-group-horizontal">
                                                <li class="list-group-item">value</li>
                                                <li v-pre class="list-group-item">{{ companyName.value }}</li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                                <div class="accordion-item">
                                    <h2 id="jobTitleAccordionHeader" class="accordion-header">
                                        <button
                                            class="accordion-button"
                                            type="button"
                                            data-bs-toggle="collapse"
                                            data-bs-target="#jobTitleAccordionBody"
                                            aria-expanded="false"
                                            aria-controls="jobTitleAccordionBody"
                                        >
                                            Job Title
                                        </button>
                                    </h2>
                                    <div
                                        id="jobTitleAccordionBody"
                                        class="accordion-collapse collapse"
                                        aria-labelledby="jobTitleAccordionHeader"
                                        data-bs-parent="#globalVarsAccordion"
                                    >
                                        <div class="accordion-body">
                                            <ul class="list-group list-group-horizontal">
                                                <li class="list-group-item">isSelected</li>
                                                <li v-pre class="list-group-item">{{ jobTitle.isSelected }}</li>
                                            </ul>
                                            <ul class="pt-2 list-group list-group-horizontal">
                                                <li class="list-group-item">value</li>
                                                <li v-pre class="list-group-item">{{ jobTitle.value }}</li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <template v-if="newTemplate.sections">
                        <div class="row">
                            <div class="col">
                                <h3 class="text-center">Template Variables</h3>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col">
                                <div id="templateVarsAccordion" class="accordion">
                                    <div
                                        v-for="section in newTemplate.sections"
                                        :key="section.key"
                                        class="accordion-item"
                                    >
                                        <h2 id="`${section.key}AccordionHeader`" class="accordion-header">
                                            <button
                                                class="accordion-button"
                                                type="button"
                                                data-bs-toggle="collapse"
                                                data-bs-target="#`${section.key}AccordionBody`"
                                                aria-expanded="false"
                                                aria-controls="`${section.key}AccordionBody`"
                                            >
                                                {{ section.label }}
                                            </button>
                                        </h2>
                                        <div
                                            id="`${section.key}AccordionBody`"
                                            class="accordion-collapse collapse"
                                            aria-labelledby="`${section.key}AccordionHeader`"
                                            data-bs-parent="#templateVarsAccordion"
                                        >
                                            <div class="accordion-body">
                                                <ul class="list-group list-group-horizontal">
                                                    <li class="list-group-item">isSelected</li>
                                                    <li class="list-group-item">
                                                        <span v-pre>{{</span> {{ section.key }}.isSelected <span v-pre>}}</span>
                                                    </li>
                                                </ul>
                                                <ul class="pt-2 list-group list-group-horizontal">
                                                    <li class="list-group-item">value</li>
                                                    <li class="list-group-item">
                                                        <span v-pre>{{</span> {{ section.key }}.value <span v-pre>}}</span>
                                                    </li>
                                                </ul>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </template>
                </div>
                <div id="working-area" class="col vh-85">
                    <form class="row gx-3 align-items-center pb-3 pt-2">
                        <div class="col-auto">
                            <label for="templateKeyInput" class="col-form-label-lg">Template ID</label>
                        </div>
                        <div class="col">
                            <input
                                id="templateKeyInput"
                                v-model="newTemplate.id"
                                type="text"
                                class="form-control form-control-lg"
                            />
                        </div>
                        <div class="col-auto">
                            <label for="templateNameInput" class="col-form-label-lg">Template Name</label>
                        </div>
                        <div class="col">
                            <input
                                id="templateNameInput"
                                v-model="newTemplate.name"
                                type="text"
                                class="form-control form-control-lg"
                            />
                        </div>
                    </form>
                    <form class="row text-center justify-content-center">
                        <div class="col-2">
                            <button class="btn btn-secondary" @click="showModal = true">Add Section</button>
                        </div>
                        <div class="col-2">
                            <button class="btn btn-success" :disabled="!saveEnabled" @click="handleSave">
                                Save Template
                            </button>
                        </div>
                        <div class="col-2">
                            <button class="btn btn-danger" :disabled="!deleteEnabled" @click="handleDelete">
                                Delete Template
                            </button>
                        </div>
                    </form>
                    <div class="row pt-3">
                        <div class="col">
                            <textarea
                                id="templateTextArea"
                                v-model="newTemplate.templateText"
                                class="form-control"
                            ></textarea>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <AddSectionModal :show="showModal" @close="showModal = false" @submit="handleModalSubmit" />
    </div>
</template>

<style scoped>
// Some css
</style>

The modal which is being created is defined as follows (AddSectionModal.vue):

<script setup>
import GenericModal from './GenericModal.vue'
import { computed, ref } from 'vue'

defineProps({
    show: Boolean
})
const emit = defineEmits(['close', 'submit'])

const section = ref({
    key: '',
    label: '',
    text: '',
    isSelected: false
})

function clearState() {
    section.value = {
        key: '',
        label: '',
        text: '',
        isSelected: false
    }
}

const submitEnabled = computed(() => {
    return section.value.key && section.value.text && section.value.label
})

const handleClose = function () {
    clearState()
    emit('close')
}

const handleSubmit = function () {
    if (submitEnabled.value) {
        const value = section.value
        clearState()
        emit('submit', value)
    }
}
</script>

<template>
    <Teleport to="body">
        <GenericModal :show="show">
            <template #header>
                <h5 class="mx-auto">Add New Section</h5>
            </template>

            <template #body>
                <div class="container">
                    <div class="row gx-3 align-items-center">
                        <div class="col-3">
                            <label for="sectionKey" class="col-form-label-lg">Section Key</label>
                        </div>
                        <div class="col">
                            <input
                                v-model="section.key"
                                name="sectionKey"
                                type="text"
                                class="form-control form-control-lg"
                            />
                        </div>
                    </div>
                    <div class="row pt-2 gx-3 align-items-center">
                        <div class="col-3">
                            <label for="sectionLabel" class="col-form-label-lg">Section Label</label>
                        </div>
                        <div class="col">
                            <input
                                v-model="section.label"
                                name="sectionLabel"
                                type="text"
                                class="form-control form-control-lg"
                            />
                        </div>
                    </div>
                    <div class="row pt-2 gx-3 align-items-center">
                        <div class="col-3">
                            <label for="sectionText" class="col-form-label-lg">Section Text</label>
                        </div>
                        <div class="col">
                            <input
                                v-model="section.text"
                                name="sectionText"
                                type="text"
                                class="form-control form-control-lg"
                            />
                        </div>
                    </div>
                </div>
            </template>

            <template #footer>
                <div class="row gx-1 float-end">
                    <div class="col">
                        <button class="btn btn-danger" @click="handleClose">Cancel</button>
                    </div>
                    <div class="col">
                        <button class="btn btn-success" :disabled="!submitEnabled" @click="handleSubmit">
                            Submit
                        </button>
                    </div>
                </div>
            </template>
        </GenericModal>
    </Teleport>
</template>

And the GenericModal implementation is as follows (GenericModal.vue):

<template>
    <Transition name="modal">
        <div v-if="show" class="modal-mask">
            <div class="modal-container">
                <div class="modal-header">
                    <slot name="header">default header</slot>
                </div>

                <div class="modal-body">
                    <slot name="body">default body</slot>
                </div>

                <div class="modal-footer">
                    <slot name="footer">
                        default footer
                        <button class="modal-default-button" @click="$emit('close')">OK</button>
                    </slot>
                </div>
            </div>
        </div>
    </Transition>
</template>

<style>
// Some CSS
</style>

What strategies could I use to track down the source of the unexpected reactivity?

Convert Blob to wav file in js to send it in the body of a POST request

I’m working on a project where I need to send an audio file through a form-data body in a POST request.
But the audio file comes from the browser, recording my microphone and giving me a blob of the record.
I need to convert this blob to a wav/mp3 file and send it to my request.
Here is the blob I get :
raw code of the blob
So, how can I properly convert it to an audio file and send it in a form-data body in my fetch function ?
Thanks a lot !

I tried to parse the blob, to stringify it, but nothing worked for me.

Vue – v-if not updating with onMounted

I’m simply trying to make a div only appear once a variable changes from false to true and I’m telling it to change the value once the component is mounted. However the v-if which is supposed to be looking for that change is not working to create the div.

<script setup>
  import { onMounted } from 'vue'

  let onceMounted = false
  
  onMounted(() => {
    onceMounted = true
    console.log(onceMounted)
  });
<div>
  Hello
  <div v-if="onceMounted === true">
    World
  </div>
</div>

The console log confirms it changing fine, just the v-if isn’t updating. I’ve checked using v-show after checking out other questions on here like this one. I’m guessing there’s something I’m just missing?

d3js pie chart with rounded segments

I am trying to experiment with different styles for the d3.js charts I have — I am unsure how you would round the segments of the pie chart to mirror this design example.

Labels in rounded boxes, segments slightly gapped with rounded edges – in this design the segments have different heights maybe relating to the value?

enter image description here

https://codesandbox.io/p/sandbox/magical-wiles-forked-cxhmky

the current code for a regular pie

import React from 'react';
import * as d3 from 'd3';
import './PieChart1.scss';

class PieChart extends React.Component {
    constructor(props) {
        super(props);
        this.myRef = React.createRef();
        this.state = {
            data: [],
            theme: this.props.theme ? this.props.theme : ['#bde0fe', '#2698f9', '#71bcfd', '#f1f8fe']
        };
    }

    componentDidMount() {
        var $this = this.myRef.current;

        d3.select($this)
            .selectAll('svg')
            .remove();

        const data = this.props.data;

        const width = parseInt(this.props.width, 10),
            height = parseInt(this.props.height, 10),
            radius = parseInt(this.props.r, 10),
            innerradius = parseInt(this.props.ir, 10);

        var color = d3.scaleOrdinal().range(this.state.theme);

        var arc = d3
            .arc()
            .outerRadius(radius)
            .innerRadius(innerradius);

        data.forEach(function(d) {
            d.total = +d.value;
        });

        var pie = d3
            .pie()
            .sort(null)
            .value(function(d) {
                return d.total;
            });

        var svg = d3
            .select($this)
            .append('svg')
            .attr('width', width)
            .attr('height', height)
            .append('g')
            .attr('class', 'piechart')
            .attr('transform', 'translate(' + width / 2 + ',' + height / 2 + ')');

        var segments = svg.append('g').attr('class', 'segments');

        var slices = segments
            .selectAll('.arc')
            .data(pie(data))
            .enter()
            .append('g')
            .attr('class', 'arc');

        slices
            .append('path')
            .attr('d', arc)
            .attr('fill', function(d, i) {
                return color(i);
            })
            .transition()
            .attrTween('d', function(d) {
                var i = d3.interpolate(d.startAngle+0.1, d.endAngle);
                return function(t) {
                    d.endAngle = i(t);
                    return arc(d);
                }
            });

    }

    render() {
        return <div ref={this.myRef} className="PieChart" />;
    }
}
export default PieChart;

Render during array updates

I have a Vue3 component where I can drag a file, get the stream end do the decoding.
The result of that decoding is an iterator, messages in this case.
I see all results after everything is done, but I would like to see the results faster. Is there a way to force the render faster?

Here is an example. With console.log I see the messages decoding, but there is nothing rendered until all is done. I tried updating messages in other ways like messages.value = [...messages.value, msg], but with the same result.

<script setup>
import { ref } from 'vue'

let messages = ref([])

async function processFile(file) {
    const messages = await Foo.decode(file.stream())
    for await (var msg of messages()) {
      console.log({msg})
      messages.value.push(msg)
    }
}

function handleDrop(ev) {
  if (ev.dataTransfer.items) {
    ;[...ev.dataTransfer.items].forEach((item) => {
      if (item.kind === 'file') {
        const file = item.getAsFile()
        processFile(file)
      }
    })
  } else {
    // Use DataTransfer interface to access the file(s)
    ;[...ev.dataTransfer.files].forEach((file) => {
      processFile(file)
    })
  }
}
</script>

<template>
  <div
    class="dropzone"
    v-on:dragover.prevent="() => ..."
    v-on:drop.prevent="handleDrop"
    v-on:dragleave.prevent="() => ..."
  >
    Drop here
  </div>
  <div v-for="(message, index) in messages" :key="index">
    {{message.something}}
  </div>
</template>


What are some tips for learning javascript basics? It seems the React and Next.js combo is a common setup for custom web development. Thoughts? [closed]

I’ve built WordPress websites for many years and am now interested in developing fully custom websites. Is Javascript, React and Next.js a good place to begin?

Is learning basics on Codecademy worth it or are there better ways to learn?

Thank you

Codecademy courses
Comfortable with CSS and HTML

there are some strange lines on some of the IOS phones, when my website is loading

see the problem here:

https://drive.google.com/file/d/1WkTjEuMzF_r4HZjSv-781npn4cz4mKA2/view?usp=sharing (https://i.sstatic.net/KpaZEBGy.jpg

ignore the glitch property i commented it

<div class="loaderr">
        <div class="loader-bg"></div>
        <img src="assets/images/load-star.svg" alt="">
    </div>
/* Home Loader */
.loaderr {
    position: fixed;
    z-index: 1000;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000000;
    transition: all 0.3s;
    opacity: 1;
    pointer-events: all;
    display: flex;
    justify-content: center;
    align-items: center;
}

.loader-bg {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    background: #fff;
    border-radius: 0px;
    z-index: -1;
    transition: all 1.3s;
    transform: scale(1);
}

.loaderr img {
    width: 100%;
    max-width: 116px;
    display: block;
    object-fit: contain;
    /* filter: url(#feaute-demo-filter-3); */
}

/* Home Loader End */

.load-layer {
    position: fixed;
    z-index: 999;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000000;
    transition: all 0.2s;
    opacity: 1;
    pointer-events: all;
}

.load-layer.hidden {
    opacity: 0;
    pointer-events: none;
}
if (document.querySelector(".loaderr")) {

        gsap.matchMedia().add("(min-width: 1024px)", () => {
            homeLoadTl.to(".loader-bg", {
                height: "304px",
                width: "110px",
                borderRadius: "10px",
                ease: "none",
                duration: 1,
                delay: 1,
                onComplete: () => {
                    loadIGlitch()
                },
            })
        });
        gsap.matchMedia().add("(max-width: 1023px)", () => {
            homeLoadTl.to(".loader-bg", {
                height: "186px",
                width: "67px",
                borderRadius: "10px",
                ease: "none",
                duration: 1,
                delay: 1,
                onComplete: () => {
                    loadIGlitch()
                },
            })
        });

I want the same animation but in some iphones users are facing this problem,
check the site : https://orbital.frototype.agency/

we have tried by clearing cache and doing hard reload even cleared complete data of browser but still facing.

Communication with Springboot server and javascript

I’ve build a couple scrappers using puppeteer lately, and im working on creating statistics based on the output of the scrappers using java. I was using java run time and processes to parse the scrapper’s output in java, but i wanted to try and learn a bit of springboot.

i’ve built a Controller file in js to manage the posts and call a bot depending on the input the post gets.

For all of this to work, i had to setup a port for js, and send the http post to that port. The thing is i didnt want to manually start the js Controller, so i use processbuilder in java, only for it to practically start the “js server”.

The code in java side looks like this:

ProcessBuilder processBuilder = new ProcessBuilder();
      processBuilder.command("node", "./lib/webs/BotController.js");
        processBuilder.inheritIO();

        Process p =   processBuilder.start();
        long pid=p.pid();
        System.out.println(pid);
        
        Thread.sleep(5000);
        
        
        ConfigurableApplicationContext context = SpringApplication.run(DemoApplication.class);

pdfMake .getBuffer doesnt work in jest test

To test pdf i need to get buffer after generating it. But .getBuffer() doesnt seem to work in test environment.

Now I’m trying to at least banally output the buffer to the console, but nothing is showing. But when i run my app and try to run this code it works like it should and i see buffer in output. Why its not working in jest? Document generates correct neither getBuffer() nor getBlob() doesnt work when i call.

Idk if it will help bu theres my code example

describe('pdf should generate right', () => {
    it('should generate right document', async () => {

        const genDoc = await GenerateDocument(dd); // <- returns document created with .createPdf()

        genDoc.getBuffer((buffer)=>{
            console.log(buffer);  // < - doesnt output anything
        })

    })
})

offline service worker not working properly in google dev tools

I have been leaning to make PWA and I have notice google dev tools are not properly simulating offline feature of service worker.

enter image description here

I am talking about this feature showed in image.
I am using

package.json

"devDependencies": {
    "http-server": "^0.9.0"
  }

for localhost web server

SW.js file

var CACHE_STATIC_NAME = 'static-v10';
var CACHE_DYNAMIC_NAME = 'dynamic-v2';

self.addEventListener('install', function(event) {
  console.log('[Service Worker] Installing Service Worker ...', event);
  event.waitUntil(
    caches.open(CACHE_STATIC_NAME)
      .then(function(cache) {
        console.log('[Service Worker] Precaching App Shell');
        cache.addAll([
          '/',
          '/index.html',
          '/offline.html',
          '/src/js/app.js',
          '/src/js/feed.js',
          '/src/js/promise.js',
          '/src/js/fetch.js',
          '/src/js/material.min.js',
          '/src/css/app.css',
          '/src/css/feed.css',
          '/src/images/main-image.jpg',
          'https://fonts.googleapis.com/css?family=Roboto:400,700',
          'https://fonts.googleapis.com/icon?family=Material+Icons',
          'https://cdnjs.cloudflare.com/ajax/libs/material-design-lite/1.3.0/material.indigo-pink.min.css'
        ]);
      })
  )
});

self.addEventListener('activate', function(event) {
  console.log('[Service Worker] Activating Service Worker ....', event);
  event.waitUntil(
    caches.keys()
      .then(function(keyList) {
        return Promise.all(keyList.map(function(key) {
          if (key !== CACHE_STATIC_NAME && key !== CACHE_DYNAMIC_NAME) {
            console.log('[Service Worker] Removing old cache.', key);
            return caches.delete(key);
          }
        }));
      })
  );
  return self.clients.claim();
});

self.addEventListener('fetch', function(event) {
  event.respondWith(
    caches.match(event.request)
      .then(function(response) {
        if (response) {
          return response;
        } else {
          return fetch(event.request)
            .then(function(res) {
              return caches.open(CACHE_DYNAMIC_NAME)
                .then(function(cache) {
                  cache.put(event.request.url, res.clone());
                  return res;
                })
            })
            .catch(function(err) {
              return caches.open(CACHE_STATIC_NAME)
                .then(function(cache) {
                  return cache.match('/offline.html');
                });
            });
        }
      })
  );
});

this is service worker file. I am trying to show offline.html page if any page

let me know if you need any thing more regarding project I am working with

How to group and find average of object in nested arrays?

I have an array like this where an object is inside nested arrays:

let arr = [
    [
        {date: 1578787200000, displacement: 0},
        {date: 1580860800000, displacement: 1},
        {date: 1593302400000, displacement: 2},
        {date: 1606780800000, displacement: 3}
    ],
    [
        {date: 1578787200000, displacement: 10},
        {date: 1580860800000, displacement: 20},
        {date: 1593302400000, displacement: 30},
        {date: 1606780800000, displacement: 40}
    ]
]

and want to group the objects by ‘date’ whilst also averaging the ‘displacement’ values so the result looks like this:

[
    {date: 1578787200000, displacement: 5},
    {date: 1580860800000, displacement: 10.5},
    {date: 1593302400000, displacement: 16.5},
    {date: 1606780800000, displacement: 21.5}
]

I have tried .reduce() combined with .forEach() to sum the displacements per date but can’t get it to output exactly what I’m after.
e.g.

let res = arr.reduce(function (prev, currentArr) {
    currentArr.forEach(function (obj) {
        (prev.date == obj.date || []).push(prev.displacement + obj.displacement)
    }, 0);
    return prev;
});

What is the best way to accomplish this?

Stream Audio from another tab to Google Meet tab using Chrome Extension

During virtual calls with friends (in Chrome and over Google Meet), I would like to stream radio for the participants. The usual way for me is to play the Radio over speakers in another tab, turn on the microphone on the GMeet tab, and let the microphone capture the audio from the Speaker. I want to know if bypassing this by using a Chrome extension is possible. The steps are,

  1. Capture the audio from Radio (can be done using tabCapture) — DONE
  2. Play the audio in the Google Meet tab so that participants can hear it (??) — PENDING

Any help with the 2nd step will be appreciated.

Thanks.