1

For my chrome extension I need to detect any click on any element on the page that might open a link and, let's say, show an alert box. There are plenty of websites where you might click on a video player or anywhere on the page and a new page will open (live streams etc.).


Links I've found useful :
How to detect if user it trying to open a link in a new tab?

How to detect Link clicks (text, images, etc) with Javascript?


So far the information I found presumes that I know which elements on the page will open the link. This javascript will be injected on the website and I do NOT know which click and where will open a new link. Is there a way to execute some code AFTER the user clicks such an element AND BEFORE the link is opened?

Ncs
  • 313
  • 1
  • 9
  • Pretty hard, because pretty much anything can open a link. Either assume that any click could do so, or monkeypatch `onclick` and `addEventListener` *before any of the page JS can run*, if that's in your power (and also look for inline handlers on the clicked element and all ancestors) – CertainPerformance Jul 25 '19 at 08:18

0 Answers0