IPC send DOM object


I’m trying to send a cloned DOM element from a preloaded script in a webview through the IPC messaging system to my renderer process. Though, DOM elements are not able to be converted to JSON, and thus the received message is printing out an empty Object (Object {}). Here’s my code:

var ipc = require("electron").ipcRenderer;

function getData(element, trait){
  if(trait === "id"){
    var elem = document.getElementById(element);
    var elem = document.getElementsByClass(element);
  var cloned = elem.cloneNode(true);
  ipc.sendToHost("retrieve", cloned);

ipc.on("incoming", function(event, initData){
  getData(initData.selected, initData.trait);


loader.addEventListener("ipc-message", function (e) {
  if (e.channel === "retrieve") {
    console.log(e.args[0]);   // I want this to print out the DOM object

loader.addEventListener("dom-ready", function() {
  var x = marks.list[i];
  loader.send("incoming", x);    

I can’t just pick what I need out of the DOM, as I need everything inside the initData.selected's element and it’s attached CSS.

I’ve seen the issue here, but that was few months back.

Is there a potential fix for this? And if not, then is there any way possible to send a DOM element between these two processes, possibly with another program or node.js module? Thanks.


You cannot send such objects through IPC. You can send pure javascript Objects, Arrays, Strings and Numbers and that’s pretty much it, I think.