-
-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Void the iframe between page loads #341
Comments
It's probably a good idea. |
Thanks @mossroy , I can confirm that about:blank works perfectly as an alternative. I've incorporated this now into kiwix-js-windows 0.9.9.1 beta. Voiding the iframe also helps with some CSS issues I was noticing when switching from Wikipedia ZIMs to Stackexchange-family ZIMs (very small fonts -- with this voiding code, the fonts show at the correct size). |
Cool : could you create a PR for that? |
Was about to post the note below when I've discovered links aren't working in Firefox! So I'll try with dummyArticle again instead.... I've made a PR and have tested quickly in Edge, but not yet in FFOS (works fine in Edge). |
OK, I've had to change it back to dummyArticle.html. Unfortunately, while about:blank works in Edge (and in UWP app context), it doesn't work in Firefox. It works in the sense that the page loads and looks perfect (styles and images load, etc.) but for some reason links don't work. dummyArticle.html seems to work fine in Firefox. This may be due to the structure of about:blank? Maybe we could create some structured html programmatically if the goal is to get rid of dummyArticle. I haven't got time to investigate further just now, but I think it's worth trying as part of testing for this PR. |
I've had five minutes to look at this, and in Firefox with src set to about:blank, links have "target=_blank" added to them, whereas in Edge they do not. This implies that the problem is with our link parsing in jQuery mode. The about:blank document must be "confusing" that routine, so the JavaScript never gets attached to internal links. Not sure what is preferable: debug that, or simply leave dummyArticle in place. In Firefox I'm also getting (with about:blank) a warning in console "Ignoring get or set of property that has [LenientThis] because the "this" object is incorrect." on line 838 of app.js. No idea what this is! |
According to https://stackoverflow.com/questions/27159967/javascript-dom-this-object-is-incorrect and https://bugzilla.mozilla.org/show_bug.cgi?id=1298830 , the console warning might be a bug in the Firefox debugger itself Regarding the non-working links, I ran the debugger on it. It seems to come from the piece of code below :
In Firefox, the "protocol" of about:blank is "http", which is different from "file" (when testing on the filesystem). So our code wrongly considers that it's an external link. |
Can you try with something like :
Source : https://stackoverflow.com/questions/1785040/how-to-clear-the-content-of-an-iframe |
Thanks, some useful test results, and helpful methods to try there. I'll tinker a bit later today. |
Some findings: It's possible to void the iframe and load the new article without setting the iframe.src to about:blank or dummyArticle, using this code in place of the code that we use to inject the html into the iframe (in displayArticleInForm function):
This method has the same advantage of clearing the DOM as far as I can tell. I know this is working because when I put this into the code for Kiwix JS Windows, and load a page requiring MathJax, I can see the scripts being voided when I load a subsequent page. CSS rules seem also to be voided. Another advantage is that this method loads the document There is one disadvantage, which I haven't debugged: while links in Wikipedia work with this method, they do not work in Stackechange-family ZIMs (I've tested on mathoverflow). It seem that the code we have for computing the base URL is not working with this method, or maybe the code for injecting the computed base URL. Going back to the dummyArticle method: While using about:blank instead of dummyArticle doesn't cause problems in the UWP app, the problem in Firefox with the links not clicking is a symptom of the fact that about:blank is loaded with "no domain". I'm a bit worried about the inconsistency this is causing in Firefox, and wonder if it is asking for trouble, even if we can work around it. For now, I think we might be better off sticking with voiding the iframe by loading the dummyArticle in
NB, this does not on its own void the DOM (I checked), and it is necessary also to set the |
Additional info: Using Bizarre. But confirms my suspicion that we should use the |
I think PR #342 is ready now. I experimented with removing dummyArticle, and it is possible to delete it, remove it from the iframe src in index.html, and programmatically set Note that the new code in the PR loads the article correctly into the iframe, with the This code incorporates #343 , and writes the baseUrl directly into the |
With commit kiwix/kiwix-js-pwa@232c73c in the master-dev branch of Kiwix JS Windows, I've been able to get rid of dummyArticle.html in jQuery mode (not tested in service worker) while still voiding the iframe using It works in IE11, Edge, Firefox ESR and the latest Firefox Quantum with the file:// protocol (not tested in Chrome), as well as in UWP app context. It is necessary to neutralize I am fairly confident this will cure #347 . Of course it needs to work also with service worker. I'll try to work on implementing this in Kiwix JS at the weekend. In the meantime feel free to try out what I've done with Kiwix JS Windows, as it runs from index.html in the three browsers I've tested it against, but only in jQuery mode (use only the |
This summarizes the outcome of experiments in #353. The first step is to change the use of I believe the solution is to use
There is one disadvantage:
The above disadvantage is not too serious when the app is running in browser context, as for the end user it simply does nothing. However, running in app context it can cause the app to crash and exit (e.g. it causes the UWP app to crash and exit). I feel it is a bad idea to have this script failing on every page load, as we can't easily predict the effects on all systems. It should be solved by #152, but we may need to neutralize JavaScript on the page in the interim, or explore other solutions. |
I fully agree that executing the Javascript on the page is something we need in the mid-term. So the behavior of .write() is the one we need. |
Fixed by #354 |
After much experimentation with MathJax script loading on kiwix-js-windows (kiwix/kiwix-js-pwa#27), I've come to the conclusion that it's good practice to void the iframe between page loads. This can be done with a single line of code added to
function readArticle(dirEntry)
:document.getElementById("articleContent").src = "dummyArticle.html";
The advantages of this are:
I was getting a very strange bug with MathJax whereby all equations on some mathoverflow pages would randomly get shifted down by one line, making the page illegible. But I noticed this never happened if I exited the app and went straight back to that page. The problem turned out to be the persistence of the MathJax scripts and configuration between page loads and even between different ZIM loads. As MathJax loads very fast and asynchronously anyway (much faster than decompressing a single SVG), the cleanest solution was to void the iframe. This solved the issue.
The main reasons to consider this for kiwix-js are a) it's good practice not to have bits of the DOM of an unrelated document hanging around (even between ZIM loads); and b) it will be necessary if we ever reinstate JavaScript loading or decide to backport MathJax from kiwix-js-windows.
The text was updated successfully, but these errors were encountered: