Safari Extension : download image on click event (document.addEventListener)

I am trying to design a Safari extension to register a mouse-click on a webpage's image to automatically download that image when clicked on (whilst holding down the Command key).

function handleImageClick(event) {
    
    if (event.target.tagName === 'IMG') {
        const imageUrl = event.target.src;

        const link = document.createElement('a');
        link.href = imageUrl; 
        link.download = 'image'; 
        
        link.click(); 
    }
}

document.addEventListener('click', handleImageClick);

However, I am having no luck and wonder if it's because all functionality is limited to the toolbar popover ?

Safari Extension : download image on click event (document.addEventListener)
 
 
Q