How to remove p5.js in browser extension with message

// get message
chrome.runtime.onMessage.addListener(gotMessage);
function gotMessage(message, sender, sendResponse) {
  runCanvas(message.val);
}

function runCanvas(value) {
  var stage = (p) => {
    if (value === "nn-edit") {
      createCanvas(p, value);
    }
    if (value === "nn-remove") {
      removeCanvas(p, value);
    }
  };

  let p5c = new p5(stage);
}

const createCanvas = (p, value) => {
  p.setup = () => {
    const parent = p.createDiv();
    parent.id("nn-div");
    if (value === "nn-edit") {
      const c = p.createCanvas(
        p.windowWidth - 20,
        document.documentElement.scrollHeight
      );
      c.parent("nn-div");
      c.position(0, 0);
      c.style("z-index", "10000");
      c.style("pointer-events", "none");
    }
  };
  p.draw = () => {
    const v = p.parent("nn-div");
    v.line(p.mouseX, p.mouseY, p.pmouseX, p.pmouseY);
  };
};

const removeCanvas = (p, value) => {
  if (value === "nn-remove") {
    $("#nn-div").remove();
  }
};

this is my code for the chrome extension, how to remove p5 from the content page with loop draw?