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

Get correct href value on onClick for "warc2zim" files. #1036

Merged
merged 1 commit into from
Jan 4, 2024

Conversation

mgautierfr
Copy link
Member

Next to come warc2zim archive will come with "wombat" embedded. The purpose of wombat is to be an interface with js code to mask that we are in a scrapped/zim context to the js.

So it rewrite the .href attributes to the original url (ie, an absolute url to the original website), even if the local relative url is valid.

Let's ask to wombat to not rewrite href in our special case.

Copy link

codecov bot commented Dec 20, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 38.95%. Comparing base (2ad5e51) to head (9375f97).
Report is 167 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1036   +/-   ##
=======================================
  Coverage   38.95%   38.95%           
=======================================
  Files          58       58           
  Lines        3958     3958           
  Branches     2181     2181           
=======================================
  Hits         1542     1542           
  Misses       1086     1086           
  Partials     1330     1330           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Jaifroid
Copy link
Member

As I will need to keep up with changes on the reader side, I need to understand the effect of this. I had noticed that getting the href of an anchor resulted in the original untransformed URL in code, even though the anchor's href is displayed in the browser as rewritten, and I had worked around that. I didn't know it was possible to disable rewriting (where are these things documented???). So I guess I just need to copy the code here that disables that rewriting when getting the href.

@mgautierfr
Copy link
Member Author

(where are these things documented???)

At the trustiest place : source code of wombat.
I am not aware[*] of a any documentation (neither comments in source code)

[*] I am NOT saying there isn't. Just I'm not aware of.

So I guess I just need to copy the code here that disables that rewriting when getting the href.

I think so. Another solution could be to do target.attributs.href which seems to be the href store in the html (dom ?). As I don't know if there is a semantic difference between both, I prefer use the former and deactivate wombat rewriting (which will return "correct" target.href)

@Jaifroid
Copy link
Member

Thanks. I tried many things, and event.target.getAttribute('href') was also subject to rewriting, just like accessing the attribute directly. I'll check the suggested store when I rewrite that code. But thanks for info on how to turn off the rewriting temporarily. I find the lack of comments in the source code (at least the source code I could find) makes it really difficult to work these things out (for me, anyway).

@Jaifroid
Copy link
Member

Just wanted to say "big thank you" 🙏 for finding the ._no_rewrite = true trick. It turned out to fix an issue in Kiwix PWA where window.open() would refuse to respect the instruction to open a new window rather than a new tab (for Zimit ZIMs of course). Doing window.open._no_rewrite = true; before issuing the window.open() command (and then setting it back to false afterwards) solves that and allows me to use the native API without issue.

I'm going to open an issue in the Wombat source Repo to add at least that bit of documentation!

Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMBIPTMISB*


* Looks good to me, but I propose to make it slightly better

Comment on lines 297 to 309
if ( isExternalUrl(target.href) ) {
const possiblyBlockedLink = blockLink(target.href);
// In case of wombat in the middle, wombat will rewrite the href value to the original url (external link)
// This is not what we want. Let's ask wombat to not rewrite href
const old_no_rewrite = target._no_rewrite;
target._no_rewrite = true;
const target_href = target.href;
target._no_rewrite = old_no_rewrite;
if (isExternalUrl(target_href)) {
const possiblyBlockedLink = blockLink(target_href);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please encapsulate (part of) this change in a helper function get????Href(). The hard part is figuring out what to put instead of ???? in the function name.

Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixup commit must be squashed

Next to come warc2zim archive will come with "wombat" embedded.
The purpose of wombat is to be an interface with js code to mask that
we are in a scrapped/zim context to the js.

So it rewrite the `.href` attributes to the original url (ie, an
absolute url to the original website), even if the local relative url
is valid.

Let's ask to wombat to not rewrite href in our special case.
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

Successfully merging this pull request may close these issues.

4 participants