I am trying to insert jquery into an iframe located in my content script. The problem is that jquery ui does get loaded but only returns a message 'Jquery is not defined.' I suspect that it has to do with the time it takes to load jquery. Do I need to set an interval in order to wait for jquery to be loaded? or is there any alternative that I can use jquery right away withtout having to wait? I have also tried to execute jquery script from my background script with no luck.
Content Script
var jsjq = iframe.contentDocument.createElement("script")
jsjq.src = chrome.extension.getURL("jquery.min.js")
jsjq.type = "text/javascript"
var jsui = iframe.contentDocument.createElement("script")
jsui.src = chrome.extension.getURL("jquery-ui.min.js")
jsui.type = "text/javascript"
var css = iframe.contentDocument.createElement("link")
css.href = chrome.extension.getURL("content.css")
css.type = "text/css"
css.rel = "stylesheet"
var cssui = iframe.contentDocument.createElement("link")
cssui.href = chrome.extension.getURL("jquery-ui.min.css")
cssui.type = "text/css"
cssui.rel = "stylesheet"
iframe.contentWindow.document.head.appendChild(jsjq)
iframe.contentWindow.document.head.appendChild(jsui)
iframe.contentWindow.document.head.appendChild(css)
iframe.contentWindow.document.head.appendChild(cssui)
var script = iframe.contentWindow.document.createElement('script')
script.type = "text/javascript"
script.innerHTML = 'if (window.jQuery) {console.log("st")} else {console.log("none")}'
iframe.contentWindow.document.head.appendChild(script)
Background Script
chrome.tabs.executeScript(sender.tab.id, {
file: "content.js"
}, function() {
chrome.tabs.executeScript(sender.tab.id, { // this part does not seem to work at all
file: "jquery.min.js"
})})
Manifest
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"css": ["content.css", "jquery-ui.min.css"],
"js": ["content.js", "jquery.min.js", "jquery-ui.min.js", "async.js"]
}
],
"web_accessible_resources": [
"content.css",
"jquery.min.js",
"jquery-ui.min.js",
"jquery-ui.min.css"
]