6
I wonder if you have any way to manipulate the DOM of another page with my extension.
Ex: I open the extension popup and there is a button, and this button I call a Javascript function:
var n1 = document.getElementById("div1").value;
var n2 = document.getElementById("div2").value;
return n1+n2;
Only when I access the popup DOM, the need is to access the DOM of the open page, and return the sum of the values of the open page to the popup DOM.
Manifest
{
"name": "Teste",
"version": "0.0.1",
"manifest_version": 2,
"description": "Teste.",
"browser_action":{
"default_icon": "icon.png",
"default_popup": "background.html"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["script.js"]
}
]
}
HTML
<html>
<head>
<style>
html,body{width:425px;}
</style>
</head>
<body>
<button onclick="Captura()">Click me</button>
</body>
</html>
Script
alert(document.getElementsByTagName("div").length);
Making some test had the result. Every time I update the google page, my extension shows the amount of div of the same. my doubt is, it is possible to trigger this event only when I click the button in the popup.