Question

I have a web page which is completely rendered on the server side (nodejs+phantomjs), I want to send this page to a client browser. The problem is the client browser tries to re-execute the javascript. Hence, I have two options:

  1. Disable javascript in the iframe that loads that page in the client
  2. Strip every javascript and js call/event from the page

Although I will not use the original javascript of the page, I will later on need to be able to add javascript events to the iframe.

It seems the first option can be realised by using the iframe 'sandbox' argument.. but that will prevent me from injecting other javascript later on. Hence I need a way to realize the second option, i.e. removing all the original javascript from the page.

Is there an efficient (and reliable) way to do so? I guess using regex could be a solution, but is it reliable?

Was it helpful?

Solution

I found a solution which appear to be working. I am not sure it is the best solution, but it is surely better than manually removing any JS reference from the document.. for my purposes.

Here's the trick: hijack js! I am just prepending in the <head> the following:

<script>
    Function.prototype.call = function(){}; 
    Function.prototype.apply = function(){};
    Function.prototype.bind = function(){};
</script>"

and JavaScript is disabled.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top