I'm trying to figure out how to access in my js
file the original page from the extension page.
Lets say I'm in example.com/test.html
, I want to know how do I access test.html from my extension (the download.js
which is been called from download.html
)
Edit: So I've added another js
script in the middle however I never reach the download.js
Update Thanks to wOxxOm I've manage to get what I wanted, I've updated the question for follow searches.
Here is my code:
background.js
chrome.tabs.executeScript(null, { file: "jquery.min.js" }, function() {
chrome.tabs.executeScript(null, { file: "download.js" }, function(results){
JSON.stringify(results);
var i;
for (i = 0; i < results[0].length; ++i) {
chrome.downloads.download({
url: results[0][i],
filename: "/Users/testusr/Documents/"
});
}
});
});
download.js
[].map.call(document.querySelectorAll('[data-bimg] img'), function(e) {
return e.src;
});
manifest.json
{
"manifest_version": 2,
"name": "test",
"version": "1.0",
"description": "This extension will download all product images",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "download.html"
},
"permissions": [
"activeTab",
"downloads"
]
}
download.html
<!doctype html>
<html>
<head>
<title>Test</title>
<script src="background.js"></script>
</head>
<body>
<h1>Test</h1>
</body>
</html>
chrome.tabs.executeScript
to inject script into the active tab. That is one of the capabilities of the"activeTab"
permission.chrome.tabs.executeScript
inbackground.js
I don't reach thedownload.js
fileconsole.log(results[0])