I'm literally out of options of trying to get it work and need your suggestions/inputs of what should I do further to make it work.
What I'm doing
I'm building a Google Chrome Extension to enhance the existing functionality of a website. For that I need to inject my own JavaScript to HTML of the website. For that there are two ways:
- Inject my script file using
content_scripts
which is written inmanifest.json
of extension - On click of extension icon, via background script
chrome.tabs.executeScript
Both of the ways are fine and working for me.
About Website
There's a div element for content, whose HTML keeps on changing based on which link/button user has clicked. The page doesn't refresh, as the HTML is added/replaced via JavaScript for that div. And there are lot of complex operations happening (with server) to replace the content which is not possible to understand and to rewrite.
The website has obfuscated JavaScript file.
When user clicks on a link: JavaScript receives the click event > does some magic with server and builds up the HTML which needs to be replaced > sets the innerHTML of content div > uses jQuery to registers events for newly added buttons, links, iframe, etc.
All of this happens in a single big obfuscated function. Something like below:
(window.webpackJsonp = window.webpackJsonp || []).push([[12], {
"/5H/": function (e, n, d) { ... },
"A3c2K": function (e, n, d) {
var de = { ...
render: function () { ... <some HTML changing code> ... var e = this; oe.call(e); // setting up events ... },
...
}
function oe() {
// all events setup function
var t = this; ...
t.iframeNode.on("load", function () {
t.iframeNode[0].elem.contentWindow.print() // the problem
})
...
}},
...
The problem
The problem is, when user clicks the link, JavaScript creates iframe and triggers on load function for that iframe, which in-turn triggers the print window from that iframe. All that happens in one chain because it is written in one big JS function. I do not want to print window to popup.
My injected JavaScript or Chrome Extension, can act before the function is called (when users clicks on the link) or after everything has happened and it will be too late to stop print window from opening.
Also,
windows.print = function() {}
also won't work as the actual window will be the iframe's window where this needs to be executed, and that too before onLoad event. Already tried this.Chrome extension doesn't have capabilities to close the print window. It can add new printers inside the print window but not able to totally disable it or close it. I haven't found one.
Other chrome extensions which are fiddler like, ex: Resource Override doesn't seems to work in my case because of interdependency of JS files. The page won't even show up anything as the above main JS file is responsible of loading the full UI and there are some errors that comes up when resource is overridden. Moreover I was not able to find which chrome extension API they are using to override resource at runtime.
If I copy the resource on local from Chrome Dev Tools for testing it out and if I comment out the
.print()
body of onLoad event. Then, print window won't show up and that is exactly what I want.
Overall, I want to disable print window totally from iFrame. And if that is somehow not possible then I want to close the print window from Chrome extension. Any help, suggestion or direction is deeply appreciated.