Questions tagged [structured-clone]
16 questions
19
votes
7 answers
"ReferenceError: structuredClone is not defined" using jest with nodejs & typescript
I'm running tests with jest in a simple NodeJS app that uses typescript. My test is throwing an error: ReferenceError: structuredClone is not defined.
I'm not getting any linter errors and the code compiles fine normally.
const…

JimmyTheCode
- 3,783
- 7
- 29
- 71
9
votes
1 answer
How to check if an object can be cloned by the structured clone algorithm
The structured clone algorithm is a serialization algorithm used, among other things, to pass data between windows via window.postMessage. It supports recursive objects (unlike JSON) but not things like DOM Nodes, Functions, and Errors, and…

Retsam
- 30,909
- 11
- 68
- 90
3
votes
1 answer
Custom property on File instance not cloned when passing to web worker
According to MDN, File objects can be passed to Web Workers and they are properly cloned using the structured cloning algorithm. So far, so good. And this works in all browsers I've tested:
// myFile comes from a form.
// webWorker is the WebWorker…

Raúl Núñez de Arenas Coronado
- 406
- 4
- 15
3
votes
1 answer
How to tell postMessage structured clone to ignore properties?
I'm working on a project where I need to create an object in an iframe and then send said object to the parent window.
The problem is the postMessage is failing as the object cannot be cloned (DataCloneError) as it has a function (callback)…

shaneod
- 49
- 1
- 7
1
vote
0 answers
Foreach with structuredClone run into RangeError
const result: Model[] = [];
array.forEach((element) => {
if (condition1)
result.push(structuredClone(element));
if (condition2)
result.push(structuredClone(element));
});
The object is nested:
export interface Model extends Dto {
…

Juri
- 1,531
- 2
- 20
- 43
1
vote
2 answers
structuredClone not available on global object in nodejs app
structuredClone doesn't work in my NodeJS app. When I try to use it I get the error: structuredClone is not defined nodejs.
If I create a simple file, and run:
console.log({
globals: Object.keys(global),
structuredClone:…

JimmyTheCode
- 3,783
- 7
- 29
- 71
1
vote
1 answer
Structured cloning - which thread does the clone?
I have some work being done on a WebWorker. When I post an object back to my GUI thread, the Javascript engine uses the structured cloning algorithm to clone the object with the GUI thread receiving a cloned object.
My question is, where is the…

Cheetah
- 13,785
- 31
- 106
- 190
1
vote
1 answer
What's the best option for structured cloning of a Fetch API Request Object?
I'm trying to store CSRF protected (querystring + cookie) API POST requests for later replay when a webapp comes back online.
To do this, I want to save the Request Object (Fetch API) in IndexedDB, but IDBObjectStore.put fails with a DataCloneError…

Alex Grant
- 363
- 3
- 10
0
votes
0 answers
structuredClone not keeping Date type
I'm using the structuredClone() global function in NodeJs 20.4.1 to clone an object that has a property of type Date. However, the clone object is not keeping the type of this object.
const originalObj = { myDate: new Date("2023-01-01 00:00:00")…

Diogo Domanski
- 483
- 1
- 4
- 7
0
votes
0 answers
Web-Worker with huge message
I'm currently facing a throttle with web-worker.
Here is what I'm trying to do:
Main thread: sends a request to web-worker
Web-worker: forward this request to a web service. The web service answers with ~1MiB of data
Web-worker: post processing the…

Raphallal
- 122
- 1
- 12
0
votes
1 answer
Why would structuredClone() ignore properties?
In a TypeScript web project I am using structuredClone to deep-clone an AxiosError object from the Axios library, defined as:
export interface AxiosError extends Error {
//...
isAxiosError: boolean;
toJSON: () => object;
}
interface…

Marco Eckstein
- 4,448
- 4
- 37
- 48
0
votes
1 answer
@electron/remote's getCurrentWindow doesn't return the full window object
When using @electron/remote, the results of remote.getCurrentWindow() lack all the additional properties/methods of the window that are accessible from the main process, and used to be accessible when using remote.getCurrentWindow() with the…

Slbox
- 10,957
- 15
- 54
- 106
0
votes
1 answer
How to pass array of transferable objects i.e. buffer along with non transferable object i.e. json obj via web worker in JavaScript - postMessage()?
So, here is what I am trying to achieve:
Call a specific function onMessage() in main thread from web-worker.
Passing an array of transferable objects i.e. Uint16Array buffer, Float32Array buffer etc.
Along with all of above, I want to pass a…

aman
- 47
- 5
0
votes
2 answers
How to append a data item to a deep nested array while keeping the original response data structure immutable?
I'm creating data per day and I'm dealing with following response data ...
{
tipster: {
name: "Gallita FC",
description: "TEST",
picks: [{
date: "Friday, February 18th 2022",
data: [{
title: "yesterday",
…

Rodrigo Ibarra
- 147
- 1
- 1
- 8
0
votes
0 answers
Most efficient way to update a already existing object(with a similar one)
What's up guys , I have a problem with atomics and this is where I'm at : I need to find the " most efficient way to alter one object with another.
Let's say I have object1 and I have object2 they are both identical in the fact they share the same…

static660
- 81
- 1
- 13