How to access native 2d context

How to access native 2d canvas context from Konva

Konva gives you object model for drawing shapes on canvas. Your app is starting from a stage (div wrapper) and then the stage have one or many layers (canvas DOM elements) inside.

You can hijack into Konva internals (or DOM internals) and draw into canvas directly without creating any shapes. But that is not recommended. Because Konva has full control over drawing and may reset your manual drawings or lost them on any export such as stage.toDataURL().

There are two recommended ways if you want to draw something manually:

  1. Use custom shape
  2. Create a new canvas element manually and then use it for Konva.Image.
Konva 20000 Nodes Demoview raw
<!DOCTYPE html>
<script src="[email protected]/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Native Context Demo</title>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;

<div id="container"></div>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height

var layer = new Konva.Layer();

// if you want to make something with native 2d canvas
//we can create it and use it for Konva.Image

var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');

var image = new Konva.Image({
image: canvas,
draggable: true

// make manual drawings
ctx.fillStyle = 'blue';
ctx.fillRect(5, 5, canvas.width - 10, canvas.height / 2);
ctx.fillStyle = 'red';
ctx.arc(100, 75, 50, 0, 2 * Math.PI);

// such as canvas is updated we need to redraw the layer

Enjoying Konva? Please consider to support the project.