How to bind an SVG DOM Element in Svelte?

I have an SVG DOM Element Object that I would like to manage using the Svelte syntax (for example, adding a class). That Element only exists in memory, in the sense that it’s not appended to the body, therefore it is not visible on the page.

<script>
  // Create an SVG element
  let mySvg1 = document.createElementNS("http://www.w3.org/2000/svg", "svg");
  mySvg1.setAttribute("width", "100");
  mySvg1.setAttribute("height", "100");

  // Create a circle element
  let circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
  circle.setAttribute("cx", "50");
  circle.setAttribute("cy", "50");
  circle.setAttribute("r", "40");
  circle.setAttribute("fill", "red");

  // Append the circle to the SVG element
  mySvg1.appendChild(circle);

    console.log(mySvg1);
</script>
<style>
  #myThing {
    width: 100px;
    height: 100px;
    background-color: blue;
  }
</style>

I tried binding it like this

<svg id="myThing" bind:this={mySvg1}></svg>

But nothing appears on the page, and the SVG Element is not visible to the inspector.

Appending it to the body using document.body.appendChild(mySvg1) isn’t a fix , because this creates a second SVG, that doesn’t have the same content as the first.

The red circle doesn’t show up INSIDE the blue square, which means the SVG with ID “myThing” isn’t bound with the mySvg1 DOM Element.

screenshot

Reminder that you can copy and paste my code on Svelte’s repl https://svelte.dev/repl

So I end up with two SVGs Element instead of one, what can I do about it?

Change video src in Mac and iOS browsers?

The mediaRequest API returns a blob object.
I dynamically change src for video and image tags. This works on PC, Android browsers . Changing src for image tag also works on Mac Safari/iOS browsers .
Changing src for video tag does not work on Mac Safari/iOS. Black screen in video tag.There are no errors in the console.

Blob {size: 19390998, type: 'application/octet-stream'}

Code:

mediaRequest(media.id, media.contentType)
  .then((mediaRes) => {
    console.log(mediaRes);
    const container = document.querySelector(`.${typeChat}`);
    if (filetype === "image") {
      const mediaPlaceholder = container.querySelector(`img[data-media-id="${media.id}"]`);
      mediaPlaceholder.src = url.createObjectURL(mediaRes);
    } else if (filetype === "video") {
      const mediaPlaceholder = container.querySelector(`video[data-media-id="${media.id}"]`);
      mediaPlaceholder.src = url.createObjectURL(mediaRes);
    }
  })
  .catch((error) => console.log(error));

Does the URL.toString() Functon encode the URL

I have the following example code:

const url = new URL("http://example.com");
url.searchParams.append("name", "Mustermann");
url.searchParams.append("question", "how does the URL.toString() function work?");
window.open(url.toString(), '_self');

My question is does the URL encode the different searchParams?
If it encodes the URL what function does it use?
Is the encodeURI() Function or the encodeURIComponent() Function used or is it something different.

Encode javascript tags in HTML string in jQuery

I have a HTML string that can contain script tags as this:

<td class="datagrid-cell" style="text-align:center;" i18n="  
 <script>alert(1);</script>">
</td>

and when in my jQuery script I set the HTML in the container with

$(target).html(html);

and display the container, the script is execupted.
How can I encode the script so that is displayed as text?

Thanks

Get current route path during static render

I’m using Next.js (v14/app router) to generate a statically exported. However, in one of my layouts, I have a tab bar that allows switching between pages.

Very basic:

<div className="tabs">
    <Link
        href={`/post/${p.slug}`}
        className={true ? 'active' : ''}
    >All wins</Link>

    <Link
        href={`/post/${p.slug}/top`}
        className={true ? 'active' : ''}
    >Top wins</Link>

    <Link
        href={`/post/${p.slug}/stats`}
        className={true ? 'active' : ''}
    >Statistics</Link>
</div>

The problem lies with the active classname. Is there any way to get the current route of the page, so that I can simply do className={currentRoute === '/post/${p.slug}/stats' ? 'active' : ''}.

I know that there’s a usePathname method, but that seems to be a client component, and seems rather silly to do this on the client side, than during actually rendering the page.

After rendering the website into Render.com the design becomes Unresponsive

I’ve built a website and then deployed it to the server of Render.com. Although all the media queries were working whenever I changed the browser width while testing them on my computer before deploying. but now the website has become unresponsive to tablets/mobiles. my guess is the problem is because of package.json file, in the file it was "main": "app.js" but I had to change it to "default": "index.html" in order to build it using parcel and deploy it to Render.com. Otherwise, these two steps will fail. is it this really what caused the problem ? or something else ?

here is my current package.json file:

{
  "name": "serenebite",
  "version": "1.0.0",
  "default": "index.html",
  "scripts": {
    "start": "parcel index.html",
    "watch": "sass --watch sass/main.scss style.css",
    "build": "parcel build index.html"
  },
  "author": "Marya",
  "license": "ISC",
  "dependencies": {
    "gsap": "^3.12.2",
    "leaflet": "^1.9.4",
    "sass": "^1.69.3"
  },
  "description": "",
  "devDependencies": {
    "parcel": "^2.10.2"
  }
}

I’ve tried to write both "main": "app.js" and "default": "index.html"
but that keeps the deploying fails.

does anyone know how can I fix this problem?

Bypass CORS policy using proxy.conf.json in Angular

I’m trying to load a url in an iframe like

<div style="width: 100%; height: 100vh;">
    <iframe src="api/depune-petitie/" frameborder="0" style="width: 100%; height: 100%;"></iframe>
</div>

From my research I tried using proxy.config.json

{
  "/api": {
    "target": "https://spv.anre.ro",
    "secure": false,
    "changeOrigin": true,
    "logLevel": "debug",
    "pathRewrite": {
      "/api": "/"
    }
  }
}

The problem is that the first page loads, but when I try to navigate through the page, it no longer works because of Refused to display 'https://spv.anre.ro/' in a frame because it set 'X-Frame-Options' to 'same origin'.

And errors like

Access to XMLHttpRequest at 'https://spv.anre.ro/PORTAL/start_page.html' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Can someone help me how I could bypass all urls that use https://spv.anre.ro and subpaths?

Need to validate image height and width validation

I have implemented a jQuery code snippet to handle image uploads and wish to perform validation based on specific image dimensions. My current code includes functionality for uploading images, but I need to validate whether the uploaded images have the dimensions of 1000 pixels in width and 1250 pixels in height. Furthermore, if the dimensions do not match, I want to remove the preview of the invalid image.

Here’s the jQuery code I’m currently using:

 $("#thumbnail").spartanMultiImagePicker({
                    fieldName: 'image',
                    maxCount: 1,
                    rowHeight: 'auto',
                    groupClassName: 'col-12',
                    maxFileSize: '',
                    placeholderImage: {
                        image: '{{ asset('assets/back-end/img/400x400/img2.jpg') }}',
                        width: '100%',
                    },
                    dropFileLabel: "Drop Here",
                    onAddRow: function(index, file) {
    
                    },
                    onRenderedPreview: function(index) {
    
                    },
                    onRemoveRow: function(index) {
    
                    },
                    onExtensionErr: function(index, file) {
                        toastr.error(
                        '{{ AppCPUtranslate('Please only input png or jpg type file') }}', {
                            CloseButton: true,
                            ProgressBar: true
                        });
                    },
                    onSizeErr: function(index, file) {
                        toastr.error('{{ AppCPUtranslate('File size too big') }}', {
                            CloseButton: true,
                            ProgressBar: true
                        });
                    }
                });

[JS][Cucumber][Webdriverio][PerformanceTotal] How to run a command that performs an S3 upload AFTER ALL feature files/steps are executed?

I am currently executing some basic performance tests using the following:

STATUS: the performanceTotal package generates csv and json results files form where I extract information in order to generate a graph that measures the time it takes for changing a page, for example. The results files are generated ONLY AFTER ALL features/steps (including AfterAll) are executed.

ISSUE: in order to generate long term graphs with the results I am interested in, I plan on running the tests in Jenkins, but I need to upload the results files to S3 (upload request successful!) and since the tests results files are available only at the end of the execution, is there a way of executing the upload command “outside” or after the ending of the run?

Here is a snippet of the AfterAll step, where feat is an Array of the features I am testing and item is an object/feature from the array which is used for generating individual graphs. For example feat may contain: [Login, Logout, NavigationToPage_X, etc.]. result is a JSON with the extracted info from the results files used for graph generation.

AfterAll({timeout: 10 * 60000} ,async () => {
  logInfo("Starting generation of charts and upload of json result files to S3");
  await Promise.all(feat.map(async item => {
    await generatePerformanceChart(item, "line", result);
    await uploadResultsToS3(item);
  }));
  logSuccess("Upload of results files to S3 successful!");
});

But this doesn’t work as the results files are generated after the AfterAll step for some reason. I would require something that executes the upload command outside the Cucumber framework.

In Our project build is getting failed and error is showing fatal error: ‘RCTAppDelegate.h’ file not found

Our Project is Upgraded on Latest version of react-native. After running project for iOS on terminal iOS build is getting failed and below error is showing on terminal.
fatal error: ‘RCTAppDelegate.h’ file not found.

project is Running fine on Xcode and build is getting succeeded but not able to debugging code on metro or debugger is not opened after project is running on x-code.

Here I attached screenshot of errors.[error screenshot of image Xcode image of the project](https://i.stack.imgur.com/gtmXN.jpg)

We are trying solution belonging to build issue and using below command

pod init
pod install
still Not getting proper solution.

We are also compare pod file with other and also changed accordingly and deleted pod folder and podfile.lock but not yet resolved.

I was also added below target in podfile
target ‘MyNewTarget’ do
inherit! :complete
end

How to send large files to user? node-telegram-bot-api

bot.sendDocument(id, 'test.zip');
I have a 1.5GB file. But it is not sent to the user, it gives the following error
(Unhandled rejection Error: ETELEGRAM: 413 Request Entity Too Large)
I know that the limit is 2GB, but the file is not sent. Tell me what should I do?

I only tried this code
bot.sendDocument(id, 'test.zip');

Looking for ‘onChange’ but using ‘addEventListener’

I’m currently working on a React project.

I don’t want to add my ‘onChange’ in each button inside the html object like this:
<input type='text' onChange={myFunction} />

I want to add it in the JS code like this:
document.getElementById('myId').addEventListener('eventName', myFunction);

The problem is that my first though that the change event was the equivalent onChange inside the HTML, but I was wrong.
Actually, the change is working like a onBlur event but triggered only when the field got modified.

I also tried the keypress event like this:
document.getElementById('myId').addEventListener('eventName', myFunction);
But when I try to get the value with event.target.value, it gives me the value before input.

This problem is only related to textarea and input type='text'. select, input type='date' and other object on which we can click are not affected by this problem.

Is there a simple event working as the onChange inside the HTML ?

What happens with async await exactly?

I have such a piece of code

async function loop() {
  for (let i = 0; i < 3; i++) {
    console.log(i,new Error("").stack);
    await 1;
  }
}

loop();

when I run it in Node (Chrome engine) I get this:

0 Error
    at loop (file:///Users/user/Desktop/test.mjs:3:19)
    at file:///Users/user/Desktop/test.mjs:8:1
    at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:308:24)
    at async loadESM (node:internal/process/esm_loader:42:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12)
1 Error
    at loop (file:///Users/user/Desktop/test.mjs:3:19)
2 Error
    at loop (file:///Users/user/Desktop/test.mjs:3:19)

so it seems that after await the execution loses its broader context but retains the context of the function.

When I run the same piece of code in Bun (Safari engine) I get this:

0 Error: 
    at <anonymous> (/Users/user/Desktop/test.mjs:3:10)
    at loop (/Users/user/Desktop/test.mjs:1:22)
    at module code (/Users/user/Desktop/test.mjs:5:5)
1 Error: 
    at <anonymous> (/Users/user/Desktop/test.mjs:3:10)
2 Error: 
    at <anonymous> (/Users/user/Desktop/test.mjs:3:10)

which says that the execution loses even the context of the function.

Now, I know what happens when I use await like this, more or less. It forces stuff to be pushed to the micro task queue, lets the rest of the sync code on the stack execute, therefore we lose the stack, and picks up the stuff pushed to the queue afterwards.

However, I’m interested in how exactly this happens and looking at these different errors stacks I’m really confused. Are we in the same function after using await or is a new function created somehow with the context of the previous one?

How to conditionally populate documents in array in mongodb using mongoose

I want to get only that notifications of user which matched the status, from_date and to_date requested in req.query.

User Schema:

const userSchema = mongoose.Schema({
email: {
    type: String,
    required: true
},
password: {
    type: String,
    minlength: 8,
    required: true
},
notifications: [{
    notification: {
        type: mongoose.Schema.Types.ObjectId,
        ref: "Notification"
    },
    status: {
        type: String,
        enum: ["Not Acknowledged", "Acknowledged"],
        default: "Not Acknowledged"
    },
 }]
})

Notification Schema:

const notificationSchema = mongoose.Schema({
  description: {
      type: String
  },
  remind_on: {
      type: Date
  },
  remind_at: {
      type: Date
  },
});

I tried this , but it is giving all notifications.

  const statusQuery = {};
  if(status) {
    statusQuery.match = { 'notifications.status': status }
  }
  const searchNotifications = await User.findById(user._id)
    .populate({
      path: "notifications",
      ...statusQuery,
      populate: {
        path: "notification",
        populate: [
          { path: "assignee", select: "first_name last_name" },
          { path: "case", select: "case_id" },
        ],
      },
    })
    .select("notifications");

In the above code I first get the user document by user Id and that tried to add queries in populate