Lootyhoof / mozarchiver

MAFF/MHT Web page compressor for Pale Moon
Mozilla Public License 2.0
26 stars 2 forks source link

window.onload does not fire in a .mht file #8

Open Siemenskun opened 5 years ago

Siemenskun commented 5 years ago

I don't know is it an issue of Pale Moon or MozArchiver, but it worked fine with old Firefox and UnMHT. The event window.onload does not fire. A simple example from MDN (https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event#Live_example) give me this if I execute it in a .mht file (testcase.mht in the attachment)

readystate: interactive
DOMContentLoaded

It should be like this (testcase.html in the attachment):

readystate: interactive
DOMContentLoaded
readystate: complete
load

So, many .mht files that rely on some JavaScript are broken. Tested with Pale Moon 28.5.2 and MozArchiver 2.0.1.

testcase.zip

Lootyhoof commented 5 years ago

How was that .mht file produced? I just re-saved the .html as .mht and it worked fine.

Re-saved file, working as intended

Siemenskun commented 5 years ago

Of course it looks like it works fine, because MozArchiver cuts off any included JavaScript while saving. Just look in the source code of your re-saved testcase.mht. Whole text in the textarea is just a plain text, not a script-generated. I made my testcase.mht by hand, but it perfectly reproduce the issue you will encounter if you will open a .mht generated by UnMHT, IE or Opera with Presto engine.

Lootyhoof commented 5 years ago

Looking at this a bit more would suggest we do, in fact, purposely remove inline scripts: https://github.com/Lootyhoof/mozarchiver/blob/master/src/chrome/content/saving/ExactPersistParsedJob.js#L733

That said, I'm not entirely sure why this is. Other than not depending on potentially-online components I guess (i.e. something that depends on a server response).