How to make coordinates adaptive

I did, but it seemed not work
I refer to this link : Scale viewer(s) to match canvas size
here is my code:

const currentViewbox = this.bpmnViewer.get('canvas').viewbox()      
const widthWindow = window.outerWidth;      
const heightWindow = window.outerHeight;      
const elementMid = {        
x: widthWindow / 2,        
y: heightWindow / 2      
}     
 this.bpmnViewer.get('canvas').viewbox({       
 x: elementMid.x - currentViewbox.width / 2,       
 y: elementMid.y - currentViewbox.height / 2,       
 width: currentViewbox.width,        
height: currentViewbox.height     
 })      
const width = document.getElementById('canvas').offsetWidth      this.bpmnViewer.get('canvas').zoom(width / this.width)

I want to know why it doesn’t work