share-extras / media-viewers

Enhanced document previews for a range of different document and media types, plus a dashlet allowing any content item to be displayed on a site dashboard.
Apache License 2.0
29 stars 23 forks source link

InvalidCharacterError: 'btoa' failed #32

Closed jirutka closed 10 years ago

jirutka commented 10 years ago

When I open a document page, MediaViewer loads (navigation bar, white “paper”, …), but the actual document doesn’t load (progress wheel is spinning). JavaScript console shows:

Uncaught InvalidCharacterError: 'btoa' failed: The string to be encoded contains characters outside of the Latin1 range. pdf_a3cc7a581acd09127d38c3ae6b3bb.js:496
fontLoaderPrepareFontLoadEvent pdf_a3cc7a581acd09127d38c3ae6b3bb.js:496
fontLoaderBind pdf_a3cc7a581acd09127d38c3ae6b3bb.js:483
transportObj pdf_a3cc7a581acd09127d38c3ae6b3bb.js:343
messageHandlerComObjOnMessage

And there’s some context:

if (i < loadTestFontId.length) {
    checksum = (checksum - XXXX_VALUE +
        int32(loadTestFontId + 'XXX', i)) | 0;
}
data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
> var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
    url + '}';
FontLoader.insertRule(rule);
var names = [];
for (i = 0, ii = fonts.length; i < ii; i++) {
    names.push(fonts[i].loadedName);
}

The weird thing is that it’s failing only somewhere. It seems that there’s no problem in Firefox (regardless of the platform), but some people with Chrome has problem.

loftux commented 10 years ago

From the code you have pasted it looks like the error is in pdf.js code. This is a library we use as is. However, we are not always on the latest version. Can you please try your pdf here http://mozilla.github.io/pdf.js/web/viewer.html If you still see the same error, report it to https://github.com/mozilla/pdf.js project. If not, we may need to update to a later version of the external pdf.js lib.

wabson commented 10 years ago

Since no further feedback has been received, this issue will be closed shortly. Please reply in this thread if this is still an issue and you are able to provide the information requested or a copy of the problem file.

charnog commented 10 years ago

@jirutka in pdf.js try to find...

var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;

And replace it with...

var loadTestFontId = 'lt' + (+Date.now()) + this.loadTestFontId++;

It can happen when the Date.now method is overloaded to return a Date instance instead of UNIX-milliseconds.

loftux commented 10 years ago

@charnog Since this seems to be a bug in the external library pdf.js, can you please report this to the pdf.js (https://github.com/mozilla/pdf.js) project? We try to avoid using custom versions of their library. Once fixed by the pdf.js project I will update the included library.

charnog commented 10 years ago

@loftux it's not a pdf.js or a media-viewers bug. According to 15.9.4.4 "The now function return a Number value...". So the polyfill MUST return a Number value too.

if (!Date.now) {
  Date.now = function now() {
    return new Date().getTime();
  };
}
wabson commented 10 years ago

Not a bug with the media-viewers project