-
Notifications
You must be signed in to change notification settings - Fork 28
Viewer does not seem to recognize .md docs from HTTP URLs #8
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
Comments
It actually might be a feature. :-) If the .md content is received as HTML, then the viewer doesn't style it. The content has to arrive as raw text. For example, navigate to this .md file (https://github.com/KeithLRobertson/markdown-viewer/blob/master/README.md). You see it has the standard github menus, headers and footers; github has styled the document, so the viewer does not. Click on the "Raw" button; it's on the right just above the markdown document content. (There are text buttons Raw, Blame, History.) That navigates here (https://raw.githubusercontent.com/KeithLRobertson/markdown-viewer/master/README.md). It is not styled by github, so it should be styled by the addon. If you see the latter link as raw text, then there may be an issue with how the addon detects whether the content is styled yet or not. (Could be different versions of Firefox wrap raw text into an HTML DOM in different ways?) I would need your help to open the developer view and show what the DOM looks like. The viewer expects that for unstyled text, the document body has exactly one child node which is a PRE element. |
@braytak Did you try the above steps? Was the raw link styled? |
@KeithLRobertson Yes I did. What I can tell you is that the |
@KeithLRobertson Addigionally, I get the following prompt from Firefox - the documents are served by |
@braytak Well, again, the extension doesn't style the markdown if the server has already styled it. I think that's being reflected in the content-type sent by the server, which is then shown in the type column. Regarding your second message, under what conditions do you see that prompt? This means Firefox wants to download the file rather than open/display it. In this case, Firefox would not pass the content to the extension, so you couldn't have seen "the extension successfully [styled] the raw markdown". |
No, the
I get it when I access my I will get back to you with further information in a couple of days. |
@KeithLRobertson I have now "refreshed" Firefox (v56.0) which included re-installing your extension.
How does the extension decide to engage styling; file extension, content-type header, both? |
@braytak What platform are you running on? I am using FF 56.0 on Windows, and the viewer styles local .md files When the readme.md is unstyled, what does the DOM look like? The viewer hooks into the tabs updated event. If FF decides to download the file (or open in an application) rather than display it, the viewer doesn't see it. That seems to happen for your local .md documents based on the file extension and some Firefox settings/mappings.
Assuming FF loads the document, the viewer triggers when the update is "complete" (i.e. the document is loaded) and when the URL extension looks like .md, .mkd, .markdown, etc. The viewer never sees the file or characters directly; at this point, FF has already read the file, decided the encoding and converted it to characters, decided whether it's plain text or HTML and converted it into a DOM (Document Object Model). For plain text, FF will have created a single <pre> element in the <body> and placed the file content in there. If the viewer sees other elements, then the document is already styled, so the viewer doesn't change it. Otherwise, the viewer pulls the content out, styles it as HTML, and replaces the <pre> element with the styled HTML elements in the DOM body. |
Oh wait! It's not styling the raw readme.md any more! I'll look into that ASAP. |
@KeithLRobertson Same platform FF56, W10. |
As noted above, I am seeing the same. This appears to be a new defect in FF 56.0+. The extension background script activates, but tabs.executeScript() doesn't do anything. This is supposed to load the content script into the page which rewrites it. It works for local markdown but not for markdown loaded from a non-local URL. My extension has "activeTab" permission, and according to the documentation that should be all that's needed. I also tested FF 56.0.1 and FF Dev Ed 57.0b, and they have the same problem. |
@KeithLRobertson Sorry... selected wrong reaction icon... I meant "bummer" ;-) |
@KeithLRobertson Willing to do further testing if ever you need it... |
@braytak, thanks! This is still an issue in FF 57.0, Quantum. Since 56.0, tabs.executeScript() doesn't work for non-local documents. I need to open a bug with Mozilla, but I haven't had time to gather all the info. |
The same here on Firefox 57 with Ubuntu Linux |
It looks like some change in permissions, but I haven't seen any documentation on what is now required. |
On a similar note with Firefox on ubuntu - going to the file through file:/// it renders correctly, but over http:// it does not. I have set the mime type & in nginx set Content-Type to text/markdown for md files. |
The viewer doesn't currently look at the Content-Type but at the URL "file extension". As mentioned above, the viewer is activating for http:// URLs, but something has changed in FF. The viewer calls tabs.executeScript(), but that no longer works for non-local documents; it just does nothing, so the Markdown is not converted. To me, this is a Firefox bug unless Mozilla documents what it requires (permissions?). And I don't have time to figure out how to work around this problem. |
This is apparently a by-design limitation, where the user needs to click or use a shortcut (or some other action) to "enable" the See https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/permissions#activeTab_permission (emphasis mine).
And also https://bugzilla.mozilla.org/show_bug.cgi?id=1392459#c1
|
Also, after doing some tests, it appears this permission is reset every time the page is reloaded. |
It's also worth noting that the plugin will not work if it is explicitely prohibited by the website (such as raw.githubusercontent.com). Check for a Content Security Policy header, it looks like:
|
If it helps, i found another extension which manages to get this to work: |
Yes @asim-vax, I had a look at how they do it:
So if we wanted to, we could do something similar, maybe have a toolbar button that asks for (or toggles) permission on the current domain. Possibly complemented by a button in the settings page to ask for permission on all domains. I don't know how persistent those permissions are. Edit: some misconceptions. This approach is probably better. |
@Cimbali thank you for investigating and taking the time to explain it :) |
Closed via #25 and version 1.3.0. |
Hi!
I don't really know if this is an issue or a known limitation.
The again, I might not be doing what I need to do to get that functionality working...!
Tks,
The text was updated successfully, but these errors were encountered: