Skip to content

Commit

Permalink
Fixed #119: direct link hack when inside an outer frame (kiwix-serve …
Browse files Browse the repository at this point in the history
…3.5+)

Every HTML entry gets injected with a small script that checks for SW.
This redirects the page to the home page (with back redirect) in order to install
the SW if it is not present (assuming a direct link to the HTML entry).

This hack used to check for being run from the top most window (`window.top`) which
was the case for older kiwix-serve.
Now that kiwix-serve uses its own iframe, this condition was never met.

This fixes in-frame behavior by removing the top-window check.
I suppose the check was for safety only as all tests I conducted showed no regression;
even with multiple layers of imbricated iframes
  • Loading branch information
rgaudin committed Sep 11, 2023
1 parent ae1c2cb commit 77e3adb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Using wabac.js 2.16.11
- Using `cover` resize method for favicon to prevent issues with too-small ones
- Fixed direct link hack when inside an outer frame (kiwix-serve 3.5+) #119

## [1.5.3] - 2023-08-23

Expand Down
2 changes: 1 addition & 1 deletion src/warc2zim/templates/sw_check.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
// No SW Fallback check: hit if loaded via direct link (no SW installed or not supported)
if (window.top === window && !window._WBWombat) {
if (!window._WBWombat) { // WBWombat is injected by service worker
if (!navigator.serviceWorker || !navigator.serviceWorker.controller) {
// finds '/A/' followed by a domain name with a .
var inx = window.location.href.search(/[/]A[/][^/]+[.]/);
Expand Down
4 changes: 2 additions & 2 deletions src/warc2zim/templates/topFrame.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
if (event.data.title) {
document.title = event.data.title;
}

// remove scheme to be consistent with current canonicalization
const urlNoScheme = event.data.url.slice(event.data.url.indexOf("//") + 2);
window.history.replaceState(null, "", prefix + urlNoScheme);
Expand Down Expand Up @@ -81,7 +81,7 @@
encodedUrl = encodeURIComponent(urlNoScheme)

link.href = parts[0] + "/" + encodedUrl;

head.appendChild(link);
}
}
Expand Down

0 comments on commit 77e3adb

Please sign in to comment.