Skip to content

Commit

Permalink
Fix error "Failed to fetch a source document" with web publications o…
Browse files Browse the repository at this point in the history
…n Microsoft Edge

The problem was: The document URLs from TOC items are obtained by `anchorElem.href` property.
This href value is absolute URL that is generated from the "href" attribute value and the base URL.
On Chrome, Safari, and Firefox, this base URL is the URL of the document containing the TOC,
and works as expected. However, on Microsoft Edge, the vivliostyle-viewer URL is used as the base URL
and the `anchorElem.href` value becomes wrong URL, and causes "Failed to fetch a source document"
error.
  • Loading branch information
MurakamiShinyu committed Aug 11, 2019
1 parent db8e9bc commit 1ed01af
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ts/adapt/epub.ts
Expand Up @@ -297,7 +297,7 @@ export class EPUBDocStore extends Ops.OPSDocStore {
}); });
} else { } else {
this.loadAsJSON( this.loadAsJSON(
(manifestLink as any).href || manifestLink.getAttribute("href") Base.resolveURL(manifestLink.getAttribute("href"), url)
).then(manifestObj => { ).then(manifestObj => {
opf.initWithWebPubManifest(manifestObj, doc).then(() => { opf.initWithWebPubManifest(manifestObj, doc).then(() => {
frame.finish(opf); frame.finish(opf);
Expand Down Expand Up @@ -1128,7 +1128,7 @@ export class OPFDoc {
"#toc a[href]"; "#toc a[href]";
Array.from(doc.querySelectorAll(selector)).forEach(anchorElem => { Array.from(doc.querySelectorAll(selector)).forEach(anchorElem => {
const hrefNoFragment = Base.stripFragment( const hrefNoFragment = Base.stripFragment(
(anchorElem as any).href || anchorElem.getAttribute("href") Base.resolveURL(anchorElem.getAttribute("href"), this.pubURL)
); );
const path = this.getPathFromURL(hrefNoFragment); const path = this.getPathFromURL(hrefNoFragment);
const url = path !== null ? encodeURI(path) : hrefNoFragment; const url = path !== null ? encodeURI(path) : hrefNoFragment;
Expand Down

0 comments on commit 1ed01af

Please sign in to comment.