ApryseSDK / webviewer-ui

WebViewer UI built in React
Other
416 stars 353 forks source link

Config in URL not supported #399

Closed michaelpeterlee closed 5 years ago

michaelpeterlee commented 5 years ago

Re: http://localhost:3000/#d=https://pdftron.s3.amazonaws.com/downloads/pl/demo-annotated.pdf&a=1&config=viewer-config.js

Chrome inspector reveals no network request for this resource.

Q. How do we develop in association with a custom config file ?

ZhijieZhang commented 5 years ago

We stopped passing the config file path to the UI as part of its URL to prevent potential XSS attack. If you'd like to load your own config while developing the UI, please make a change to this file: https://github.com/PDFTron/webviewer-ui/blob/60eeaf0f73990e39462f0d8ba8c28315f87a5bd7/src/helpers/loadScript.js#L26-L29

Instead of just calling resolve(), try using the loadScript function like below:

loadScript('viewer-config.js').then(resolve)
ZhijieZhang commented 5 years ago

Hi Mike, just want to follow up to see how it works for you and if you have any other questions.

michaelpeterlee commented 5 years ago

Thanks Zhijie, that resolves the config.

You may like to consider that as the new default and expose that somewhere else, else folks have to fiddle there to develop which is not intuitive.

michaelpeterlee commented 5 years ago

Re: $(document).on('documentLoaded') Re: readerControl.docViewer.on('documentLoaded')

These listeners do not reveal any events during development in this project, yet it works when in production.

We need to develop with customisations, so can you please advise what we need to do to our external WebViewer config file to get this to work.

ZhijieZhang commented 5 years ago

Hmm I can't seem to reproduce the issue. Here are the steps that I took:

  1. create a config.js inside the assets folder.
  2. have the following code in config.js:
    $(document).on('documentLoaded', () => {
    console.log('document just loaded!');
    });
  3. open loadScript.js, change line 28 to
    loadScript('/assets/config.js').then(resolve);
  4. npm start
  5. After the document is loaded, I see document just loaded! in the console, which indicates that the config file is working.

I'd like to confirm first that your config file is actually be requested? You can use the Chrome dev tools, network tab to check if there's a request sent to your config file. It'd be also helpful if you can send me a sample project in which I can reproduce the issue. Thanks!

michaelpeterlee commented 5 years ago

To get events to fire, we have to wrap event-listener instantiations with setTimeout to apply on next clock. documentLoaded then fires but viewerLoaded still does not. Investigating further now..

michaelpeterlee commented 5 years ago

We replaced our viewer-config.js with just the listeners and it works. So something is bombing silently in our config file. Thanks for your help to confirm things work after editing the loadScript helper.