# How to copy & paste from/to different browser tabs

**URL:** <https://forum.bpmn.io/t/how-to-copy-paste-from-to-different-browser-tabs/1837>\
**Category:** Modeler\
**Created:** [October 10, 2017, 11:01am UTC](https://forum.bpmn.io/t/how-to-copy-paste-from-to-different-browser-tabs/1837 "2017-10-10T11:01:14Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbatllet](https://forum.bpmn.io/user_avatar/forum.bpmn.io/rbatllet/32/611_2.png) [@rbatllet](https://forum.bpmn.io/u/rbatllet)\
**Post date:** [October 10, 2017, 11:01am UTC](https://forum.bpmn.io/t/how-to-copy-paste-from-to-different-browser-tabs/1837/1 "2017-10-10T11:01:14Z")

</div>

I don’t find the success way to copy/paste elements from a browser tab to another one.

My idea is to save the content of the clipboard class into the HTML5 Web Storage (localStorage) this way:

```auto
       const getClipboard = modeler.get('clipboard').get();

       localforage.setItem('bpmn', getClipboard).then(value => {
          console.log('Value: ', value);
       }).catch(error => {
          console.log('Error: ', error);
       });

```

and restore it from localStorage before execute the paste action:

```auto
       localforage.getItem('bpmn').then(value => {
         modeler.get('clipboard').set(value);
         modeler.get('editorActions').trigger('paste');
       }).catch(error => {
         console.log('Error: ', error);
       });

```

---

<div class="post-metadata">

**Author:** ![nikku](https://forum.bpmn.io/user_avatar/forum.bpmn.io/nikku/32/5130_2.png) [@nikku](https://forum.bpmn.io/u/nikku)\
**Post date:** [October 11, 2017, 8:35am UTC](https://forum.bpmn.io/t/how-to-copy-paste-from-to-different-browser-tabs/1837/2 "2017-10-11T08:35:30Z")

</div>

Make sure that you `JSON.stringify` the clipboard contents and deserialize them before putting them back to the clipboard. Other than that, the code you’ve pasted looks good to me.

```javascript
// copy
var clipboardContents = JSON.stringify(modeler.get('clipboard').get());
localforage.setItem('bpmn', clipboardContents);

// paste
localforage.getItem('bpmn').then(function(value) {

  var clipboardContents = JSON.parse(value);
 
  modeler.get('clipboard').set(clipboardContents);
  modeler.get('editorActions').trigger('paste');
});

```

---

<div class="post-metadata">

**Author:** ![rbatllet](https://forum.bpmn.io/user_avatar/forum.bpmn.io/rbatllet/32/611_2.png) [@rbatllet](https://forum.bpmn.io/u/rbatllet)\
**Post date:** [October 11, 2017, 9:06am UTC](https://forum.bpmn.io/t/how-to-copy-paste-from-to-different-browser-tabs/1837/3 "2017-10-11T09:06:42Z")

</div>

I’ve detected the problem. It’s the JSON.stringify or the JSON.parser

If I do the following it crashes as well:

```auto
// copy and paste in the same function:
modeler.get('editorActions').trigger('copy');

var getClipboard = modeler.get('clipboard').get();

// it would return the origional clipboard content, not the case!
var myClipBoard = JSON.parse(JSON.stringify(getClipboard)); 

modeler.get('clipboard').set(myClipBoard);
modeler.get('editorActions').trigger('paste');

```

Something is getting lost when stringify or parse the content of the clipboard.

---

<div class="post-metadata">

**Author:** ![rbatllet](https://forum.bpmn.io/user_avatar/forum.bpmn.io/rbatllet/32/611_2.png) [@rbatllet](https://forum.bpmn.io/u/rbatllet)\
**Post date:** [October 11, 2017, 9:14am UTC](https://forum.bpmn.io/t/how-to-copy-paste-from-to-different-browser-tabs/1837/4 "2017-10-11T09:14:28Z")

</div>

Is there an alternative to JSON.stringify / JSON.parser to serialize data in Javascript?

---

<div class="post-metadata">

**Author:** ![nikku](https://forum.bpmn.io/user_avatar/forum.bpmn.io/nikku/32/5130_2.png) [@nikku](https://forum.bpmn.io/u/nikku)\
**Post date:** [October 11, 2017, 9:36am UTC](https://forum.bpmn.io/t/how-to-copy-paste-from-to-different-browser-tabs/1837/5 "2017-10-11T09:36:10Z")

</div>

It looks like the descriptor contains hidden, non-enumerable fields. Could you diff `getClipboard` and `JSON.parse(JSON.stringify(getClipboard))`?

---

<div class="post-metadata">

**Author:** ![rbatllet](https://forum.bpmn.io/user_avatar/forum.bpmn.io/rbatllet/32/611_2.png) [@rbatllet](https://forum.bpmn.io/u/rbatllet)\
**Post date:** [October 11, 2017, 11:50am UTC](https://forum.bpmn.io/t/how-to-copy-paste-from-to-different-browser-tabs/1837/6 "2017-10-11T11:50:02Z")

</div>

The original clipboard data is:

![18](https://forum.bpmn.io/uploads/default/original/1X/f4fcbfb6e48947d63523f943ee61b86ace319ae2.png)

The $descriptor and $model properties are read-only and cannot be copied.

* * *

The stringify and parsed clipboard data is:

![43](https://forum.bpmn.io/uploads/default/original/1X/5d12505aa839fc7c6faddcdde4d9322158a791de.png)

The \_\_proto\_\_properties inside oldBusinessObject have disappeared.

---

<div class="post-metadata">

**Author:** ![nikku](https://forum.bpmn.io/user_avatar/forum.bpmn.io/nikku/32/5130_2.png) [@nikku](https://forum.bpmn.io/u/nikku)\
**Post date:** [October 12, 2017, 2:17pm UTC](https://forum.bpmn.io/t/how-to-copy-paste-from-to-different-browser-tabs/1837/7 "2017-10-12T14:17:47Z")

</div>

So, we might assume inside our code that `oldBusinessObject` is an actual model instance rather than a plain object.

You could use the [second `reviver` argument to JSON#parse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) to re-instantiate the object(s) with the correct types based on the `$type` attribute.

---

<div class="post-metadata">

**Author:** ![nikku](https://forum.bpmn.io/user_avatar/forum.bpmn.io/nikku/32/5130_2.png) [@nikku](https://forum.bpmn.io/u/nikku)\
**Post date:** [October 12, 2017, 7:13pm UTC](https://forum.bpmn.io/t/how-to-copy-paste-from-to-different-browser-tabs/1837/8 "2017-10-12T19:13:37Z")

</div>

I’ve [created an example](https://github.com/nikku/bpmn-js-copy-paste-example) that should help you out.

---

<div class="post-metadata">

**Author:** ![rbatllet](https://forum.bpmn.io/user_avatar/forum.bpmn.io/rbatllet/32/611_2.png) [@rbatllet](https://forum.bpmn.io/u/rbatllet)\
**Post date:** [October 12, 2017, 9:37pm UTC](https://forum.bpmn.io/t/how-to-copy-paste-from-to-different-browser-tabs/1837/9 "2017-10-12T21:37:58Z")

</div>

Thank you very much for your interest and for the effort in the response.

I am very grateful. I take my hat off to you.

---

<div class="post-metadata">

**Author:** ![nikku](https://forum.bpmn.io/user_avatar/forum.bpmn.io/nikku/32/5130_2.png) [@nikku](https://forum.bpmn.io/u/nikku)\
**Post date:** [July 22, 2025, 3:12pm UTC](https://forum.bpmn.io/t/how-to-copy-paste-from-to-different-browser-tabs/1837/10 "2025-07-22T15:12:48Z")

</div>

Closed on July 22, 2025, 3:12pm UTC


