MouseOverイベントを取って、aタグのURLをbackgroundに送信するサンプル。content-scriptsでは処理に制限が多いのでbackgroundで処理する場合を想定。
manifest.json{
"manifest_version": 2,
"name": "MouseOver",
"version": "0.0.1",
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["content.js"],
"run_at": "document_end"
}],
"background": {
"scripts": ["background.js"]
}
}
content.jsvar elements = document.querySelectorAll('a');
for (var i = 0; i < elements.length; i++) {
elements[i].addEventListener('mouseover', function(event) {
chrome.extension.sendRequest({"url": this.href});
});
}
background.jschrome.extension.onRequest.addListener(function(req, sender, res) {
console.log(req.url);
});