Do you have an issue with a specific file(s)? No (happens with numerous files)
Can you reproduce using one of our samples or online demos? No
Are you using the WebViewer server? No
Does the issue only happen on certain browsers? Fails in chrome and firefox (the only ones tested)
Is your issue related to a front-end framework? No
Is your issue related to annotations? Yes? (buttons defined in XFDF)
Please give a brief summary of your issue:
In a PDF with embedded buttons, the js in the button fails referencing âwindowâ properties; âwindowâ is undefined.
Please describe your issue and provide steps to reproduce it:
The XFDF for many of our PDFs contain buttons of this style:
<widget âŚ>
When this PDF+XFDF is loaded in WebViewer, and we click on the button, I see these errors in the Chrome browser console:
webviewer-core.min.js:215 Embedded JS error encountered, Mouse Up event on Field: TypeError: Cannot read properties of undefined (reading âtopâ)
webviewer-core.min.js:215 window.top.document.getElementById(âobsf:actionAppSign1of1â).click();
In Firefox the messages are similar:
Embedded JS error encountered, Mouse Up event on Field: TypeError: window is undefined webviewer-core.min.js:215:453
window.top.document.getElementById(âobsf:actionAppSign1of1â).click(); [webviewer-core.min.js:215:476]
This worked in v6.3.6; weâre in the process of trying to upgrade to v8.6.
The XFDF for the document is supplied via the WebViewer callback to the serverUrl supplied in the WebViewer constructor.
Please provide a link to a minimal sample where the issue is reproducible: N/A
Yes, hereâs a sample PDF file with one button that fails as described above. SimpleButtonTest.zip (34.4 KB)
I also tried âturning offâ our XFDF loading, so all that happens is the WebViewer loads the PDF, and then when I click the button, I still see the same error.
Yes, window is undefined, but why? This WORKED in WebViewer 5 & 6, now it doesnât. It appears that the environment supplied by WebViewer when executing the JS has broken this.
A colleague of mine reminded me that, basically, itâs not secure for embedded JS to allow access to the window, so at some point (by the 7.3 version and we ported back to 6.3), we disallowed that so that the environment would be consistent with the embedded JS environment in other PDF viewers.
So, in summary, it worked before as youâve noted, but we blocked it since itâs a security concern.
It would be good to add that information to the âmigrating to V7â document. Itâs not a security issue for us because we do not allow end users to modify or upload documents, so the JS is strictly controlled by us. [Probably doesnât matter, but I tested with v6.3.6 Build âNy8yOS8yMDIwfDljMzNhYmIxâ and it worked. The Build id is different in your screen shot.]
We have dozens of documents that rely on this feature. How can we accomplish the same goal, which is to âclickâ a (hidden) button on the page that contains the webViewer?
Hi @dfelix ,
Thanks, that fixed the âAnnotationâ error, but now the PDF doesnât load.
myWebViewer = new WebViewer({ ...
initialDoc: '../../_db_document/3103$RO/my test document.pdf.xod',
documentType: 'xod', ...
).then(instance => {
const { Annotations } = instance.Core;
Annotations.Forms.EmbeddedJS.update(scope => {
scope.window = instance.UI.iframeWindow; /* document load hangs if executed*/
console.log('scope updated'); /* this always shows up */
});
...
});
If I comment out the âscope.window = âŚâ, it works fine. But when that line is executed, the screen is left in a gray-disabled state with a circle. I do get my console.log output in either case, and my server gets the PDF URL request and responds. In the case where the document does not load, I do not get the callback for the XFDF via the DocumentXFDFRetriever Iâve specified. (Donât think itâd make a difference, but note that weâre loading xod documents.) Hereâs a screen shot.
I can reproduce the issue. It looks like there are some undesirable side effects when you try to override a property called window since itâs a special case when we are talking about DOM.
I have a similar issue. We upgraded to 11.1 version and our js fails on our pdf. it gives
Embedded JS error encountered, Mouse Up event on Field: TypeError: Cannot read properties of undefined (reading âsignâ)
Why am I getting this error on click of a field?
how do i add a new function in my embeddedJS through EmbeddedJS.update?