In threejs, if the size of renderer is not the width and height of window, an error will occur in ray pickup. How to solve this problem?

I want to embed the demo of threejs into a div, and then change the size of the renderer to put it in my other pages. It turns out that after the size of the renderer has changed, the ray pickup seems to have gone wrong.

was originally renderer.setSize (window.innerWidth,window.innerHeight); click events are all normal
later I set renderer.setSize (window.innerWidth/2,window.innerHeight/2) like this, and found that renderer has become smaller, and the objects in it have shrunk accordingly, but there is something wrong with the click event, and the actual position coordinates of the object do not seem to have changed. How should I deal with this?

Oct.12,2021

function initRay() {  
  let getBoundingClientRect = **canvas**.getBoundingClientRect()  //canvasid
  // 
  let x = ((event.clientX - getBoundingClientRect .left) / canvas.offsetWidth) * 2 - 1;// 
  let y = -((event.clientY - getBoundingClientRect .top) / canvas.offsetHeight) * 2 + 1;// 
  let standardVector = new THREE.Vector3(x, y, 1);// 
  // 
  let worldVector = standardVector.unproject(camera);
  // (worldVector)
  let ray = worldVector.sub(camera.position).normalize();
  // 
  let rayCaster = new THREE.Raycaster(camera.position, ray);
  //   false
  let intersects = rayCaster.intersectObjects(scene.children, true);
  if (intersects.length > 0) {
      // console.log(intersects[0].object);
  }
}
Menu