This JavaScript code allows you to retrieve the mouse position on a right-click event, and then use those coordinates to create a context menu that appears where the mouse is located.
Please note that this solution does not make use of the "add-buttons" feature as shown in your example.
document.getElementById("yourDiv").addEventListener("contextmenu", setContextMenuPosition)
function setContextMenuPosition(event) {
event.preventDefault();
if (event.which === 3) {
createContextMenu(event.clientX, event.clientY);
}
}
function createContextMenu(xCoord, yCoord) {
let contextMenu = document.createElement("div");
contextMenu.style.cssText = "position: fixed; top:" + xCoord + "; left: " + yCoord + ";";
}