Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9164985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:48:40+00:00 2026-06-17T14:48:40+00:00

consider the following code: window.stage = bonsai.run(document.getElementById(‘stage’), { code: function() { var circle; circle

  • 0

consider the following code:

window.stage = bonsai.run(document.getElementById('stage'), {
  code: function() {
    var circle;
    circle = new Circle(200, 200, 50);
    circle.stroke('green', 2);
    circle.addTo(stage);
    circle.on('click', function(ev) {
      stage.sendMessage('click', ev);
    });
  },
  width: 500,
  height: 500
});

stage.on('load', function() {
  console.log('loaded');
  stage.on('message:click', function(ev) {
      console.log('click', ev);
  });
});

So, clicking on the circle gives me the error: DATA_CLONE_ERR: DOM Exception 25

If I just send out properties like ev.x and ev.y, they pass out just fine. I can also reconstruct the object from its properties before sending and it passes fine.

How can I send the event object out intact to the parent context without deconstructing-> reconstructing it? And by the way, why does bonsai work this way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:48:41+00:00Added an answer on June 17, 2026 at 2:48 pm

    Great that you’ve asked why we do the separation that way. Just went through the BonsaiJS documentation and realized that we don’t explicitely say a word about why we separate the rendering from the execution thread.

    BonsaiJS code is mostly executed in a worker (falls back to iframe, if workers aren’t available) and uses postMessage to communicate with the context which created the worker. The DATA_CLONE_ERR: DOM Exception 25 is raised because the DOM event object can’t be serialized by postMessage. To solve your problem, you could create a simple function, which removes all nested objects / functions of the object, which should be passed:

    window.stage = bonsai.run(document.getElementById('stage'), {
      code: function() {
        var circle;
        var makeSerializable = function(obj) {
          var ret = {}, val;
          Object.keys(obj).forEach(function(key) {
            val = obj[key];
            if (typeof val != 'object' && typeof val != 'function') {
              ret[key] = val;
            };
          });
          return ret; 
        };
        circle = new Circle(200, 200, 50);
        circle.stroke('green', 2);
        circle.addTo(stage);
        circle.on('click', function(ev) {
          stage.sendMessage('click', makeSerializable(ev));
        });
      },
      width: 500,
      height: 500
    });
    
    stage.on('load', function() {
      console.log('loaded');
      stage.on('message:click', function(ev) {
        console.log('click', ev);
      });
    });
    

    Or you can force BonsaiJS to be executed in an iFrame. Then you’ll have access to the DOM and you can serialize any object (note: see below, why I wouldn’t recommend that):

    window.stage = bonsai.setup({
      runnerContext: bonsai.IframeRunnerContext
    }).run({...});
    

    The main reason for putting the main code execution into a worker, is, that we don’t want any computation to block the rendering “thread”, so that we get more fluent animations (if the code is executed in an iFrame, rendering + code execution will happen in the same thread and it won’t be as fluent as with the worker). Another advantage of executing JS code in a worker, is, that we don’t rely on the DOM and can also take the same JS code and execute it in a different JS environment like Rhino or NodeJS (here is some example code, how you could execute BonsaiJS on node and send the rendering messages to the browser through SocketIO: https://github.com/uxebu/bonsai-server).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

consider the following code: <script> function testFunc(){ alert('test') } $(function(){ var g = document.getElementById
Consider the following code: $(window).unload(function () { console.log('foo'); }); If I trigger the unload
Consider the following code: $(document).ready(function() { $(body).append(<div class='outer'><span class='inner'>Click me</span></div>); $(html).click(function(event) { var targetClass
Consider the following code Class.prototype.init = function() { var self = this; var onComplete
Consider the following code: hashString = window.location.hash.substring(1); alert('Hash String = '+hashString); When run with
Consider the following code: (function() { var a = 5; var someFunc = function()
Consider the following code: function hide(aFrame) { var frameset = aFrame.frameset; //<-- this doesn't
consider the following python code: import gtk class MainWindow(): def __init__(self): self.window = gtk.Window()
This is rather interesting, I think. Consider following code, both the window.onload and body
Please consider the following code (also in this fiddle ): var viewModel = {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.