Strange error on loading pdf

Hi, I’m using WebViewer 7.3 as an NPM Package and on my local machine everything works fine.
When I publish on our AppService on Azure and I load a pdf I get the following error:
“TypeError: Cannot read property ‘push’ of undefined at XMLHttpRequest. (ExternalPdfPartRetriever.chunk.js:67)”.
I have set a procedure to copy over all the static files from the npm directory to my target directory and in fact all the files are there, everything looks fine.
I have then temporarily solved the problem by adding an extra check in the affected file (ExternalPdfPartRetriever.chunk.js), which I have “pretty-printed”. You can find a screenshot attached, it’s on line 66 with comment “mirko’s hotfix”. Apparently the ca.Ro variable is undefined. With this hotfix everything works fine also on the server. The problem is, I don’t like this solution at all, I have no idea what this variable is (this is minified code) and why and what has lead to this problem. Also, in the code on github at GitHub - PDFTron/webviewer-ui: WebViewer UI built in React I have not been able to find the corresponding source code of this minified code.
Thank you, best regards
Mirko

Hi Mirko,

May I know how you’re loading the pdf? Is it a local file, or URL, or something else? And also did you upgrade from an older WebViewer version? Thanks.

Wanbo

Hi Wanbo
the pdfs I load are all urls pointing to blobs in our azure storage.
Yes I was using WebViewer 5.1 before.

these are the options I pass to the WebViewer on initialization:
var _options = {
css: ‘/Content/css/webViewer.css’,
enableAnnotations: false,
type: “html5”,
path: “…/Scripts/lib/webViewer”,
initialDoc: instance.currentUrlVar,
forceClientSideInit: true,
extension: ‘pdf’,
azureWorkaround: true,
l: “mylicense”,
documentType: ‘pdf’,
fullAPI: true,
config: “…/Scripts/lib/webViewer/config.js”,
streaming: false,
disableLogs: true,
backendType: ‘ems’
}

best regards,
Mirko

Could you try removing the all WebViewer lib files (remember to keep your own files like config files) and re-install WebViewer? Just want to make sure the issue is not related to the project set up. Thanks very much.

Hi Wanbo
I had already removed all the files in the webViewer directory. I only leave my config.js file and an index.html file (which has included some svgs and some scripts). I have also tried removing my custom config.js file, my custom css and resetting the original ui/index.html file but nothing changed.

I realized that I get some errors on executing inline scripts (see “pdftron_error.png” attached). I already had a similar issue and made a question Does the WebViewer require Content Security Policy unsafe-inline and unsafe-eval directives? and it was solved. As you can see in the other attachment, in my config.js file I call CoreControls.disableEmbeddedJavaScript() as suggested. It then worked, now it is apparently ignored, since this inline script gets executed anyway. What I also find strange is that I had to outcomment CoreControls.enableSubzero(false) because it is not recognized as a function any more.

Regarding inline script I have added a hash to our Content Security Policy to allow execution of this very exact inline code of pdftron, now I don’t get the inline script error any more, but if I remove my fix in the “ExternalPdfPartRetriever.chunk.js” file I still get the same error (“Uncaught (in promise) TypeError: Cannot read property ‘push’ of undefined”).
All in all it’s a bit fishy. Do you have an idea, or could you please give me a hint, what this variable “ca.Ro” in the ExternalPdfPartRetriever.chunk.js file is, so that I can try and debug?
Thank you, best regards
Mirko

Hi Mirko,

I have investigated into the ExternalPdfPartRetriever.chunk.js file and looks like the ca.Ro is not from the code, but added by the complier when we’re building the prod minified build.

Wanbo

Hi Wanbo,
thanx yes I had noticed it is minified code, thus making it impossible for me to debug.
Is the original source code public, and in that case could you please point me to it so that I can understand better where this comes from and what should I look into?
Otherwise can you understand from the code what/why is the variable undefined? Or maybe add a check to your source code which initializes the variable to empty array (like I did in the hotfix)?
Sorry for me being vague, but I have no idea where this comes from.
Thanx, best regards
Mirko

Hi Mirko,

Actually I have also spent several hours finding the corresponding source code and debugging. The source code is not public, unlike our UI codes. Based on my investigation, that piece of code happens to be added by the compiler, not like other minified codes, and it’s not a translation from our source code. So this issue is very strange, it may because of the bug in the compiler or your environment configuration or something else, I’m not sure honestly. So if it’s working fine locally on your machine, I would suspect the error is related to the new environment where you’re running your app. Maybe try upgrading the node version?

Sorry that I did not find the solution for you. Please let me know how it goes.

Thanks.

Wanbo

Hi Wanbo,
thank you for your investigation, I understand that the code is not public and that it is difficult to investigate something you can’t reproduce (I know the feeling… :slight_smile: )
So, I still didn’t understand the original problem, but I noticed that after I updated the webViewer to the npm package version there was a typo in the pdftronServer option I passed to the webViewer on initialization. This lead to the webViewer not using our pdftronServer instance and hence falling back to the local instance. Now I fixed the typo, and after yesterday’s publish, today it goes to our pdftronServer instance and it seems to be working well as before, even without my fix in the “ExternalPdfPartRetriever.chunk.js”.
Still, this does not explain why that variable was null, nor why it was working on my machine and not on the server, but using our pdftronServer instance seems to have fixed the issue, so it should not be relevant any more.
Again, thank you anyway for your time and dedication (hoping to not having to give you other updates on this in the following days :slight_smile: ).
Best regards
Mirko

No problem. Hope everything goes well with your project!

Wanbo