Urgent!! In want exact coordinates inside the html canvas element
Posted by Illustrious_Creme203@reddit | learnprogramming | View on Reddit | 5 comments
Thing is I want to exact coordinates inside the canvas element not viewport.
Is there a robust way for this.
Please help
abrahamguo@reddit
Illustrious_Creme203@reddit (OP)
Purpose of this is to do playwright ui automation. I have locators of canvas.
Below code gives me coordinates, but of viewport
const canvas = document.getElementById("canvas");
canvas.addEventListener("click", (e) => { const rect = canvas.getBoundingClientRect();
});
abrahamguo@reddit
Use
offsetXandoffsetY.Ormek_II@reddit
Sorry to not provide an answer but falling back to 40 years of internet: why do you want that?
Can you guarantee the size of the canvas, so your coordinates make sense?
Illustrious_Creme203@reddit (OP)
Yes size is guaranteed