Files
webextensions-examples/notify-link-clicks/content-script.js
Mindaugas Jakutis 4d5fef4423 improve link detection in notify-link-clicks
Original approach is a bit too naive and misses all links
that contain other elements which can grab mouse clicks.
E. g. simple target checking fails on the grid @ mozilla.org.

Traversing up the tree to look for valid links fixes this problem.
2016-01-06 09:04:54 +02:00

14 lines
361 B
JavaScript

window.addEventListener("click", notifyExtension);
function notifyExtension(e) {
var target = e.target;
while ((target.tagName != "A" || !target.href) && target.parentNode) {
target = target.parentNode;
}
if (target.tagName != "A")
return;
console.log("content script sending message");
chrome.runtime.sendMessage({"url": target.href});
}