Skip to content

cy.serialize()

cy.serialize — Core > Export and snapshots > Graph data and wire format. Cytoscape.js signatures, parameters and return contract.

cy.serialize — Core › Export and snapshots › Graph data and wire format

Preview · Core › Export and snapshots › Graph data and wire format

Read in the complete API reference · All API members

// Export graph elements and graph-level data as a binary buffer
cy.serialize(): ArrayBuffer

Export graph elements and graph-level data as a binary buffer. Load it into a new instance with cytoscape({ elements: buffer }), or add its elements to an existing instance with cy.add(buffer).

The buffer carries element identity, positions, topology, selection and data. It excludes stylesheet, viewport and scratch. Constructor loading applies its graph-level data; add() leaves the destination's graph data unchanged.

Returns ArrayBuffer

a fresh little-endian buffer, self-contained (every edge endpoint indexes a node in the same payload) and directly loadable — derived geometry is flushed first, so parent boxes are the current ones rather than whatever was last materialized

Example

const buffer = cy.serialize();
const restored = cytoscape({ headless: true, elements: buffer });
console.log(restored.nodes().length); // 3
restored.destroy();

Example graph and handle setup