Skip to content
Snippets Groups Projects
Commit 077a2bbe authored by Anton Bershanskiy's avatar Anton Bershanskiy
Browse files

Now can inject resources directly into window context

parent 3608a2b4
No related branches found
No related tags found
No related merge requests found
// This code is executed in the background context
// source: https://stackoverflow.com/questions/9862182/on-page-load-event-in-chrome-extensions
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/executeScript
// Listen for the navigation event
chrome.webNavigation.onCompleted.addListener (function(details) {
// Execute the context script in its own context with "clean DOM"
chrome.tabs.executeScript(details.tabId, {
file: "/content_scripts/inject.js"
});
});
\ No newline at end of file
// This code is executed in a separate context with "clean DOM"
(function() {
// Execute the actal payload in the context of the window
var s = document.createElement("script");
s.src = chrome.extension.getURL("/web_accessible_resources/inject.js");
s.onload = function() {
this.remove();
}
(document.head || document.documentElement).appendChild(s);
})()
\ No newline at end of file
alert("Hi");
\ No newline at end of file
......@@ -11,7 +11,9 @@
},
"permissions": [
"storage",
"cookies"
"cookies",
"tabs",
"webNavigation"
],
"optional_permissions": [
"webRequest",
......@@ -24,8 +26,12 @@
},
"background": {
"scripts": [
"background/cookiestore.js"
"background/cookiestore.js",
"background/inject.js"
],
"persistent": false
}
"persistent": true
},
"web_accessible_resources": [
"web_accessible_resources/*"
]
}
\ No newline at end of file
// This code is executed in the context of the window
var veryConvolutedInjection = 4;
console.log("Injection completed, try logging the variable veryConvolutedInjection");
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment