mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-17 06:48:37 +02:00
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.
14 lines
361 B
JavaScript
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});
|
|
}
|