-1

Hi I am creating chroma app using pdftron webviewer.js.I am able to render pdf on browser.but When I am including pdftron webviewer library in my chrome app the I am getting some error. This is web version pdftron webviewer control.

PDFTronWebViewer Sample

I am getting this error: 1)document.write()and localStorage are not available in packaged apps. throw new Error(message);

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Jitendra singh
  • 413
  • 11
  • 27

3 Answers3

3

document.write() and localStorage are not available in Chrome apps.

As simple as that. You'll need to use a library that doesn't rely on those.

Xan
  • 74,770
  • 16
  • 179
  • 206
0

Instead of overriding window.localStorage in your index.js file you can make changes to lib/HTML5/ControlUtils.js to change how the _storePreference and _getPreference functions work. Instead of having them use localStorage (which is not available in Chrome apps) you can use Google's storage API https://developer.chrome.com/extensions/storage i.e.

_storePreference: function(key, value) {
  chrome.storage.local.set({key: JSON.stringify(value)});
}

If you prefer, you can override these functions in your config.js file i.e.

window.ControlUtils.userPreferences._storePreference = function(key, value) {
  chrome.storage.local.set({key: JSON.stringify(value)});
}
Ryan
  • 2,473
  • 1
  • 11
  • 14
  • And that won't work, because `chrome.storage.local` is not a drop-in replacement of `localStorage`. It is asynchronous while `localStorage` is synchronous. – Xan Jan 20 '16 at 19:40
  • There's also a `document.write()` problem according to OP. – Xan Jan 20 '16 at 19:41
  • thanks Xan & Ryan , I have created sample for this I am getting two error like localStorage and document.write(). can we resolve this issue. This is my sample :- https://jumpshare.com/v/LVWrorMVVkJJB7XvcidN – Jitendra singh Jan 21 '16 at 07:22
0

Instead of document.write you should use document.createElement

fmquaglia
  • 407
  • 2
  • 11
  • 20