Skip to content
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

Can we force the extension to load page not by specified file extension? #271

Open
w-wong opened this issue Feb 22, 2019 · 17 comments
Open

Comments

@w-wong
Copy link

w-wong commented Feb 22, 2019

Can we force the extension to load page without checking on specified file extension?

Sometimes we can't change the remote link file extension

@mojavelinux
Copy link
Member

Perhaps we can look for a query string argument (or some other URL modifier).

@w-wong
Copy link
Author

w-wong commented Feb 23, 2019

I have no idea how to develop these plugin extension. However, I can see JSONView can do so via an option of "When you click the extension"

@ggrossetie
Copy link
Member

Hello @w-wong,

From a technical point of view it's really easy to load the extension on every page. That's what JSONView is doing but, in my opinion, it's also a very bad practice because the extension is basically making your browser slower even if you don't navigate to a JSON document or in our case an AsciiDoc document.
That's why we are using a pattern:

"matches":[
"*://*/*.ad",
"*://*/*.ad?*",
"*://*/*.ad.*",
"*://*/*.adoc",
"*://*/*.adoc?*",
"*://*/*.adoc.*",
"*://*/*.asc",
"*://*/*.asc?*",
"*://*/*.asc.*",
"*://*/*.asciidoc",
"*://*/*.asciidoc?*",
"*://*/*.asciidoc.*",
"*://*/*.txt",
"*://*/*.txt?*",
"*://*/*.txt.*",
"file://*/*.ad",
"file://*/*.ad?*",
"file://*/*.ad.*",
"file://*/*.adoc",
"file://*/*.adoc?*",
"file://*/*.adoc.*",
"file://*/*.asc",
"file://*/*.asc?*",
"file://*/*.asc.*",
"file://*/*.asciidoc",
"file://*/*.asciidoc?*",
"file://*/*.asciidoc.*",
"file://*/*.txt",
"file://*/*.txt?*",
"file://*/*.txt.*"

The Asciidoctor extension will only be loaded if the URL matches.

Perhaps we can look for a query string argument (or some other URL modifier).

That could work, maybe we could use an hint like ?content=asciidoc or a more direct/descriptive query string like ?enable-asciidoctor-extension.

I think we should be careful because query string arguments are already used as Asciidoctor attributes and they can also cause conflicts...

Sometimes we can't change the remote link file extension

Could you please provide an example ?

@w-wong
Copy link
Author

w-wong commented Feb 23, 2019

Hi @Mogztter,

Thanks for your answer.

I actually expect a possibility of a manual load of the asciidoc by clicking the extension button.
JSONView can configure either for all pages or by the option of "When you click the extension". I can see asciidoctor-browser-extension has this option too but it just not working when I click on the extension button.

In my use case, I need to upload my document to a content management system, which support only docx and pdf as attachment. We can see the uploaded attachment in another page. When we click on the hyper link on that page. It redirects to open the document in another browser window or tab with the url not really referring to the actual document file. Therefore, I can only see the plain text of my asciidoc

In another scenario, I uploaded a json file as an attachment. When I click on the JSONView extension button, the page can be reloaded with a Json view.

I hope you can understand what I explained.

@mojavelinux
Copy link
Member

I'm thinking, is it possible to detect a modified click on the extension button? We can't use a regular click since that action has already been taken to enable/disable the extension (which is an important use case).

@mojavelinux
Copy link
Member

If we looked for a query string, I'd making it something pretty formal such as ?content-type=text/asciidoc.

@w-wong
Copy link
Author

w-wong commented Feb 24, 2019

I'm thinking, is it possible to detect a modified click on the extension button? We can't use a regular click since that action has already been taken to enable/disable the extension (which is an important use case).

What is this enable/disable use case? I thought "When you click the extension" option is the disable use case provided that you can re-enable the current page/tab by clicking the extension button

Thanks

@mojavelinux
Copy link
Member

The button is currently used to toggle the extension on and off. This is a persistent setting. The reason for it is that having the page preview is not always desirable. Sometimes you are interested in looking at the AsciiDoc source. So it's possible to quickly disable the extension.

I suppose we could reconsider that setting and have it be per document.

@w-wong
Copy link
Author

w-wong commented Feb 24, 2019

Thanks for reconsidering that.

@ggrossetie
Copy link
Member

If we looked for a query string, I'd making it something pretty formal such as ?content-type=text/asciidoc.

@w-wong Would that be useful in your context ?

I'm thinking, is it possible to detect a modified click on the extension button? We can't use a regular click since that action has already been taken to enable/disable the extension (which is an important use case).

That does not change the fact that the extension should be always "loaded".
If we want to be able to convert an AsciiDoc document to HTML 5 on any page then we can to do the following:

  • update the matching rule (and the permissions) to load the extension on any page
  • if the active tab URL matches an AsciiDoc extension (.ad, .adoc, .asc, .asciidoc, .ad or .txt if enabled) then the extension will be enabled and it will convert the page content
  • if the URL does not match, the extension will be disabled

The user can then decide to "force" the extension to convert non-matching page by clicking on the extension (disabled -> enabled).
Likewise it's also possible to display the raw content on a matching URL by clicking on the extension (enabled -> disabled).

Arguably this approach is better from a UX perspective but it's bad in term of security and performance. I'm torn between the two options...

@mojavelinux
Copy link
Member

That does not change the fact that the extension should be always "loaded".

Oh, I see what you're saying about the pre-filtering. That's what sets this extension apart from many others. Most extensions are always active, whereas this one is only active for relevant URLs (which is different from performing work). That makes it very lightweight, something we may not want to give up. 🤔

@ggrossetie
Copy link
Member

That makes it very lightweight, something we may not want to give up.

Exactly.
And since browser extensions are now one of the most commonly used malware attack vectors, it can be scary for a user if the extension asks to access any pages...

Tough decision but since it's not the most common use case then I think we should not deteriorate performance or security.

@w-wong
Copy link
Author

w-wong commented Feb 24, 2019

If we looked for a query string, I'd making it something pretty formal such as ?content-type=text/asciidoc.

@w-wong Would that be useful in your context ?

No because the content management system control how to display my document after it is uploaded. I can't even see my document name on the URL when my document is opened in the browser.

If we want to be able to convert an AsciiDoc document to HTML 5 on any page then we can to do the following:

* update the matching rule (and the permissions) to load the extension on any page

* if the active tab URL matches an AsciiDoc extension (`.ad`, `.adoc`, `.asc`, `.asciidoc`, `.ad` or `.txt` if enabled) then the extension will be enabled and it will convert the page content

* if the URL does not match, the extension will be disabled

The user can then decide to "force" the extension to convert non-matching page by clicking on the extension (disabled -> enabled).
Likewise it's also possible to display the raw content on a matching URL by clicking on the extension (enabled -> disabled).

This approach sounds pretty good as it becomes user choice on how to view the document.

@w-wong
Copy link
Author

w-wong commented Feb 24, 2019

That makes it very lightweight, something we may not want to give up.

Exactly.
And since browser extensions are now one of the most commonly used malware attack vectors, it can be scary for a user if the extension asks to access any pages...

Tough decision but since it's not the most common use case then I think we should not deteriorate performance or security.

After your explanation, I agree there is security issue and pretty serious actually, which I never think of the power of extension. Maybe this is the reason why the extension (both AsciiDoc extension and JSONView) can't work for documents in Google Drive and One Drive.

However, it turns out I can only use it for reading local files.

@sturtison
Copy link
Contributor

@w-wong I appreciate your use case. Similarly, I would like to have Box render asciidoc files. The above discussion suggests that this be done at the Box server, similar to GitHub, and not at the extension level.

@ggrossetie
Copy link
Member

@sturtison If https://www.box.com can serve the AsciiDoc file as plain-text from an URL ending with .adoc then the Asciidoctor Browser Extension can render it to HTML. However, if https://www.box.com serves the AsciiDoc file wrapped in an HTML page then that won't work.

@ggrossetie
Copy link
Member

Maybe this is the reason why the extension (both AsciiDoc extension and JSONView) can't work for documents in Google Drive and One Drive.

Yes and no, the main reason is that the content needs to be served as plain-text otherwise the extension cannot extract the AsciiDoc content (or JSON content) from an HTML page.
If you are using Google Docs, you can save your document as plain-text (.txt) and open it in your browser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants