Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: #4

Open
jfparie opened this issue Nov 9, 2021 · 7 comments
Open

Uncaught TypeError: #4

jfparie opened this issue Nov 9, 2021 · 7 comments

Comments

@jfparie
Copy link

jfparie commented Nov 9, 2021

Chrome browser 95.0.4638.69 gives the following error:

Cannot read properties of undefined (reading 'GlobalWorkerOptions') at window.onload ((index):256)

I copied ./layouts/shortcodes/embed-pdf.html to my own /layouts/shortcodes folder. The same from pdf.js library files from ./static/js/pdf-js to ./static/js. Is the following path structure correct?

- static

-- js

--- pdf-js

---- build
----- pdf.js
----- pdf.js.map
----- pdf.worker.js
----- pdf.worker.js.map

---- LICENSE

---- web
----- cmaps
etc.

@anvithks
Copy link
Member

@jfparie Seems correct. Could you please share a link to your repository.
This repo is for the demo website of Hugo Embed PDF shortcode. You could refer the code in this repository and compare it with your code.
The shortcode is hosted at this repository

@jfparie
Copy link
Author

jfparie commented Nov 10, 2021

@anvithks Thanks for your response :-) Here is the link to the repository of my website where I want to use Hugo Embed PDF shortcode. I call the short code only in a .md markdown file by using the following command:

{{< embed-pdf url="./uploads/file_name.pdf" >}}

My issue has great similarities to issue #18. However, I was not able to solve the issue based on the mentioned work around by Arwhyte .

Note I cloned your repository by using git clone https://github.com/anvithks/hugo-embed-pdf-shortcode.git outside my website's repository, then I copied and pasted the earlier mentioned files in the above tree structure.

Thanks for looking into this!

@anvithks
Copy link
Member

One thing I see is that the PDF file is not located with the .md file where it is included. Currently this is a limitation for which I am yet to get a proper solution.
Another thing I noticed is that clicking on http://algorithmaudit.eu/ opens a site not found error page. This is the baseURL specified in the config.toml file.
Could you please share the link to the website and page where you are including the pdf?

@jfparie
Copy link
Author

jfparie commented Nov 11, 2021

Hi @anvithks, thanks for your reply :-)

  1. I included the file_name.pdf in the folder where the file_name.md document is located. I rendered {{< embed-pdf url="file_name.pdf" >}} but this doesn't seem to work. The same Failed to load resource: net::ERR_NAME_NOT_RESOLVED and Uncaught TypeError occur.
  2. The url you mentioned is indeed the baseURL where the website ultimately can be reached. However, for the time being I am working locally (using Hugo server on http://localhost:1313/) to develop the website.
    Based on this, have you any thoughts how to solve the issue. Many thanks!

@anvithks
Copy link
Member

anvithks commented Nov 15, 2021

@jfparie I cloned your repository and by making a few changes I was able to get the pdf to display.
You are right. It is related to the src and baseURL.
The changes I made were:

  • removed the config.toml in the root directory.
  • Modified config/_default/config.toml with baseURL = "/" (In understand the config.toml in the root overrides this. If yes, then you can make the change outside.)
  • Kept the pdf file in the same directory as the md file and used the shortcode as {{< embed-pdf url="./file_name.pdf" >}}
  • Used the file from here and modified the contents as follows
    • line 1 <script type="text/javascript" src= '/js/pdf-js/build/pdf.js'></script>
    • line 61 var url = '{{ .Get "url" }}';
    • line 71 pdfjsLib.GlobalWorkerOptions.workerSrc = '/js/pdf-js/build/pdf.worker.js';

With these changes I am able to see the pdf file.

This problem arises when we use the baseURL and try to build locally or do not specify one and try to build locally.
I have not been able to spend a lot of time recently and have not been able to put out a fix. The code works when deployed on the actual baseURL.

I will try to fix this but in the meanwhile you can try the following:

  • Use the hack above (it's actually the older code which was modified by users who faced problems when using baseURL)
  • use the code as is and try building the website on the web server.

Best,
Anvith.

@jfparie
Copy link
Author

jfparie commented Nov 16, 2021

Many thanks for fixing this! I will take a careful look later. Would you mind to remove the image previewing the document (the document should remain undisclosed)? Many thanks again :-)

@anvithks
Copy link
Member

@jfparie sure. I have removed the screenshot.
Let me know if you are able to get it to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants