0
Good morning!
I’m trying to create a pro Chrome extension to click a button each X seconds. The problem is that the part of the page that needs to run the script is inside a iframe and it doesn’t work at all. In the top and side menu (which is outside the iframe) I can run the script normally, follow image example.
I found a way to access an external link where the page is outside the iframe and the script works normal, the problem is that this external link does not load the top and side menu (in dark green), follow image example.
Is there any way to load all content outside of iframe? If not, could you make the extension work within iframe?
- Extension code:
manifest.json
{
"manifest_version": 2,
"name": "Auto Refresh - ServiceNow",
"description": "Extensão para o Google Chrome que atualiza automaticamente o ServiceNow.",
"version": "1.1",
"icons": {
"128": "128.png"
},
"content_scripts": [{
"matches": ["https://renner.service-now.com/*"],
"js": ["autorefresh-servicenow.js"]
}]
}
autorefresh-servicenow.js
function clickButton() {
const btn_element = document.querySelector('button[aria-label="Atualizar Widget Dashboard Fila Atendimento - Incidentes"]');
btn_element.click();
btn_element.dispatchEvent(new Event('click'));
}
document.querySelector('button').addEventListener('click', () => {
console.log('Fui clicado...')
})
// Intervalo de clicks por segunto
setInterval(clickButton, 3000);
- Page code:
iframe
<iframe id="gsft_main" allowfullscreen="true" main-pane="true" name="gsft_main" title="Fila de Atendimento LINX | ServiceNow" aria-label="Conteúdo principal" src="/$pa_dashboard.do?sysparm_dashboard=efd58c4fdbfc1450a918cf2414961945&sysparm_tab=81f5008fdbfc1450a918cf2414961931&sysparm_cancelable=true&sysparm_editable=undefined&sysparm_active_panel=false" __idm_frm__="161" data-original-title="Conteúdo principal"></iframe>
div do botão
<button tabindex="0" class="btn header-icon icon-refresh" style="color: #FFFFFF" aria-label="Atualizar Widget Dashboard Fila Atendimento - Incidentes" title="" data-original-title="Atualizar"></button>
can’t do that, that would be a cross side scripting, your Extension if you had access to an iframe could open a bank’s website in iframe and when you have access to steal user data, for security reasons you cannot have access to what you have in iframe, other than an iframe within the same domain, which is not the case for an extension
– Ricardo Pontual