CORS error when trying to view PDF

When I try viewing a PDF invoice the system hangs and I get the following error in the console? Not sure if it helps but im using cloudflare

index.php#/:1 Access to XMLHttpRequest at ‘https://mydomain.com/invoice/public/client/invoice/Rr5LPpY9XwuNqsKPLEBkT4awBwiJFHfB/download?t=1644087174964&per_page=999999’ from origin ‘https://www.mydomain.com’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: Redirect is not allowed for a preflight request.

and then the following error:

index.php#/:1 WebGL: CONTEXT_LOST_WEBGL: loseContext: context lost

Hi,

@david any thoughts?

You may want to try with the desktop app

Will do and let you know… Thanks

But what’s causing the CORS issue in case I want to use the web version?

I’ve tried the windows app and I get the following error when trying to view PDF:

500: Internal Server Error

There was an error generating the PDF with Phantom JS

Are there any details about the error in storage/logs

I tried again now in order for it to log the error then it worked. Will try a few more times and let u know

Where will I find the error log? Nothing appears on the server and in the app > dashboard > system log there is nothing related to the error either

It happened again… So it seems to work sometimes and othertimes it doesn’t

Do I perhaps need to run php artisan optimize? I’ve got shell access to my server, how would I run it?

@ihsaan

Are you on the latest version of the application?

Yes its the latest v5.3.55 c76

You can find the error log file here:

Oh sorry about that. This is from the error log:

[2022-02-05 19:57:54] production.INFO: https://mysite.com/invoice/public/phantom/invoice/VScl5C8nOxdUCqJJZ5sgGeCVYcYrrSpA?phantomjs_secret=secret  
[2022-02-05 19:57:55] production.ERROR: There was an error generating the PDF with Phantom JS {"exception":"[object] (App\\Exceptions\\PhantomPDFFailure(code: 0): There was an error generating the PDF with Phantom JS at /home2/mysite/public_html/invoice/app/Utils/PhantomJS/Phantom.php:150)
[stacktrace]

Is PHANTOMJS_PDF_GENERATION=true in your .env file?
Could you try a different PDF generation method and see if that fixes it?

Also:

If you’re using the anonymous key you may have exceeded the limit, if that’s the case you can create an account to increase it. https://invoiceninja.github.io/docs/self-host-troubleshooting/#phantom-js

Make sure that you run php artisan optimize after editing your .env file.

Here is somebody with your exact issue: https://forum2.invoiceninja.com/t/error-on-pdf-generation-with-phantom/8693

Sorry about all the noob questions but how do I run php artisan optimize

I have registered with PhantomJSCloud, should I keep the secret key as “secret”

No problem mate that’s what the community is here for!
Are you running shared hosting? If so add this to the end of your URL: ?clear_cache=true

Change the key to whatever your PhantomJS secret key is. It is located on your PhantomJS profile.

PhantomJS only gives an API I cant seem to find the secret key. So I used the api key in the .env file however I left secret="secret"

How do I run artisan optimize?