Can I pre-edit the html of a web page before the javascript is run?

2

I'm viewing this website that has a client side javascript error caused by the scripts being loaded in the wrong order. Problem is I don't own this source, but I really need to use the site ASAP.

Is there a browser/browser plugin that will let me fix this in the browser and let me continue to use the page? The problem is that since this is loaded in the head element, if I modify the html the JS error has already occurred. And if I refresh the changes (at least in chrome) my local modifications have disappeared.

Specifically, the html is like this:

<script 
    language="javascript" 
    src="/scripts/util.js" 
    type="text/javascript"></script>
<script 
    language="javascript" 
    src="/scripts/scriptaculous/prototype.js" 
    type="text/javascript"></script>
<script 
    language="javascript" 
    src="/scripts/scriptaculous/scriptaculous.js" 
    type="text/javascript"></script>

And to fix the bug, it would need to be like this:

<script 
    language="javascript" 
    src="/scripts/scriptaculous/prototype.js" 
    type="text/javascript"></script>
<script 
    language="javascript" 
    src="/scripts/scriptaculous/scriptaculous.js" 
    type="text/javascript"></script>
<script 
    language="javascript" 
    src="/scripts/util.js" 
    type="text/javascript"></script>

Notice how the util.js moved to the bottom.

Daniel Kaplan

Posted 2013-12-01T07:00:45.197

Reputation: 419

Answers

1

You might be able to do this by making a userscript that loads the javascript you need in the order you need it. A userscript can execute essentially any arbitrary javascript on the page, including loading other javascript. The only concern would be whether the browser executes the userscript before or after loading the other scripts on the page. This stack overflow question seems to imply (2nd answer) that there's a way to do this.

A simple userscript might use the aforementioned method and the document.write command to insert a new <script> element as needed before the page parses any other javascript.

nhinkle

Posted 2013-12-01T07:00:45.197

Reputation: 35 057

Thanks for the help. This is the path I'm going down. Is this question better suited for stack overflow? – Daniel Kaplan – 2013-12-01T07:17:29.613

1@tieTYT I think the question is OK for SU since you were initially asking if your browser could do something, and there could be other answers that aren't programming-related. If you run into additional problems along the way, I'd suggest searching on SO first, and then asking a question over there if you need to. – nhinkle – 2013-12-01T07:22:28.430

1Unfortunately a user-script won’t work because Chrome doesn’t support document-start for the run-at key, only document-end. – Synetech – 2013-12-03T06:25:28.247

@Synetech hm. Well I'm assuming the user could probably use Firefox just for this one page, but that's a good point. – nhinkle – 2013-12-03T09:02:57.607