Open bjosttveit opened 5 months ago
Another option is using Playwright with C#, what all of these options have in common is that they all use the Chrome Dev-Tools Protocol (CDP) under the hood anyway, so in a sense they are all the same, and only differ in how much functionality and stability each tool can provide out-of-the-box. One thing that Playwright is missing is built in functionality for returning PDFs as streams, and only supports the "old" base64 option. However, I am pretty sure it is possible to make direct CDP-calls to the browser anyway, so this could probably be solved by implementing a function for handling this ourselves.
Since Playwright is maintained by Microsoft, it will probably have great support for the .NET libraries for the forseable future.
Really good analysis @bjosttveit ! Another issue to consider is auth, we should have the option for machine to machine auth somehow, will be important for watermark functionality and other things :)
Absolutely! Although I don't think the PDF service itself needs to concern itself with this. As long as the app is able to use a machine-token instead of the users token to access the required data it can just pass this on to the PDF-service the same way we do with the users token today, I think!
Unless I misunderstood the issue, how is machine auth related to watermarking the PDF?
Based on the analysis done on this issue we need a discussion resulting in a decision about how to move forward with implementation.
Update: It looks like the API documentation for browserless v1 has been removed, been getting a 404 for a couple of days now: https://chrome.browserless.io/docs/#/Browser%20API/post%20pdf
Description
There are some areas that could be improved related to the PDF generation process that are directly tied to the PDF service itself, browserless (v1).
In scope
Out of scope
Additional Information
No response
Analysis
Identified issues related to the current PDF service
userDataDir
solution in browserless would work.waitFor
option is quite limited. Ideally, we would like for app-frontend to be able to signal if loading the page failed, so we can quickly respond with an error. Today, if app frontend shows the "unknown error" page, that page will get printed. The alternative is waiting 30 seconds for it to time out if the#readyForPrint
element is not found.Possible solutions:
Upgrading browserless to v2
Creating our own chrome-based PDF generator
First of all, browserless seems to be a relatively thin wrapper around puppeteer (with a lot more functionality we dont need), so creating something similar just for generating PDFs seems to be relatively straight forward.
As for the issues:
Conclusion
Even though browserless v2 should be an improvement in several areas, accessibility and possibly stability(?), its waitFor support is still very limited and not optimal to our use case. Upgrading browserless to v2 is probably the easiest, as the API is not very different. However, if we create our own, we could tailor it more to suit our needs where browserless falls short.