I am able to use messaging to have a content script communicate with background.js:
content.js
chrome.runtime.sendMessage({type: 'injectTheAdditionalScript'});
Background.js
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse){
console.log('In Background and received message from iFrame...' + sender.tab.id + ' / ' + sender.frameId);
if(typeof message === 'object' && message.type === 'injectTheAdditionalScript') {
chrome.tabs.executeScript(sender.tab.id,{
frameId: sender.frameId,
code: "console.log('Injecting a console log...');\
console.log('2nd line injecting a console log...');\
var activeEl = document.activeElement;\
var activeTag = activeEl.tagName.toLowerCase();\
var activeID = activeEl.id;\
console.log('Injected code and type of element is: ' + activeEl.id + ' / ' + activeTag);\
"
});
}
});
The console.log messages successfully show in the page with the content script.
But I need to know the frameID in order to append/add html to the iframe.
My goal is to 'paste' a string into the iframe - as if you'd CTRL-V'd a string into the iframe.
It would seem that you'd be able to 'get' the element ID of the iframe if you can run code in it...but the 'activeID' variable in the code above is blank.
Thank you for any consideration/help.